diff --git a/extensions/git/src/historyProvider.ts b/extensions/git/src/historyProvider.ts index b7ebb00e980..bf083f723fb 100644 --- a/extensions/git/src/historyProvider.ts +++ b/extensions/git/src/historyProvider.ts @@ -132,26 +132,18 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec } async provideHistoryItems2(options: SourceControlHistoryOptions): Promise { - if (!this.currentHistoryItemGroup || !options.historyItemGroupIds) { + if (!this.currentHistoryItemGroup || !options.historyItemGroupIds || typeof options.limit === 'number' || !options.limit?.id) { return []; } // Deduplicate refNames const refNames = Array.from(new Set(options.historyItemGroupIds)); - // Get the merge base of the refNames - const refsMergeBase = await this.resolveHistoryItemGroupsMergeBase(refNames); - if (!refsMergeBase) { - return []; - } - - const historyItems: SourceControlHistoryItem[] = []; - try { // Get the common ancestor commit, and commits const [mergeBaseCommit, commits] = await Promise.all([ - this.repository.getCommit(refsMergeBase), - this.repository.log({ range: `${refsMergeBase}..`, refNames, shortStats: true }) + this.repository.getCommit(options.limit.id), + this.repository.log({ range: `${options.limit.id}..`, refNames, shortStats: true }) ]); // Add common ancestor commit @@ -161,7 +153,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec await ensureEmojis(); - historyItems.push(...commits.map(commit => { + return commits.map(commit => { const newLineIndex = commit.message.indexOf('\n'); const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message; @@ -177,12 +169,11 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec statistics: commit.shortStat ?? { files: 0, insertions: 0, deletions: 0 }, labels: labels.length !== 0 ? labels : undefined }; - })); + }); } catch (err) { - this.logger.error(`[GitHistoryProvider][provideHistoryItems2] Failed to get history items '${refsMergeBase}..': ${err}`); + this.logger.error(`[GitHistoryProvider][provideHistoryItems2] Failed to get history items '${options.limit.id}..': ${err}`); + return []; } - - return historyItems; } async provideHistoryItemSummary(historyItemId: string, historyItemParentId: string | undefined): Promise { @@ -260,17 +251,39 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec return undefined; } - provideFileDecoration(uri: Uri): FileDecoration | undefined { - return this.historyItemDecorations.get(uri.toString()); - } + async resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[]): Promise { + try { + if (historyItemGroupIds.length === 0) { + // TODO@lszomoru - log + return undefined; + } else if (historyItemGroupIds.length === 1 && historyItemGroupIds[0] === this.currentHistoryItemGroup?.id) { + // Remote + if (this.currentHistoryItemGroup.remote) { + const ancestor = await this.repository.getMergeBase(historyItemGroupIds[0], this.currentHistoryItemGroup.remote.id); + return ancestor; + } - private async resolveHistoryItemGroupsMergeBase(refNames: string[]): Promise { - if (refNames.length < 2) { - return undefined; + // Base + if (this.currentHistoryItemGroup.base) { + const ancestor = await this.repository.getMergeBase(historyItemGroupIds[0], this.currentHistoryItemGroup.base.id); + return ancestor; + } + + // TODO@lszomoru - Return first commit + } else if (historyItemGroupIds.length > 1) { + const ancestor = await this.repository.getMergeBase(historyItemGroupIds[0], historyItemGroupIds[1], ...historyItemGroupIds.slice(2)); + return ancestor; + } + } + catch (err) { + this.logger.error(`[GitHistoryProvider][resolveHistoryItemGroupCommonAncestor2] Failed to resolve common ancestor for ${historyItemGroupIds.join(',')}: ${err}`); } - const refsMergeBase = await this.repository.getMergeBase(refNames[0], refNames[1], ...refNames.slice(2)); - return refsMergeBase; + return undefined; + } + + provideFileDecoration(uri: Uri): FileDecoration | undefined { + return this.historyItemDecorations.get(uri.toString()); } private resolveHistoryItemLabels(commit: Commit, refNames: string[]): SourceControlHistoryItemLabel[] { diff --git a/src/vs/workbench/api/browser/mainThreadSCM.ts b/src/vs/workbench/api/browser/mainThreadSCM.ts index af9d3f401cf..1311f30eb71 100644 --- a/src/vs/workbench/api/browser/mainThreadSCM.ts +++ b/src/vs/workbench/api/browser/mainThreadSCM.ts @@ -180,6 +180,10 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider { return this.proxy.$resolveHistoryItemGroupCommonAncestor(this.handle, historyItemGroupId1, historyItemGroupId2, CancellationToken.None); } + async resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[]): Promise { + return this.proxy.$resolveHistoryItemGroupCommonAncestor2(this.handle, historyItemGroupIds, CancellationToken.None); + } + async provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise { const historyItems = await this.proxy.$provideHistoryItems(this.handle, historyItemGroupId, options, CancellationToken.None); return historyItems?.map(historyItem => toISCMHistoryItem(historyItem)); diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 5d118042116..ae3c9f43ea7 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -2333,6 +2333,7 @@ export interface ExtHostSCMShape { $provideHistoryItemSummary(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise; $provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise; $resolveHistoryItemGroupCommonAncestor(sourceControlHandle: number, historyItemGroupId1: string, historyItemGroupId2: string | undefined, token: CancellationToken): Promise<{ id: string; ahead: number; behind: number } | undefined>; + $resolveHistoryItemGroupCommonAncestor2(sourceControlHandle: number, historyItemGroupIds: string[], token: CancellationToken): Promise; } export interface ExtHostQuickDiffShape { diff --git a/src/vs/workbench/api/common/extHostSCM.ts b/src/vs/workbench/api/common/extHostSCM.ts index 46f25cb7dd2..b07e8f498b2 100644 --- a/src/vs/workbench/api/common/extHostSCM.ts +++ b/src/vs/workbench/api/common/extHostSCM.ts @@ -972,6 +972,11 @@ export class ExtHostSCM implements ExtHostSCMShape { return await historyProvider?.resolveHistoryItemGroupCommonAncestor(historyItemGroupId1, historyItemGroupId2, token) ?? undefined; } + async $resolveHistoryItemGroupCommonAncestor2(sourceControlHandle: number, historyItemGroupIds: string[], token: CancellationToken): Promise { + const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider; + return await historyProvider?.resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds, token) ?? undefined; + } + async $provideHistoryItems(sourceControlHandle: number, historyItemGroupId: string, options: any, token: CancellationToken): Promise { const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider; const historyItems = await historyProvider?.provideHistoryItems(historyItemGroupId, options, token); diff --git a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts index cb7db2c6c4f..04ae69dc457 100644 --- a/src/vs/workbench/contrib/scm/browser/scmViewPane.ts +++ b/src/vs/workbench/contrib/scm/browser/scmViewPane.ts @@ -4074,7 +4074,15 @@ class SCMTreeDataSource extends Disposable implements IAsyncDataSource; provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise; resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string | undefined): Promise<{ id: string; ahead: number; behind: number } | undefined>; + resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[]): Promise; } export interface ISCMHistoryProviderCacheEntry { diff --git a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts index 9d3151733aa..ee0fdcb8572 100644 --- a/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts +++ b/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts @@ -30,6 +30,7 @@ declare module 'vscode' { provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): ProviderResult; resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string | undefined, token: CancellationToken): ProviderResult<{ id: string; ahead: number; behind: number }>; + resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[], token: CancellationToken): ProviderResult; } export interface SourceControlHistoryOptions {