SCM - refactoring to enable filtering of history item groups (#221395)

This commit is contained in:
Ladislau Szomoru
2024-07-10 20:00:19 +02:00
committed by GitHub
parent bc67f5aa71
commit 233ccb7df9
7 changed files with 58 additions and 25 deletions
+37 -24
View File
@@ -132,26 +132,18 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
}
async provideHistoryItems2(options: SourceControlHistoryOptions): Promise<SourceControlHistoryItem[]> {
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<string>(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<SourceControlHistoryItem> {
@@ -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<string | undefined> {
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<string | undefined> {
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[] {
@@ -180,6 +180,10 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
return this.proxy.$resolveHistoryItemGroupCommonAncestor(this.handle, historyItemGroupId1, historyItemGroupId2, CancellationToken.None);
}
async resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[]): Promise<string | undefined> {
return this.proxy.$resolveHistoryItemGroupCommonAncestor2(this.handle, historyItemGroupIds, CancellationToken.None);
}
async provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined> {
const historyItems = await this.proxy.$provideHistoryItems(this.handle, historyItemGroupId, options, CancellationToken.None);
return historyItems?.map(historyItem => toISCMHistoryItem(historyItem));
@@ -2333,6 +2333,7 @@ export interface ExtHostSCMShape {
$provideHistoryItemSummary(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemDto | undefined>;
$provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined>;
$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<string | undefined>;
}
export interface ExtHostQuickDiffShape {
@@ -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<string | undefined> {
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<SCMHistoryItemDto[] | undefined> {
const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider;
const historyItems = await historyProvider?.provideHistoryItems(historyItemGroupId, options, token);
@@ -4074,7 +4074,15 @@ class SCMTreeDataSource extends Disposable implements IAsyncDataSource<ISCMViewS
...currentHistoryItemGroup.base ? [currentHistoryItemGroup.base.id] : [],
];
historyItemsElement = await historyProvider.provideHistoryItems2({ historyItemGroupIds }) ?? [];
// Common ancestor of current, remote, base independent of the select history item group
const ancestor = await historyProvider.resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds);
if (!ancestor) {
return [];
}
// History items of selected history item groups
historyItemsElement = await historyProvider.provideHistoryItems2({ historyItemGroupIds, limit: { id: ancestor } }) ?? [];
this.historyProviderCache.update(element, {
historyItems2: historyItemsMap.set(element.id, historyItemsElement)
});
@@ -30,6 +30,7 @@ export interface ISCMHistoryProvider {
provideHistoryItemSummary(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItem | undefined>;
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined>;
resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string | undefined): Promise<{ id: string; ahead: number; behind: number } | undefined>;
resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[]): Promise<string | undefined>;
}
export interface ISCMHistoryProviderCacheEntry {
@@ -30,6 +30,7 @@ declare module 'vscode' {
provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): ProviderResult<SourceControlHistoryItemChange[]>;
resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string | undefined, token: CancellationToken): ProviderResult<{ id: string; ahead: number; behind: number }>;
resolveHistoryItemGroupCommonAncestor2(historyItemGroupIds: string[], token: CancellationToken): ProviderResult<string>;
}
export interface SourceControlHistoryOptions {