Skip to content

Commit

Permalink
SCM Graph - add option to return only a subset of history item refere…
Browse files Browse the repository at this point in the history
…nces (#228932)
  • Loading branch information
lszomoru committed Sep 18, 2024
1 parent be74c1f commit 47a8de0
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export interface InitOptions {
export interface RefQuery {
readonly contains?: string;
readonly count?: number;
readonly pattern?: string;
readonly pattern?: string | string[];
readonly sort?: 'alphabetically' | 'committerdate';
}

Expand Down
5 changes: 4 additions & 1 deletion extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2431,7 +2431,10 @@ export class Repository {
args.push('--format', '%(refname) %(objectname) %(*objectname)');

if (query.pattern) {
args.push(query.pattern.startsWith('refs/') ? query.pattern : `refs/${query.pattern}`);
const patterns = Array.isArray(query.pattern) ? query.pattern : [query.pattern];
for (const pattern of patterns) {
args.push(pattern.startsWith('refs/') ? pattern : `refs/${pattern}`);
}
}

if (query.contains) {
Expand Down
4 changes: 2 additions & 2 deletions extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
this.logger.trace(`[GitHistoryProvider][onDidRunWriteOperation] historyItemRefs: ${JSON.stringify(deltaLog)}`);
}

async provideHistoryItemRefs(): Promise<SourceControlHistoryItemRef[]> {
const refs = await this.repository.getRefs();
async provideHistoryItemRefs(historyItemRefs: string[] | undefined): Promise<SourceControlHistoryItemRef[]> {
const refs = await this.repository.getRefs({ pattern: historyItemRefs });

const branches: SourceControlHistoryItemRef[] = [];
const remoteBranches: SourceControlHistoryItemRef[] = [];
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
return this.proxy.$resolveHistoryItemRefsCommonAncestor(this.handle, historyItemRefs, CancellationToken.None);
}

async provideHistoryItemRefs(): Promise<ISCMHistoryItemRef[] | undefined> {
const historyItemRefs = await this.proxy.$provideHistoryItemRefs(this.handle, CancellationToken.None);
async provideHistoryItemRefs(historyItemsRefs?: string[]): Promise<ISCMHistoryItemRef[] | undefined> {
const historyItemRefs = await this.proxy.$provideHistoryItemRefs(this.handle, historyItemsRefs, CancellationToken.None);
return historyItemRefs?.map(ref => ({ ...ref, icon: getIconFromIconDto(ref.icon) }));
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,7 @@ export interface ExtHostSCMShape {
$executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number, preserveFocus: boolean): Promise<void>;
$validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string | IMarkdownString, number] | undefined>;
$setSelectedSourceControl(selectedSourceControlHandle: number | undefined): Promise<void>;
$provideHistoryItemRefs(sourceControlHandle: number, token: CancellationToken): Promise<SCMHistoryItemRefDto[] | undefined>;
$provideHistoryItemRefs(sourceControlHandle: number, historyItemRefs: string[] | undefined, token: CancellationToken): Promise<SCMHistoryItemRefDto[] | undefined>;
$provideHistoryItems(sourceControlHandle: number, options: any, token: CancellationToken): Promise<SCMHistoryItemDto[] | undefined>;
$provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined>;
$resolveHistoryItemRefsCommonAncestor(sourceControlHandle: number, historyItemRefs: string[], token: CancellationToken): Promise<string | undefined>;
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,11 @@ export class ExtHostSCM implements ExtHostSCMShape {
return await historyProvider?.resolveHistoryItemRefsCommonAncestor(historyItemRefs, token) ?? undefined;
}

async $provideHistoryItemRefs(sourceControlHandle: number, token: CancellationToken): Promise<SCMHistoryItemRefDto[] | undefined> {
async $provideHistoryItemRefs(sourceControlHandle: number, historyItemRefs: string[] | undefined, token: CancellationToken): Promise<SCMHistoryItemRefDto[] | undefined> {
const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider;
const historyItemRefs = await historyProvider?.provideHistoryItemRefs(token);
const refs = await historyProvider?.provideHistoryItemRefs(historyItemRefs, token);

return historyItemRefs?.map(ref => ({ ...ref, icon: getHistoryItemIconDto(ref.icon) })) ?? undefined;
return refs?.map(ref => ({ ...ref, icon: getHistoryItemIconDto(ref.icon) })) ?? undefined;
}

async $provideHistoryItems(sourceControlHandle: number, options: any, token: CancellationToken): Promise<SCMHistoryItemDto[] | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ class SCMHistoryViewModel extends Disposable {
break;
default: {
// Get the latest revisions for the history items references in the filer
const refs = (await historyProvider.provideHistoryItemRefs() ?? [])
const refs = (await historyProvider.provideHistoryItemRefs(historyItemsFilter) ?? [])
.filter(ref => historyItemsFilter.some(filter => filter === ref.id));

if (refs.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/common/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface ISCMHistoryProvider {

readonly historyItemRefChanges: IObservable<ISCMHistoryItemRefsChangeEvent>;

provideHistoryItemRefs(): Promise<ISCMHistoryItemRef[] | undefined>;
provideHistoryItemRefs(historyItemsRefs?: string[]): Promise<ISCMHistoryItemRef[] | undefined>;
provideHistoryItems(options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined>;
resolveHistoryItemRefsCommonAncestor(historyItemRefs: string[]): Promise<string | undefined>;
Expand Down
2 changes: 1 addition & 1 deletion src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare module 'vscode' {
*/
onDidChangeHistoryItemRefs: Event<SourceControlHistoryItemRefsChangeEvent>;

provideHistoryItemRefs(token: CancellationToken): ProviderResult<SourceControlHistoryItemRef[]>;
provideHistoryItemRefs(historyItemRefs: string[] | undefined, token: CancellationToken): ProviderResult<SourceControlHistoryItemRef[]>;
provideHistoryItems(options: SourceControlHistoryOptions, token: CancellationToken): ProviderResult<SourceControlHistoryItem[]>;
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): ProviderResult<SourceControlHistoryItemChange[]>;

Expand Down

0 comments on commit 47a8de0

Please sign in to comment.