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

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[] {