SCM - 💄 remove SourceControlHistoryItemGroup from the API proposal

This commit is contained in:
Ladislau Szomoru 2024-09-10 14:46:12 +02:00
parent c2f7ee51b3
commit c2c032e0da
13 changed files with 149 additions and 180 deletions

View file

@ -3059,7 +3059,7 @@ export class CommandCenter {
@command('git.fetchRef', { repository: true })
async fetchRef(repository: Repository, ref?: string): Promise<void> {
ref = ref ?? repository?.historyProvider.currentHistoryItemGroup?.remote?.id;
ref = ref ?? repository?.historyProvider.currentHistoryItemRemoteRef?.id;
if (!repository || !ref) {
return;
}
@ -3132,7 +3132,7 @@ export class CommandCenter {
@command('git.pullRef', { repository: true })
async pullRef(repository: Repository, ref?: string): Promise<void> {
ref = ref ?? repository?.historyProvider.currentHistoryItemGroup?.remote?.id;
ref = ref ?? repository?.historyProvider.currentHistoryItemRemoteRef?.id;
if (!repository || !ref) {
return;
}

View file

@ -164,11 +164,11 @@ class GitIncomingChangesFileDecorationProvider implements FileDecorationProvider
constructor(private readonly repository: Repository) {
this.disposables.push(
window.registerFileDecorationProvider(this),
runAndSubscribeEvent(repository.historyProvider.onDidChangeCurrentHistoryItemGroup, () => this.onDidChangeCurrentHistoryItemGroup())
runAndSubscribeEvent(repository.historyProvider.onDidChangeCurrentHistoryItemRefs, () => this.onDidChangeCurrentHistoryItemRefs())
);
}
private async onDidChangeCurrentHistoryItemGroup(): Promise<void> {
private async onDidChangeCurrentHistoryItemRefs(): Promise<void> {
const newDecorations = new Map<string, FileDecoration>();
await this.collectIncomingChangesFileDecorations(newDecorations);
const uris = new Set([...this.decorations.keys()].concat([...newDecorations.keys()]));
@ -218,18 +218,19 @@ class GitIncomingChangesFileDecorationProvider implements FileDecorationProvider
private async getIncomingChanges(): Promise<Change[]> {
try {
const historyProvider = this.repository.historyProvider;
const currentHistoryItemGroup = historyProvider.currentHistoryItemGroup;
const currentHistoryItemRef = historyProvider.currentHistoryItemRef;
const currentHistoryItemRemoteRef = historyProvider.currentHistoryItemRemoteRef;
if (!currentHistoryItemGroup?.remote) {
if (!currentHistoryItemRef || !currentHistoryItemRemoteRef) {
return [];
}
const ancestor = await historyProvider.resolveHistoryItemRefsCommonAncestor([currentHistoryItemGroup.id, currentHistoryItemGroup.remote.id]);
const ancestor = await historyProvider.resolveHistoryItemRefsCommonAncestor([currentHistoryItemRef.id, currentHistoryItemRemoteRef.id]);
if (!ancestor) {
return [];
}
const changes = await this.repository.diffBetween(ancestor, currentHistoryItemGroup.remote.id);
const changes = await this.repository.diffBetween(ancestor, currentHistoryItemRemoteRef.id);
return changes;
} catch (err) {
return [];

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryItemGroup, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent } from 'vscode';
import { Disposable, Event, EventEmitter, FileDecoration, FileDecorationProvider, SourceControlHistoryItem, SourceControlHistoryItemChange, SourceControlHistoryOptions, SourceControlHistoryProvider, ThemeIcon, Uri, window, LogOutputChannel, SourceControlHistoryItemRef, l10n, SourceControlHistoryItemRefsChangeEvent } from 'vscode';
import { Repository, Resource } from './repository';
import { IDisposable, deltaHistoryItemRefs, dispose } from './util';
import { toGitUri } from './uri';
@ -45,22 +45,23 @@ function toSourceControlHistoryItemRef(ref: Ref): SourceControlHistoryItemRef {
}
export class GitHistoryProvider implements SourceControlHistoryProvider, FileDecorationProvider, IDisposable {
private readonly _onDidChangeCurrentHistoryItemGroup = new EventEmitter<void>();
readonly onDidChangeCurrentHistoryItemGroup: Event<void> = this._onDidChangeCurrentHistoryItemGroup.event;
private readonly _onDidChangeHistoryItemRefs = new EventEmitter<SourceControlHistoryItemRefsChangeEvent>();
readonly onDidChangeHistoryItemRefs: Event<SourceControlHistoryItemRefsChangeEvent> = this._onDidChangeHistoryItemRefs.event;
private readonly _onDidChangeDecorations = new EventEmitter<Uri[]>();
readonly onDidChangeFileDecorations: Event<Uri[]> = this._onDidChangeDecorations.event;
private _currentHistoryItemGroup: SourceControlHistoryItemGroup | undefined;
get currentHistoryItemGroup(): SourceControlHistoryItemGroup | undefined { return this._currentHistoryItemGroup; }
set currentHistoryItemGroup(value: SourceControlHistoryItemGroup | undefined) {
this._currentHistoryItemGroup = value;
this._onDidChangeCurrentHistoryItemGroup.fire();
}
private _currentHistoryItemRef: SourceControlHistoryItemRef | undefined;
get currentHistoryItemRef(): SourceControlHistoryItemRef | undefined { return this._currentHistoryItemRef; }
private _currentHistoryItemRemoteRef: SourceControlHistoryItemRef | undefined;
get currentHistoryItemRemoteRef(): SourceControlHistoryItemRef | undefined { return this._currentHistoryItemRemoteRef; }
private _currentHistoryItemBaseRef: SourceControlHistoryItemRef | undefined;
get currentHistoryItemBaseRef(): SourceControlHistoryItemRef | undefined { return this._currentHistoryItemBaseRef; }
private readonly _onDidChangeCurrentHistoryItemRefs = new EventEmitter<void>();
readonly onDidChangeCurrentHistoryItemRefs: Event<void> = this._onDidChangeCurrentHistoryItemRefs.event;
private readonly _onDidChangeHistoryItemRefs = new EventEmitter<SourceControlHistoryItemRefsChangeEvent>();
readonly onDidChangeHistoryItemRefs: Event<SourceControlHistoryItemRefsChangeEvent> = this._onDidChangeHistoryItemRefs.event;
private _HEAD: Branch | undefined;
private historyItemRefs: SourceControlHistoryItemRef[] = [];
@ -78,7 +79,9 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
private async onDidRunGitStatus(): Promise<void> {
if (!this.repository.HEAD) {
this.logger.trace('[GitHistoryProvider][onDidRunGitStatus] repository.HEAD is undefined');
this.currentHistoryItemGroup = undefined;
this._currentHistoryItemRef = this._currentHistoryItemRemoteRef = this._currentHistoryItemBaseRef = undefined;
this._onDidChangeCurrentHistoryItemRefs.fire();
return;
}
@ -122,19 +125,26 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
this._HEAD = this.repository.HEAD;
this.currentHistoryItemGroup = {
this._currentHistoryItemRef = {
id: historyItemRefId,
name: historyItemRefName,
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
} : undefined,
base: this.historyItemBaseRef
icon: new ThemeIcon('target'),
};
this.logger.trace(`[GitHistoryProvider][onDidRunGitStatus] currentHistoryItemGroup: ${JSON.stringify(this.currentHistoryItemGroup)}`);
this._currentHistoryItemRemoteRef = 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,
icon: new ThemeIcon('cloud')
} : undefined;
this._currentHistoryItemBaseRef = this.historyItemBaseRef;
this._onDidChangeCurrentHistoryItemRefs.fire();
this.logger.trace(`[GitHistoryProvider][onDidRunGitStatus] currentHistoryItemRef: ${JSON.stringify(this._currentHistoryItemRef)}`);
this.logger.trace(`[GitHistoryProvider][onDidRunGitStatus] currentHistoryItemRemoteRef: ${JSON.stringify(this._currentHistoryItemRemoteRef)}`);
this.logger.trace(`[GitHistoryProvider][onDidRunGitStatus] currentHistoryItemBaseRef: ${JSON.stringify(this._currentHistoryItemBaseRef)}`);
// Refs (alphabetically)
const refs = await this.repository.getRefs({ sort: 'alphabetically' });
@ -177,7 +187,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
}
async provideHistoryItems(options: SourceControlHistoryOptions): Promise<SourceControlHistoryItem[]> {
if (!this.currentHistoryItemGroup || !options.historyItemRefs) {
if (!this.currentHistoryItemRef || !options.historyItemRefs) {
return [];
}
@ -265,16 +275,16 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
if (historyItemRefs.length === 0) {
// TODO@lszomoru - log
return undefined;
} else if (historyItemRefs.length === 1 && historyItemRefs[0] === this.currentHistoryItemGroup?.id) {
} else if (historyItemRefs.length === 1 && historyItemRefs[0] === this.currentHistoryItemRemoteRef?.id) {
// Remote
if (this.currentHistoryItemGroup.remote) {
const ancestor = await this.repository.getMergeBase(historyItemRefs[0], this.currentHistoryItemGroup.remote.id);
if (this.currentHistoryItemRemoteRef) {
const ancestor = await this.repository.getMergeBase(historyItemRefs[0], this.currentHistoryItemRemoteRef.id);
return ancestor;
}
// Base
if (this.currentHistoryItemGroup.base) {
const ancestor = await this.repository.getMergeBase(historyItemRefs[0], this.currentHistoryItemGroup.base.id);
if (this.currentHistoryItemBaseRef) {
const ancestor = await this.repository.getMergeBase(historyItemRefs[0], this.currentHistoryItemBaseRef.id);
return ancestor;
}

View file

@ -6,10 +6,10 @@
import { Barrier } from '../../../base/common/async.js';
import { URI, UriComponents } from '../../../base/common/uri.js';
import { Event, Emitter } from '../../../base/common/event.js';
import { derivedOpts, IObservable, observableValue, observableValueOpts } from '../../../base/common/observable.js';
import { IObservable, observableValue, observableValueOpts, transaction } from '../../../base/common/observable.js';
import { IDisposable, DisposableStore, combinedDisposable, dispose, Disposable } from '../../../base/common/lifecycle.js';
import { ISCMService, ISCMRepository, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations, IInputValidation, ISCMViewService, InputValidationType, ISCMActionButtonDescriptor } from '../../contrib/scm/common/scm.js';
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceSplices, SCMGroupFeatures, MainContext, SCMHistoryItemGroupDto, SCMHistoryItemDto, SCMHistoryItemRefsChangeEventDto } from '../common/extHost.protocol.js';
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceSplices, SCMGroupFeatures, MainContext, SCMHistoryItemDto, SCMHistoryItemRefsChangeEventDto, SCMHistoryItemRefDto } from '../common/extHost.protocol.js';
import { Command } from '../../../editor/common/languages.js';
import { extHostNamedCustomer, IExtHostContext } from '../../services/extensions/common/extHostCustomers.js';
import { CancellationToken } from '../../../base/common/cancellation.js';
@ -17,7 +17,7 @@ import { MarshalledId } from '../../../base/common/marshallingIds.js';
import { ThemeIcon } from '../../../base/common/themables.js';
import { IMarkdownString } from '../../../base/common/htmlContent.js';
import { IQuickDiffService, QuickDiffProvider } from '../../contrib/scm/common/quickDiff.js';
import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHistoryItemRef, ISCMHistoryItemRefsChangeEvent, ISCMHistoryOptions, ISCMHistoryProvider } from '../../contrib/scm/common/history.js';
import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemRef, ISCMHistoryItemRefsChangeEvent, ISCMHistoryOptions, ISCMHistoryProvider } from '../../contrib/scm/common/history.js';
import { ResourceTree } from '../../../base/common/resourceTree.js';
import { IUriIdentityService } from '../../../platform/uriIdentity/common/uriIdentity.js';
import { IWorkspaceContextService } from '../../../platform/workspace/common/workspace.js';
@ -28,8 +28,8 @@ import { ITextModelContentProvider, ITextModelService } from '../../../editor/co
import { Schemas } from '../../../base/common/network.js';
import { ITextModel } from '../../../editor/common/model.js';
import { structuralEquals } from '../../../base/common/equals.js';
import { Codicon } from '../../../base/common/codicons.js';
import { historyItemGroupBase, historyItemGroupLocal, historyItemGroupRemote } from '../../contrib/scm/browser/scmHistory.js';
import { historyItemBaseRefColor, historyItemRefColor, historyItemRemoteRefColor } from '../../contrib/scm/browser/scmHistory.js';
import { ColorIdentifier } from '../../../platform/theme/common/colorUtils.js';
function getIconFromIconDto(iconDto?: UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon): URI | { light: URI; dark: URI } | ThemeIcon | undefined {
if (iconDto === undefined) {
@ -56,6 +56,10 @@ function toISCMHistoryItem(historyItemDto: SCMHistoryItemDto): ISCMHistoryItem {
return { ...historyItemDto, subject, references };
}
function toISCMHistoryItemRef(historyItemRefDto?: SCMHistoryItemRefDto, color?: ColorIdentifier): ISCMHistoryItemRef | undefined {
return historyItemRefDto ? { ...historyItemRefDto, icon: getIconFromIconDto(historyItemRefDto.icon), color: color } : undefined;
}
class SCMInputBoxContentProvider extends Disposable implements ITextModelContentProvider {
constructor(
textModelService: ITextModelService,
@ -168,55 +172,23 @@ class MainThreadSCMResource implements ISCMResource {
}
class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
private readonly _currentHistoryItemGroup = observableValueOpts<ISCMHistoryItemGroup | undefined>({
owner: this, equalsFn: structuralEquals
private readonly _historyItemRef = observableValueOpts<ISCMHistoryItemRef | undefined>({
owner: this,
equalsFn: structuralEquals
}, undefined);
get currentHistoryItemGroup() { return this._currentHistoryItemGroup; }
get historyItemRef(): IObservable<ISCMHistoryItemRef | undefined> { return this._historyItemRef; }
readonly currentHistoryItemRef = derivedOpts<ISCMHistoryItemRef | undefined>({
private readonly _historyItemRemoteRef = observableValueOpts<ISCMHistoryItemRef | undefined>({
owner: this,
equalsFn: structuralEquals
}, reader => {
const currentHistoryItemGroup = this._currentHistoryItemGroup.read(reader);
}, undefined);
get historyItemRemoteRef(): IObservable<ISCMHistoryItemRef | undefined> { return this._historyItemRemoteRef; }
return currentHistoryItemGroup ? {
id: currentHistoryItemGroup.id ?? '',
name: currentHistoryItemGroup.name,
revision: currentHistoryItemGroup.revision,
color: historyItemGroupLocal,
icon: Codicon.target,
} : undefined;
});
readonly currentHistoryItemRemoteRef = derivedOpts<ISCMHistoryItemRef | undefined>({
private readonly _historyItemBaseRef = observableValueOpts<ISCMHistoryItemRef | undefined>({
owner: this,
equalsFn: structuralEquals
}, reader => {
const currentHistoryItemGroup = this._currentHistoryItemGroup.read(reader);
return currentHistoryItemGroup?.remote ? {
id: currentHistoryItemGroup.remote.id ?? '',
name: currentHistoryItemGroup.remote.name,
revision: currentHistoryItemGroup.remote.revision,
color: historyItemGroupRemote,
icon: Codicon.cloud,
} : undefined;
});
readonly currentHistoryItemBaseRef = derivedOpts<ISCMHistoryItemRef | undefined>({
owner: this,
equalsFn: structuralEquals
}, reader => {
const currentHistoryItemGroup = this._currentHistoryItemGroup.read(reader);
return currentHistoryItemGroup?.base ? {
id: currentHistoryItemGroup.base.id ?? '',
name: currentHistoryItemGroup.base.name,
revision: currentHistoryItemGroup.base.revision,
color: historyItemGroupBase,
icon: Codicon.cloud,
} : undefined;
});
}, undefined);
get historyItemBaseRef(): IObservable<ISCMHistoryItemRef | undefined> { return this._historyItemBaseRef; }
private readonly _historyItemRefChanges = observableValue<ISCMHistoryItemRefsChangeEvent>(this, { added: [], modified: [], removed: [] });
get historyItemRefChanges(): IObservable<ISCMHistoryItemRefsChangeEvent> { return this._historyItemRefChanges; }
@ -247,14 +219,18 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
}));
}
$onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined): void {
this._currentHistoryItemGroup.set(historyItemGroup, undefined);
$onDidChangeCurrentHistoryItemRefs(historyItemRef?: SCMHistoryItemRefDto, historyItemRemoteRef?: SCMHistoryItemRefDto, historyItemBaseRef?: SCMHistoryItemRefDto): void {
transaction(tx => {
this._historyItemRef.set(toISCMHistoryItemRef(historyItemRef, historyItemRefColor), tx);
this._historyItemRemoteRef.set(toISCMHistoryItemRef(historyItemRemoteRef, historyItemRemoteRefColor), tx);
this._historyItemBaseRef.set(toISCMHistoryItemRef(historyItemBaseRef, historyItemBaseRefColor), tx);
});
}
$onDidChangeHistoryItemRefs(historyItemRefs: SCMHistoryItemRefsChangeEventDto): void {
const added = historyItemRefs.added.map(ref => ({ ...ref, icon: getIconFromIconDto(ref.icon) }));
const modified = historyItemRefs.modified.map(ref => ({ ...ref, icon: getIconFromIconDto(ref.icon) }));
const removed = historyItemRefs.removed.map(ref => ({ ...ref, icon: getIconFromIconDto(ref.icon) }));
const added = historyItemRefs.added.map(ref => toISCMHistoryItemRef(ref)!);
const modified = historyItemRefs.modified.map(ref => toISCMHistoryItemRef(ref)!);
const removed = historyItemRefs.removed.map(ref => toISCMHistoryItemRef(ref)!);
this._historyItemRefChanges.set({ added, modified, removed }, undefined);
}
@ -487,12 +463,12 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
return result && URI.revive(result);
}
$onDidChangeHistoryProviderCurrentHistoryItemGroup(currentHistoryItemGroup?: SCMHistoryItemGroupDto): void {
$onDidChangeHistoryProviderCurrentHistoryItemRefs(historyItemRef?: SCMHistoryItemRefDto, historyItemRemoteRef?: SCMHistoryItemRefDto, historyItemBaseRef?: SCMHistoryItemRefDto): void {
if (!this.historyProvider.get()) {
return;
}
this._historyProvider.get()?.$onDidChangeCurrentHistoryItemGroup(currentHistoryItemGroup);
this._historyProvider.get()?.$onDidChangeCurrentHistoryItemRefs(historyItemRef, historyItemRemoteRef, historyItemBaseRef);
}
$onDidChangeHistoryProviderHistoryItemRefs(historyItemRefs: SCMHistoryItemRefsChangeEventDto): void {
@ -736,7 +712,7 @@ export class MainThreadSCM implements MainThreadSCMShape {
}
}
async $onDidChangeHistoryProviderCurrentHistoryItemGroup(sourceControlHandle: number, historyItemGroup: SCMHistoryItemGroupDto | undefined): Promise<void> {
async $onDidChangeHistoryProviderCurrentHistoryItemRefs(sourceControlHandle: number, historyItemRef?: SCMHistoryItemRefDto, historyItemRemoteRef?: SCMHistoryItemRefDto, historyItemBaseRef?: SCMHistoryItemRefDto): Promise<void> {
await this._repositoryBarriers.get(sourceControlHandle)?.wait();
const repository = this._repositories.get(sourceControlHandle);
@ -745,7 +721,7 @@ export class MainThreadSCM implements MainThreadSCMShape {
}
const provider = repository.provider as MainThreadSCMProvider;
provider.$onDidChangeHistoryProviderCurrentHistoryItemGroup(historyItemGroup);
provider.$onDidChangeHistoryProviderCurrentHistoryItemRefs(historyItemRef, historyItemRemoteRef, historyItemBaseRef);
}
async $onDidChangeHistoryProviderHistoryItemRefs(sourceControlHandle: number, historyItemRefs: SCMHistoryItemRefsChangeEventDto): Promise<void> {

View file

@ -1542,14 +1542,6 @@ export type SCMRawResourceSplices = [
SCMRawResourceSplice[]
];
export interface SCMHistoryItemGroupDto {
readonly id: string;
readonly name: string;
readonly revision?: string;
readonly base?: Omit<Omit<SCMHistoryItemGroupDto, 'base'>, 'remote'>;
readonly remote?: Omit<Omit<SCMHistoryItemGroupDto, 'base'>, 'remote'>;
}
export interface SCMHistoryItemRefDto {
readonly id: string;
readonly name: string;
@ -1606,7 +1598,7 @@ export interface MainThreadSCMShape extends IDisposable {
$showValidationMessage(sourceControlHandle: number, message: string | IMarkdownString, type: InputValidationType): Promise<void>;
$setValidationProviderIsEnabled(sourceControlHandle: number, enabled: boolean): Promise<void>;
$onDidChangeHistoryProviderCurrentHistoryItemGroup(sourceControlHandle: number, historyItemGroup: SCMHistoryItemGroupDto | undefined): Promise<void>;
$onDidChangeHistoryProviderCurrentHistoryItemRefs(sourceControlHandle: number, historyItemRef?: SCMHistoryItemRefDto, historyItemRemoteRef?: SCMHistoryItemRefDto, historyItemBaseRef?: SCMHistoryItemRefDto): Promise<void>;
$onDidChangeHistoryProviderHistoryItemRefs(sourceControlHandle: number, historyItemRefs: SCMHistoryItemRefsChangeEventDto): Promise<void>;
}

View file

@ -79,6 +79,10 @@ function toSCMHistoryItemDto(historyItem: vscode.SourceControlHistoryItem): SCMH
return { ...historyItem, references };
}
function toSCMHistoryItemRefDto(historyItemRef?: vscode.SourceControlHistoryItemRef): SCMHistoryItemRefDto | undefined {
return historyItemRef ? { ...historyItemRef, icon: getHistoryItemIconDto(historyItemRef.icon) } : undefined;
}
function compareResourceThemableDecorations(a: vscode.SourceControlResourceThemableDecorations, b: vscode.SourceControlResourceThemableDecorations): number {
if (!a.iconPath && !b.iconPath) {
return 0;
@ -577,7 +581,6 @@ class ExtHostSourceControl implements vscode.SourceControl {
private _historyProvider: vscode.SourceControlHistoryProvider | undefined;
private readonly _historyProviderDisposable = new MutableDisposable<DisposableStore>();
private _historyProviderCurrentHistoryItemGroup: vscode.SourceControlHistoryItemGroup | undefined;
get historyProvider(): vscode.SourceControlHistoryProvider | undefined {
checkProposedApiEnabled(this._extension, 'scmHistoryProvider');
@ -593,9 +596,12 @@ class ExtHostSourceControl implements vscode.SourceControl {
this.#proxy.$updateSourceControl(this.handle, { hasHistoryProvider: !!historyProvider });
if (historyProvider) {
this._historyProviderDisposable.value.add(historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
this._historyProviderCurrentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemGroup(this.handle, this._historyProviderCurrentHistoryItemGroup);
this._historyProviderDisposable.value.add(historyProvider.onDidChangeCurrentHistoryItemRefs(() => {
const historyItemRef = toSCMHistoryItemRefDto(historyProvider?.currentHistoryItemRef);
const historyItemRemoteRef = toSCMHistoryItemRefDto(historyProvider?.currentHistoryItemRemoteRef);
const historyItemBaseRef = toSCMHistoryItemRefDto(historyProvider?.currentHistoryItemBaseRef);
this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemRefs(this.handle, historyItemRef, historyItemRemoteRef, historyItemBaseRef);
}));
this._historyProviderDisposable.value.add(historyProvider.onDidChangeHistoryItemRefs((e) => {
if (e.added.length === 0 && e.modified.length === 0 && e.removed.length === 0) {

View file

@ -39,9 +39,9 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe
private readonly _activeRepositoryCurrentHistoryItemGroupName = derived(reader => {
const repository = this.scmViewService.activeRepository.read(reader);
const historyProvider = repository?.provider.historyProvider.read(reader);
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.read(reader);
const historyItemRef = historyProvider?.historyItemRef.read(reader);
return currentHistoryItemGroup?.name;
return historyItemRef?.name;
});
private readonly _countBadgeRepositories = derived(this, reader => {

View file

@ -19,11 +19,11 @@ const CIRCLE_RADIUS = 4;
const SWIMLANE_CURVE_RADIUS = 5;
/**
* History graph colors (local, remote, base)
* History item reference colors (local, remote, base)
*/
export const historyItemGroupLocal = registerColor('scmGraph.historyItemGroupLocal', chartsBlue, localize('scmGraphHistoryItemGroupLocal', "Local history item group color."));
export const historyItemGroupRemote = registerColor('scmGraph.historyItemGroupRemote', chartsPurple, localize('scmGraphHistoryItemGroupRemote', "Remote history item group color."));
export const historyItemGroupBase = registerColor('scmGraph.historyItemGroupBase', chartsOrange, localize('scmGraphHistoryItemGroupBase', "Base history item group color."));
export const historyItemRefColor = registerColor('scmGraph.historyItemRefColor', chartsBlue, localize('scmGraphHistoryItemRefColor', "History item reference color."));
export const historyItemRemoteRefColor = registerColor('scmGraph.historyItemRemoteRefColor', chartsPurple, localize('scmGraphHistoryItemRemoteRefColor', "History item remote reference color."));
export const historyItemBaseRefColor = registerColor('scmGraph.historyItemBaseRefColor', chartsOrange, localize('scmGraphHistoryItemBaseRefColor', "History item base reference color."));
/**
* History item hover color
@ -107,7 +107,7 @@ export function renderSCMHistoryItemGraph(historyItemViewModel: ISCMHistoryItemV
// Circle color - use the output swimlane color if present, otherwise the input swimlane color
const circleColor = circleIndex < outputSwimlanes.length ? outputSwimlanes[circleIndex].color :
circleIndex < inputSwimlanes.length ? inputSwimlanes[circleIndex].color : historyItemGroupLocal;
circleIndex < inputSwimlanes.length ? inputSwimlanes[circleIndex].color : historyItemRefColor;
let outputSwimlaneIndex = 0;
for (let index = 0; index < inputSwimlanes.length; index++) {
@ -315,7 +315,7 @@ export function toISCMHistoryItemViewModelArray(historyItems: ISCMHistoryItem[],
// Circle color - use the output swimlane color if present, otherwise the input swimlane color
color = circleIndex < outputSwimlanes.length ? outputSwimlanes[circleIndex].color :
circleIndex < inputSwimlanes.length ? inputSwimlanes[circleIndex].color : historyItemGroupLocal;
circleIndex < inputSwimlanes.length ? inputSwimlanes[circleIndex].color : historyItemRefColor;
}
return { ...ref, color };

View file

@ -129,9 +129,9 @@ class SCMHistoryItemRefsActionViewItem extends ActionViewItem {
const historyProvider = this._repository.provider.historyProvider.get();
return [
historyProvider?.currentHistoryItemRef.get()?.name,
historyProvider?.currentHistoryItemRemoteRef.get()?.name,
historyProvider?.currentHistoryItemBaseRef.get()?.name
historyProvider?.historyItemRef.get()?.name,
historyProvider?.historyItemRemoteRef.get()?.name,
historyProvider?.historyItemBaseRef.get()?.name
].filter(ref => !!ref).join(', ');
} else if (this._historyItemsFilter.length === 1) {
return this._historyItemsFilter[0].name;
@ -326,7 +326,7 @@ class HistoryItemRenderer implements ITreeRenderer<SCMHistoryItemViewModelTreeEl
templateData.graphContainer.appendChild(renderSCMHistoryItemGraph(historyItemViewModel));
const provider = node.element.repository.provider;
const historyItemRef = provider.historyProvider.get()?.currentHistoryItemRef?.get();
const historyItemRef = provider.historyProvider.get()?.historyItemRef?.get();
const extraClasses = historyItemRef?.revision === historyItem.id ? ['history-item-current'] : [];
const [matches, descriptionMatches] = this._processMatches(historyItemViewModel, node.filterData);
templateData.label.setLabel(historyItem.subject, historyItem.author, { matches, descriptionMatches, extraClasses });
@ -752,9 +752,9 @@ class SCMHistoryViewModel extends Disposable {
break;
case 'auto':
historyItemRefs = [
historyProvider.currentHistoryItemRef.get(),
historyProvider.currentHistoryItemRemoteRef.get(),
historyProvider.currentHistoryItemBaseRef.get(),
historyProvider.historyItemRef.get(),
historyProvider.historyItemRemoteRef.get(),
historyProvider.historyItemBaseRef.get(),
].filter(ref => !!ref);
break;
default:
@ -801,9 +801,9 @@ class SCMHistoryViewModel extends Disposable {
private _getGraphColorMap(historyItemRefs: ISCMHistoryItemRef[]): Map<string, ColorIdentifier | undefined> {
const repository = this.repository.get();
const historyProvider = repository?.provider.historyProvider.get();
const historyItemRef = historyProvider?.currentHistoryItemRef.get();
const historyItemRemoteRef = historyProvider?.currentHistoryItemRemoteRef.get();
const historyItemBaseRef = historyProvider?.currentHistoryItemBaseRef.get();
const historyItemRef = historyProvider?.historyItemRef.get();
const historyItemRemoteRef = historyProvider?.historyItemRemoteRef.get();
const historyItemBaseRef = historyProvider?.historyItemBaseRef.get();
const colorMap = new Map<string, ColorIdentifier | undefined>();
@ -1086,7 +1086,7 @@ export class SCMHistoryViewPane extends ViewPane {
const firstRepositoryInitialized = derived(this, reader => {
const repository = this._treeViewModel.repository.read(reader);
const historyProvider = repository?.provider.historyProvider.read(reader);
const historyItemRef = historyProvider?.currentHistoryItemRef.read(reader);
const historyItemRef = historyProvider?.historyItemRef.read(reader);
return historyItemRef !== undefined ? true : undefined;
});
@ -1115,12 +1115,12 @@ export class SCMHistoryViewPane extends ViewPane {
// Publish
const historyItemRemoteRefIdSignal = signalFromObservable(this, derived(reader => {
return historyProvider.currentHistoryItemRemoteRef.read(reader)?.id;
return historyProvider.historyItemRemoteRef.read(reader)?.id;
}));
// Fetch, Push
const historyItemRemoteRefRevision = derived(reader => {
return historyProvider.currentHistoryItemRemoteRef.read(reader)?.revision;
return historyProvider.historyItemRemoteRef.read(reader)?.revision;
});
// HistoryItemRefs changed
@ -1134,7 +1134,7 @@ export class SCMHistoryViewPane extends ViewPane {
},
}, (reader, changeSummary) => {
historyItemRemoteRefIdSignal.read(reader);
const historyItemRefValue = historyProvider.currentHistoryItemRef.read(reader);
const historyItemRefValue = historyProvider.historyItemRef.read(reader);
const historyItemRemoteRefRevisionValue = historyItemRemoteRefRevision.read(reader);
// Commit, Checkout, Publish, Pull

View file

@ -63,17 +63,17 @@ export class SCMWorkingSetController extends Disposable implements IWorkbenchCon
private _onDidAddRepository(repository: ISCMRepository): void {
const disposables = new DisposableStore();
const currentHistoryItemGroupId = derived(reader => {
const historyItemRefId = derived(reader => {
const historyProvider = repository.provider.historyProvider.read(reader);
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.read(reader);
const historyItemRef = historyProvider?.historyItemRef.read(reader);
return currentHistoryItemGroup?.id;
return historyItemRef?.id;
});
disposables.add(autorun(async reader => {
const historyItemGroupId = currentHistoryItemGroupId.read(reader);
const historyItemRefIdValue = historyItemRefId.read(reader);
if (!historyItemGroupId) {
if (!historyItemRefIdValue) {
return;
}
@ -81,20 +81,20 @@ export class SCMWorkingSetController extends Disposable implements IWorkbenchCon
const repositoryWorkingSets = this._workingSets.get(providerKey);
if (!repositoryWorkingSets) {
this._workingSets.set(providerKey, { currentHistoryItemGroupId: historyItemGroupId, editorWorkingSets: new Map() });
this._workingSets.set(providerKey, { currentHistoryItemGroupId: historyItemRefIdValue, editorWorkingSets: new Map() });
return;
}
// Editors for the current working set are automatically restored
if (repositoryWorkingSets.currentHistoryItemGroupId === historyItemGroupId) {
if (repositoryWorkingSets.currentHistoryItemGroupId === historyItemRefIdValue) {
return;
}
// Save the working set
this._saveWorkingSet(providerKey, historyItemGroupId, repositoryWorkingSets);
this._saveWorkingSet(providerKey, historyItemRefIdValue, repositoryWorkingSets);
// Restore the working set
await this._restoreWorkingSet(providerKey, historyItemGroupId);
await this._restoreWorkingSet(providerKey, historyItemRefIdValue);
}));
this._repositoryDisposables.set(repository, disposables);

View file

@ -15,11 +15,9 @@ export interface ISCMHistoryProviderMenus {
}
export interface ISCMHistoryProvider {
readonly currentHistoryItemGroup: IObservable<ISCMHistoryItemGroup | undefined>;
readonly currentHistoryItemRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly currentHistoryItemRemoteRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly currentHistoryItemBaseRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly historyItemRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly historyItemRemoteRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly historyItemBaseRef: IObservable<ISCMHistoryItemRef | undefined>;
readonly historyItemRefChanges: IObservable<ISCMHistoryItemRefsChangeEvent>;
@ -35,14 +33,6 @@ export interface ISCMHistoryOptions {
readonly historyItemRefs?: readonly string[];
}
export interface ISCMHistoryItemGroup {
readonly id: string;
readonly name: string;
readonly revision?: string;
readonly base?: Omit<Omit<ISCMHistoryItemGroup, 'base'>, 'remote'>;
readonly remote?: Omit<Omit<ISCMHistoryItemGroup, 'base'>, 'remote'>;
}
export interface ISCMHistoryItemStatistics {
readonly files: number;
readonly insertions: number;

View file

@ -6,7 +6,7 @@
import * as assert from 'assert';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
import { ColorIdentifier } from '../../../../../platform/theme/common/colorUtils.js';
import { colorRegistry, historyItemGroupBase, historyItemGroupLocal, historyItemGroupRemote, toISCMHistoryItemViewModelArray } from '../../browser/scmHistory.js';
import { colorRegistry, historyItemBaseRefColor, historyItemRefColor, historyItemRemoteRefColor, toISCMHistoryItemViewModelArray } from '../../browser/scmHistory.js';
import { ISCMHistoryItem, ISCMHistoryItemRef } from '../../common/history.js';
function toSCMHistoryItem(id: string, parentIds: string[], references?: ISCMHistoryItemRef[]): ISCMHistoryItem {
@ -526,9 +526,9 @@ suite('toISCMHistoryItemViewModelArray', () => {
];
const colorMap = new Map<string, ColorIdentifier>([
['topic', historyItemGroupLocal],
['origin/topic', historyItemGroupRemote],
['origin/main', historyItemGroupBase],
['topic', historyItemRefColor],
['origin/topic', historyItemRemoteRefColor],
['origin/main', historyItemBaseRefColor],
]);
const viewModels = toISCMHistoryItemViewModelArray(models, colorMap);
@ -540,57 +540,57 @@ suite('toISCMHistoryItemViewModelArray', () => {
assert.strictEqual(viewModels[0].outputSwimlanes.length, 1);
assert.strictEqual(viewModels[0].outputSwimlanes[0].id, 'b');
assert.strictEqual(viewModels[0].outputSwimlanes[0].color, historyItemGroupLocal);
assert.strictEqual(viewModels[0].outputSwimlanes[0].color, historyItemRefColor);
// node b
assert.strictEqual(viewModels[1].inputSwimlanes.length, 1);
assert.strictEqual(viewModels[1].inputSwimlanes[0].id, 'b');
assert.strictEqual(viewModels[1].inputSwimlanes[0].color, historyItemGroupLocal);
assert.strictEqual(viewModels[1].inputSwimlanes[0].color, historyItemRefColor);
assert.strictEqual(viewModels[1].outputSwimlanes.length, 1);
assert.strictEqual(viewModels[1].outputSwimlanes[0].id, 'c');
assert.strictEqual(viewModels[1].outputSwimlanes[0].color, historyItemGroupLocal);
assert.strictEqual(viewModels[1].outputSwimlanes[0].color, historyItemRefColor);
// node c
assert.strictEqual(viewModels[2].inputSwimlanes.length, 1);
assert.strictEqual(viewModels[2].inputSwimlanes[0].id, 'c');
assert.strictEqual(viewModels[2].inputSwimlanes[0].color, historyItemGroupLocal);
assert.strictEqual(viewModels[2].inputSwimlanes[0].color, historyItemRefColor);
assert.strictEqual(viewModels[2].outputSwimlanes.length, 1);
assert.strictEqual(viewModels[2].outputSwimlanes[0].id, 'd');
assert.strictEqual(viewModels[2].outputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[2].outputSwimlanes[0].color, historyItemRemoteRefColor);
// node d
assert.strictEqual(viewModels[3].inputSwimlanes.length, 1);
assert.strictEqual(viewModels[3].inputSwimlanes[0].id, 'd');
assert.strictEqual(viewModels[3].inputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[3].inputSwimlanes[0].color, historyItemRemoteRefColor);
assert.strictEqual(viewModels[3].outputSwimlanes.length, 1);
assert.strictEqual(viewModels[3].outputSwimlanes[0].id, 'e');
assert.strictEqual(viewModels[3].outputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[3].outputSwimlanes[0].color, historyItemRemoteRefColor);
// node e
assert.strictEqual(viewModels[4].inputSwimlanes.length, 1);
assert.strictEqual(viewModels[4].inputSwimlanes[0].id, 'e');
assert.strictEqual(viewModels[4].inputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[4].inputSwimlanes[0].color, historyItemRemoteRefColor);
assert.strictEqual(viewModels[4].outputSwimlanes.length, 2);
assert.strictEqual(viewModels[4].outputSwimlanes[0].id, 'f');
assert.strictEqual(viewModels[4].outputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[4].outputSwimlanes[0].color, historyItemRemoteRefColor);
assert.strictEqual(viewModels[4].outputSwimlanes[1].id, 'g');
assert.strictEqual(viewModels[4].outputSwimlanes[1].color, historyItemGroupBase);
assert.strictEqual(viewModels[4].outputSwimlanes[1].color, historyItemBaseRefColor);
// node g
assert.strictEqual(viewModels[5].inputSwimlanes.length, 2);
assert.strictEqual(viewModels[5].inputSwimlanes[0].id, 'f');
assert.strictEqual(viewModels[5].inputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[5].inputSwimlanes[0].color, historyItemRemoteRefColor);
assert.strictEqual(viewModels[5].inputSwimlanes[1].id, 'g');
assert.strictEqual(viewModels[5].inputSwimlanes[1].color, historyItemGroupBase);
assert.strictEqual(viewModels[5].inputSwimlanes[1].color, historyItemBaseRefColor);
assert.strictEqual(viewModels[5].outputSwimlanes.length, 2);
assert.strictEqual(viewModels[5].outputSwimlanes[0].id, 'f');
assert.strictEqual(viewModels[5].outputSwimlanes[0].color, historyItemGroupRemote);
assert.strictEqual(viewModels[5].outputSwimlanes[0].color, historyItemRemoteRefColor);
assert.strictEqual(viewModels[5].outputSwimlanes[1].id, 'h');
assert.strictEqual(viewModels[5].outputSwimlanes[1].color, historyItemGroupBase);
assert.strictEqual(viewModels[5].outputSwimlanes[1].color, historyItemBaseRefColor);
});
});

View file

@ -11,13 +11,15 @@ declare module 'vscode' {
}
export interface SourceControlHistoryProvider {
currentHistoryItemGroup?: SourceControlHistoryItemGroup;
readonly currentHistoryItemRef: SourceControlHistoryItemRef | undefined;
readonly currentHistoryItemRemoteRef: SourceControlHistoryItemRef | undefined;
readonly currentHistoryItemBaseRef: SourceControlHistoryItemRef | undefined;
/**
* Fires when the current history item group changes after
* a user action (ex: commit, checkout, fetch, pull, push)
* Fires when the current history item refs (local, remote, base)
* change after a user action (ex: commit, checkout, fetch, pull, push)
*/
onDidChangeCurrentHistoryItemGroup: Event<void>;
onDidChangeCurrentHistoryItemRefs: Event<void>;
/**
* Fires when history item refs change
@ -37,14 +39,6 @@ declare module 'vscode' {
readonly historyItemRefs?: readonly string[];
}
export interface SourceControlHistoryItemGroup {
readonly id: string;
readonly name: string;
readonly revision?: string;
readonly base?: Omit<Omit<SourceControlHistoryItemGroup, 'base'>, 'remote'>;
readonly remote?: Omit<Omit<SourceControlHistoryItemGroup, 'base'>, 'remote'>;
}
export interface SourceControlHistoryItemStatistics {
readonly files: number;
readonly insertions: number;