Git - 💄 add historyItemParentId to provideHistoryItemChanges (#201991)

This commit is contained in:
Ladislau Szomoru 2024-01-08 14:00:57 +01:00 committed by GitHub
parent b0b59b4c5a
commit 51e490e8a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 32 deletions

View file

@ -78,12 +78,12 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
throw new Error('Unsupported options.'); throw new Error('Unsupported options.');
} }
const optionsRef = options.limit.id; const refParentId = options.limit.id;
const historyItemGroupIdRef = await this.repository.revParse(historyItemGroupId) ?? ''; const refId = await this.repository.revParse(historyItemGroupId) ?? '';
const [commits, summary] = await Promise.all([ const [summary, commits] = await Promise.all([
this.repository.log({ range: `${optionsRef}..${historyItemGroupIdRef}`, shortStats: true, sortByAuthorDate: true }), this.getSummaryHistoryItem(refId, refParentId),
this.getSummaryHistoryItem(optionsRef, historyItemGroupIdRef) this.repository.log({ range: `${refParentId}..${refId}`, shortStats: true, sortByAuthorDate: true })
]); ]);
await ensureEmojis(); await ensureEmojis();
@ -107,20 +107,15 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return historyItems; return historyItems;
} }
async provideHistoryItemChanges(historyItemId: string): Promise<SourceControlHistoryItemChange[]> { async provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<SourceControlHistoryItemChange[]> {
// The "All Changes" history item uses a special id if (!historyItemParentId) {
// which is a commit range instead of a single commit id const commit = await this.repository.getCommit(historyItemId);
let [originalRef, modifiedRef] = historyItemId.includes('..') historyItemParentId = commit.parents.length > 0 ? commit.parents[0] : `${historyItemId}^`;
? historyItemId.split('..') : [undefined, historyItemId];
if (!originalRef) {
const commit = await this.repository.getCommit(modifiedRef);
originalRef = commit.parents.length > 0 ? commit.parents[0] : `${modifiedRef}^`;
} }
const historyItemChangesUri: Uri[] = []; const historyItemChangesUri: Uri[] = [];
const historyItemChanges: SourceControlHistoryItemChange[] = []; const historyItemChanges: SourceControlHistoryItemChange[] = [];
const changes = await this.repository.diffBetween(originalRef, modifiedRef); const changes = await this.repository.diffBetween(historyItemParentId, historyItemId);
for (const change of changes) { for (const change of changes) {
const historyItemUri = change.uri.with({ const historyItemUri = change.uri.with({
@ -130,8 +125,8 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
// History item change // History item change
historyItemChanges.push({ historyItemChanges.push({
uri: historyItemUri, uri: historyItemUri,
originalUri: toGitUri(change.originalUri, originalRef), originalUri: toGitUri(change.originalUri, historyItemParentId),
modifiedUri: toGitUri(change.originalUri, modifiedRef), modifiedUri: toGitUri(change.originalUri, historyItemId),
renameUri: change.renameUri, renameUri: change.renameUri,
}); });
@ -208,9 +203,9 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return new FileDecoration(letter, tooltip, color); return new FileDecoration(letter, tooltip, color);
} }
private async getSummaryHistoryItem(ref1: string, ref2: string): Promise<SourceControlHistoryItem> { private async getSummaryHistoryItem(refId: string, refParentId: string): Promise<SourceControlHistoryItem> {
const statistics = await this.repository.diffBetweenShortStat(ref1, ref2); const statistics = await this.repository.diffBetweenShortStat(refParentId, refId);
return { id: `${ref1}..${ref2}`, parentIds: [], icon: new ThemeIcon('files'), label: l10n.t('All Changes'), statistics }; return { id: refId, parentIds: [refParentId], icon: new ThemeIcon('files'), label: l10n.t('All Changes'), statistics };
} }
dispose(): void { dispose(): void {

View file

@ -187,8 +187,8 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
return historyItems?.map(historyItem => ({ ...historyItem, icon: getIconFromIconDto(historyItem.icon) })); return historyItems?.map(historyItem => ({ ...historyItem, icon: getIconFromIconDto(historyItem.icon) }));
} }
async provideHistoryItemChanges(historyItemId: string): Promise<ISCMHistoryItemChange[] | undefined> { async provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined> {
const changes = await this.proxy.$provideHistoryItemChanges(this.handle, historyItemId, CancellationToken.None); const changes = await this.proxy.$provideHistoryItemChanges(this.handle, historyItemId, historyItemParentId, CancellationToken.None);
return changes?.map(change => ({ return changes?.map(change => ({
uri: URI.revive(change.uri), uri: URI.revive(change.uri),
originalUri: change.originalUri && URI.revive(change.originalUri), originalUri: change.originalUri && URI.revive(change.originalUri),

View file

@ -2220,7 +2220,7 @@ export interface ExtHostSCMShape {
$validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string | IMarkdownString, number] | undefined>; $validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string | IMarkdownString, number] | undefined>;
$setSelectedSourceControl(selectedSourceControlHandle: number | undefined): Promise<void>; $setSelectedSourceControl(selectedSourceControlHandle: number | undefined): Promise<void>;
$provideHistoryItems(sourceControlHandle: number, historyItemGroupId: string, options: any, token: CancellationToken): Promise<SCMHistoryItemDto[] | undefined>; $provideHistoryItems(sourceControlHandle: number, historyItemGroupId: string, options: any, token: CancellationToken): Promise<SCMHistoryItemDto[] | undefined>;
$provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined>; $provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined>;
$resolveHistoryItemGroupBase(sourceControlHandle: number, historyItemGroupId: string, token: CancellationToken): Promise<SCMHistoryItemGroupDto | undefined>; $resolveHistoryItemGroupBase(sourceControlHandle: number, historyItemGroupId: string, token: CancellationToken): Promise<SCMHistoryItemGroupDto | undefined>;
$resolveHistoryItemGroupCommonAncestor(sourceControlHandle: number, historyItemGroupId1: string, historyItemGroupId2: string, token: CancellationToken): Promise<{ id: string; ahead: number; behind: number } | undefined>; $resolveHistoryItemGroupCommonAncestor(sourceControlHandle: number, historyItemGroupId1: string, historyItemGroupId2: string, token: CancellationToken): Promise<{ id: string; ahead: number; behind: number } | undefined>;
} }

View file

@ -955,8 +955,8 @@ export class ExtHostSCM implements ExtHostSCMShape {
return historyItems?.map(item => ({ ...item, icon: getHistoryItemIconDto(item) })) ?? undefined; return historyItems?.map(item => ({ ...item, icon: getHistoryItemIconDto(item) })) ?? undefined;
} }
async $provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined> { async $provideHistoryItemChanges(sourceControlHandle: number, historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): Promise<SCMHistoryItemChangeDto[] | undefined> {
const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider; const historyProvider = this._sourceControls.get(sourceControlHandle)?.historyProvider;
return await historyProvider?.provideHistoryItemChanges(historyItemId, token) ?? undefined; return await historyProvider?.provideHistoryItemChanges(historyItemId, historyItemParentId, token) ?? undefined;
} }
} }

View file

@ -1257,7 +1257,7 @@ function getSCMResourceId(element: TreeElement): string {
} else if (isSCMHistoryItemTreeElement(element)) { } else if (isSCMHistoryItemTreeElement(element)) {
const historyItemGroup = element.historyItemGroup; const historyItemGroup = element.historyItemGroup;
const provider = historyItemGroup.repository.provider; const provider = historyItemGroup.repository.provider;
return `historyItem:${provider.id}/${historyItemGroup.id}/${element.id}`; return `historyItem:${provider.id}/${historyItemGroup.id}/${element.id}/${element.parentIds.join(',')}`;
} else if (isSCMHistoryItemChangeTreeElement(element)) { } else if (isSCMHistoryItemChangeTreeElement(element)) {
const historyItem = element.historyItem; const historyItem = element.historyItem;
const historyItemGroup = historyItem.historyItemGroup; const historyItemGroup = historyItem.historyItemGroup;
@ -1713,7 +1713,8 @@ class HistoryItemViewChangesAction extends Action2 {
return; return;
} }
const historyItemChanges = await historyProvider.provideHistoryItemChanges(historyItem.id); const historyItemParentId = historyItem.parentIds.length > 0 ? historyItem.parentIds[0] : undefined;
const historyItemChanges = await historyProvider.provideHistoryItemChanges(historyItem.id, historyItemParentId);
if (!historyItemChanges || historyItemChanges.length === 0) { if (!historyItemChanges || historyItemChanges.length === 0) {
return; return;
} }
@ -3417,13 +3418,17 @@ class SCMTreeDataSource implements IAsyncDataSource<ISCMViewService, TreeElement
const historyProviderCacheEntry = this.getHistoryProviderCacheEntry(repository); const historyProviderCacheEntry = this.getHistoryProviderCacheEntry(repository);
const historyItemChangesMap = historyProviderCacheEntry.historyItemChanges; const historyItemChangesMap = historyProviderCacheEntry.historyItemChanges;
let historyItemChanges = historyItemChangesMap.get(element.id);
const historyItemParentId = element.parentIds.length > 0 ? element.parentIds[0] : undefined;
let historyItemChanges = historyItemChangesMap.get(`${element.id}/${historyItemParentId}`);
if (!historyItemChanges) { if (!historyItemChanges) {
historyItemChanges = await historyProvider.provideHistoryItemChanges(element.id) ?? []; const historyItemParentId = element.parentIds.length > 0 ? element.parentIds[0] : undefined;
historyItemChanges = await historyProvider.provideHistoryItemChanges(element.id, historyItemParentId) ?? [];
this.historyProviderCache.set(repository, { this.historyProviderCache.set(repository, {
...historyProviderCacheEntry, ...historyProviderCacheEntry,
historyItemChanges: historyItemChangesMap.set(element.id, historyItemChanges) historyItemChanges: historyItemChangesMap.set(`${element.id}/${historyItemParentId}`, historyItemChanges)
}); });
} }

View file

@ -21,7 +21,7 @@ export interface ISCMHistoryProvider {
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined); set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined);
provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>; provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
provideHistoryItemChanges(historyItemId: string): Promise<ISCMHistoryItemChange[] | undefined>; provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined): Promise<ISCMHistoryItemChange[] | undefined>;
resolveHistoryItemGroupBase(historyItemGroupId: string): Promise<ISCMHistoryItemGroup | undefined>; resolveHistoryItemGroupBase(historyItemGroupId: string): Promise<ISCMHistoryItemGroup | undefined>;
resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string): Promise<{ id: string; ahead: number; behind: number } | undefined>; resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId2: string): Promise<{ id: string; ahead: number; behind: number } | undefined>;
resolveHistoryItemGroupDetails(historyItemGroup: ISCMHistoryItemGroup): Promise<ISCMHistoryItemGroupDetails | undefined>; resolveHistoryItemGroupDetails(historyItemGroup: ISCMHistoryItemGroup): Promise<ISCMHistoryItemGroupDetails | undefined>;

View file

@ -25,7 +25,7 @@ declare module 'vscode' {
// onDidChangeHistoryItemGroups: Event<SourceControlHistoryChangeEvent>; // onDidChangeHistoryItemGroups: Event<SourceControlHistoryChangeEvent>;
provideHistoryItems(historyItemGroupId: string, options: SourceControlHistoryOptions, token: CancellationToken): ProviderResult<SourceControlHistoryItem[]>; provideHistoryItems(historyItemGroupId: string, options: SourceControlHistoryOptions, token: CancellationToken): ProviderResult<SourceControlHistoryItem[]>;
provideHistoryItemChanges(historyItemId: string, token: CancellationToken): ProviderResult<SourceControlHistoryItemChange[]>; provideHistoryItemChanges(historyItemId: string, historyItemParentId: string | undefined, token: CancellationToken): ProviderResult<SourceControlHistoryItemChange[]>;
resolveHistoryItemGroupBase(historyItemGroupId: string, token: CancellationToken): ProviderResult<SourceControlHistoryItemGroup | undefined>; resolveHistoryItemGroupBase(historyItemGroupId: string, token: CancellationToken): ProviderResult<SourceControlHistoryItemGroup | undefined>;
resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId: string, token: CancellationToken): ProviderResult<{ id: string; ahead: number; behind: number }>; resolveHistoryItemGroupCommonAncestor(historyItemGroupId1: string, historyItemGroupId: string, token: CancellationToken): ProviderResult<{ id: string; ahead: number; behind: number }>;