diff --git a/extensions/git/src/historyProvider.ts b/extensions/git/src/historyProvider.ts index cb94816874f..5872eb3bcb5 100644 --- a/extensions/git/src/historyProvider.ts +++ b/extensions/git/src/historyProvider.ts @@ -83,16 +83,16 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec this.currentHistoryItemGroup = { id: `refs/heads/${this.repository.HEAD.name ?? ''}`, name: this.repository.HEAD.name ?? '', - revision: this.repository.HEAD.commit ?? '', + revision: this.repository.HEAD.commit, remote: this.repository.HEAD.upstream ? { id: `refs/remotes/${this.repository.HEAD.upstream.remote}/${this.repository.HEAD.upstream.name}`, name: `${this.repository.HEAD.upstream.remote}/${this.repository.HEAD.upstream.name}`, - revision: this.repository.HEAD.upstream.commit ?? '' + revision: this.repository.HEAD.upstream.commit } : undefined, base: mergeBase ? { id: `refs/remotes/${mergeBase.remote}/${mergeBase.name}`, name: `${mergeBase.remote}/${mergeBase.name}`, - revision: mergeBase.commit ?? '' + revision: mergeBase.commit } : undefined }; diff --git a/src/vs/workbench/api/browser/mainThreadSCM.ts b/src/vs/workbench/api/browser/mainThreadSCM.ts index d35131056be..451c5c86185 100644 --- a/src/vs/workbench/api/browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/browser/mainThreadSCM.ts @@ -6,7 +6,7 @@ import { Barrier } from 'vs/base/common/async'; import { URI, UriComponents } from 'vs/base/common/uri'; import { Event, Emitter } from 'vs/base/common/event'; -import { derivedOpts, observableValue, observableValueOpts } from 'vs/base/common/observable'; +import { derived, observableValue, observableValueOpts } from 'vs/base/common/observable'; import { IDisposable, DisposableStore, combinedDisposable, dispose, Disposable } from 'vs/base/common/lifecycle'; import { ISCMService, ISCMRepository, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations, IInputValidation, ISCMViewService, InputValidationType, ISCMActionButtonDescriptor } from 'vs/workbench/contrib/scm/common/scm'; import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceSplices, SCMGroupFeatures, MainContext, SCMHistoryItemGroupDto, SCMHistoryItemDto } from '../common/extHost.protocol'; @@ -17,7 +17,7 @@ import { MarshalledId } from 'vs/base/common/marshallingIds'; import { ThemeIcon } from 'vs/base/common/themables'; import { IMarkdownString } from 'vs/base/common/htmlContent'; import { IQuickDiffService, QuickDiffProvider } from 'vs/workbench/contrib/scm/common/quickDiff'; -import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHistoryItemGroupWithRevision, ISCMHistoryOptions, ISCMHistoryProvider } from 'vs/workbench/contrib/scm/common/history'; +import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHistoryOptions, ISCMHistoryProvider } from 'vs/workbench/contrib/scm/common/history'; import { ResourceTree } from 'vs/base/common/resourceTree'; import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -49,12 +49,6 @@ function toISCMHistoryItem(historyItemDto: SCMHistoryItemDto): ISCMHistoryItem { return { ...historyItemDto, icon, labels }; } -function historyItemGroupEquals(a: ISCMHistoryItemGroup | undefined, b: ISCMHistoryItemGroup | undefined): boolean { - return a?.id === b?.id && a?.name === b?.name && - a?.base?.id === b?.base?.id && a?.base?.name === b?.base?.name && - a?.remote?.id === b?.remote?.id && a?.remote?.name === b?.remote?.name; -} - class SCMInputBoxContentProvider extends Disposable implements ITextModelContentProvider { constructor( textModelService: ITextModelService, @@ -171,26 +165,18 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider { private _onDidChangeCurrentHistoryItemGroup = new Emitter(); readonly onDidChangeCurrentHistoryItemGroup = this._onDidChangeCurrentHistoryItemGroup.event; - private _currentHistoryItemGroup: ISCMHistoryItemGroupWithRevision | undefined; - get currentHistoryItemGroup(): ISCMHistoryItemGroupWithRevision | undefined { return this._currentHistoryItemGroup; } - set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined) { + private _currentHistoryItemGroup: ISCMHistoryItemGroup | undefined; + get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined { return this._currentHistoryItemGroup; } + set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined) { this._currentHistoryItemGroup = historyItemGroup; this._onDidChangeCurrentHistoryItemGroup.fire(); } - /** - * Changes when the id/name changes for the current, remote, or base history item group - */ - private readonly _currentHistoryItemGroupObs = derivedOpts({ - owner: this, equalsFn: historyItemGroupEquals, - }, reader => this._currentHistoryItemGroupWithRevisionObs.read(reader)); - get currentHistoryItemGroupObs() { return this._currentHistoryItemGroupObs; } + readonly currentHistoryItemGroupIdObs = derived(this, reader => this.currentHistoryItemGroup?.id); + readonly currentHistoryItemGroupNameObs = derived(this, reader => this.currentHistoryItemGroup?.name); - /** - * Changes when the id/name/revision changes for the current, remote, or base history item group - */ - private readonly _currentHistoryItemGroupWithRevisionObs = observableValueOpts({ owner: this, equalsFn: structuralEquals }, undefined); - get currentHistoryItemGroupWithRevisionObs() { return this._currentHistoryItemGroupWithRevisionObs; } + private readonly _currentHistoryItemGroupObs = observableValueOpts({ owner: this, equalsFn: structuralEquals }, undefined); + get currentHistoryItemGroupObs() { return this._currentHistoryItemGroupObs; } constructor(private readonly proxy: ExtHostSCMShape, private readonly handle: number) { } @@ -227,8 +213,8 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider { })); } - $onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined): void { - this._currentHistoryItemGroupWithRevisionObs.set(historyItemGroup, undefined); + $onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined): void { + this._currentHistoryItemGroupObs.set(historyItemGroup, undefined); } } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 70cd8cb371a..d8cbfba387b 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1516,7 +1516,7 @@ export type SCMRawResourceSplices = [ export interface SCMHistoryItemGroupDto { readonly id: string; readonly name: string; - readonly revision: string; + readonly revision?: string; readonly base?: Omit, 'remote'>; readonly remote?: Omit, 'remote'>; } diff --git a/src/vs/workbench/contrib/scm/browser/activity.ts b/src/vs/workbench/contrib/scm/browser/activity.ts index 36a6aeffdb3..6f5794f7570 100644 --- a/src/vs/workbench/contrib/scm/browser/activity.ts +++ b/src/vs/workbench/contrib/scm/browser/activity.ts @@ -25,7 +25,6 @@ import { autorun, autorunWithStore, derived, IObservable, observableFromEvent } import { observableConfigValue } from 'vs/platform/observable/common/platformObservableUtils'; import { derivedObservableWithCache, latestChangedValue, observableFromEventOpts } from 'vs/base/common/observableInternal/utils'; import { Command } from 'vs/editor/common/languages'; -import { ISCMHistoryItemGroup } from 'vs/workbench/contrib/scm/common/history'; const ActiveRepositoryContextKeys = { ActiveRepositoryName: new RawContextKey('scmActiveRepositoryName', ''), @@ -135,9 +134,10 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe this._register(autorun(reader => { const repository = this._activeRepository.read(reader); - const currentHistoryItemGroup = repository?.provider.historyProviderObs.read(reader)?.currentHistoryItemGroupObs.read(reader); + const historyProvider = repository?.provider.historyProviderObs.read(reader); + const branchName = historyProvider?.currentHistoryItemGroupNameObs.read(reader); - this._updateActiveRepositoryContextKeys(repository, currentHistoryItemGroup); + this._updateActiveRepositoryContextKeys(repository?.provider.name, branchName); })); } @@ -196,9 +196,9 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe } } - private _updateActiveRepositoryContextKeys(repository: ISCMRepository | undefined, currentHistoryItemGroup: ISCMHistoryItemGroup | undefined): void { - this._activeRepositoryNameContextKey.set(repository?.provider.name ?? ''); - this._activeRepositoryBranchNameContextKey.set(currentHistoryItemGroup?.name ?? ''); + private _updateActiveRepositoryContextKeys(repositoryName: string | undefined, branchName: string | undefined): void { + this._activeRepositoryNameContextKey.set(repositoryName ?? ''); + this._activeRepositoryBranchNameContextKey.set(branchName ?? ''); } } diff --git a/src/vs/workbench/contrib/scm/browser/workingSet.ts b/src/vs/workbench/contrib/scm/browser/workingSet.ts index 274bd713910..fe2f0752faa 100644 --- a/src/vs/workbench/contrib/scm/browser/workingSet.ts +++ b/src/vs/workbench/contrib/scm/browser/workingSet.ts @@ -65,7 +65,7 @@ export class SCMWorkingSetController extends Disposable implements IWorkbenchCon disposables.add(autorun(async reader => { const historyProvider = repository.provider.historyProviderObs.read(reader); - const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupObs.read(reader)?.id; + const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupIdObs.read(reader); if (!currentHistoryItemGroupId) { return; diff --git a/src/vs/workbench/contrib/scm/common/history.ts b/src/vs/workbench/contrib/scm/common/history.ts index f708d8617b8..c2c353ea87f 100644 --- a/src/vs/workbench/contrib/scm/common/history.ts +++ b/src/vs/workbench/contrib/scm/common/history.ts @@ -21,10 +21,12 @@ export interface ISCMHistoryProvider { readonly onDidChangeCurrentHistoryItemGroup: Event; - get currentHistoryItemGroup(): ISCMHistoryItemGroupWithRevision | undefined; - set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined); + get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined; + set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined); + + readonly currentHistoryItemGroupIdObs: IObservable; + readonly currentHistoryItemGroupNameObs: IObservable; readonly currentHistoryItemGroupObs: IObservable; - readonly currentHistoryItemGroupWithRevisionObs: IObservable; provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise; provideHistoryItems2(options: ISCMHistoryOptions): Promise; @@ -51,18 +53,11 @@ export interface ISCMHistoryOptions { export interface ISCMHistoryItemGroup { readonly id: string; readonly name: string; + readonly revision?: string; readonly base?: Omit, 'remote'>; readonly remote?: Omit, 'remote'>; } -export interface ISCMHistoryItemGroupWithRevision { - readonly id: string; - readonly name: string; - readonly revision: string; - readonly base?: Omit, 'remote'>; - readonly remote?: Omit, 'remote'>; -} - export interface SCMHistoryItemGroupTreeElement { readonly id: string; readonly label: string; diff --git a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts index f79fa1885b9..85567a6fa7d 100644 --- a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts +++ b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts @@ -42,7 +42,7 @@ declare module 'vscode' { export interface SourceControlHistoryItemGroup { readonly id: string; readonly name: string; - readonly revision: string; + readonly revision?: string; readonly base?: Omit, 'remote'>; readonly remote?: Omit, 'remote'>; }