Skip to content

Commit 00082d1

Browse files
authored
SCM - use fixed references when paging in more data (microsoft#226425)
1 parent d6394ad commit 00082d1

File tree

2 files changed

+47
-31
lines changed

2 files changed

+47
-31
lines changed

extensions/git/src/historyProvider.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
165165
const newLineIndex = commit.message.indexOf('\n');
166166
const subject = newLineIndex !== -1 ? commit.message.substring(0, newLineIndex) : commit.message;
167167

168-
const labels = this.resolveHistoryItemLabels(commit, refNames);
168+
const labels = this.resolveHistoryItemLabels(commit);
169169

170170
return {
171171
id: commit.hash,
@@ -292,14 +292,10 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
292292
return this.historyItemDecorations.get(uri.toString());
293293
}
294294

295-
private resolveHistoryItemLabels(commit: Commit, refNames: string[]): SourceControlHistoryItemLabel[] {
295+
private resolveHistoryItemLabels(commit: Commit): SourceControlHistoryItemLabel[] {
296296
const labels: SourceControlHistoryItemLabel[] = [];
297297

298298
for (const label of commit.refNames) {
299-
if (!label.startsWith('HEAD -> ') && !refNames.includes(label)) {
300-
continue;
301-
}
302-
303299
for (const [key, value] of this.historyItemLabels) {
304300
if (label.startsWith(key)) {
305301
labels.push({

src/vs/workbench/contrib/scm/browser/scmHistoryViewPane.ts

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { IViewDescriptorService, ViewContainerLocation } from 'vs/workbench/comm
3838
import { renderSCMHistoryItemGraph, historyItemGroupLocal, historyItemGroupRemote, historyItemGroupBase, historyItemGroupHoverLabelForeground, toISCMHistoryItemViewModelArray, SWIMLANE_WIDTH, renderSCMHistoryGraphPlaceholder } from 'vs/workbench/contrib/scm/browser/scmHistory';
3939
import { RepositoryActionRunner } from 'vs/workbench/contrib/scm/browser/scmRepositoryRenderer';
4040
import { collectContextMenuActions, connectPrimaryMenu, getActionViewItemProvider, isSCMHistoryItemLoadMoreTreeElement, isSCMHistoryItemViewModelTreeElement, isSCMRepository, isSCMViewService } from 'vs/workbench/contrib/scm/browser/util';
41-
import { ISCMHistoryItem, ISCMHistoryItemViewModel, SCMHistoryItemLoadMoreTreeElement, SCMHistoryItemViewModelTreeElement } from 'vs/workbench/contrib/scm/common/history';
41+
import { ISCMHistoryItem, ISCMHistoryItemGroup, ISCMHistoryItemViewModel, SCMHistoryItemLoadMoreTreeElement, SCMHistoryItemViewModelTreeElement } from 'vs/workbench/contrib/scm/common/history';
4242
import { HISTORY_VIEW_PANE_ID, ISCMProvider, ISCMRepository, ISCMViewService, ISCMViewVisibleRepositoryChangeEvent } from 'vs/workbench/contrib/scm/common/scm';
4343
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
4444
import { stripIcons } from 'vs/base/common/iconLabels';
@@ -237,8 +237,11 @@ class HistoryItemRenderer implements ITreeRenderer<SCMHistoryItemViewModelTreeEl
237237
const instantHoverDelegate = createInstantHoverDelegate();
238238
templateData.elementDisposables.add(instantHoverDelegate);
239239

240+
// Get lits of labels to render (current, remote, base)
241+
const labels = this.getLabels(node.element.repository);
242+
240243
for (const label of historyItem.labels) {
241-
if (label.icon && ThemeIcon.isThemeIcon(label.icon)) {
244+
if (label.icon && ThemeIcon.isThemeIcon(label.icon) && labels.includes(label.title)) {
242245
const icon = append(templateData.labelContainer, $('div.label'));
243246
icon.classList.add(...ThemeIcon.asClassNameArray(label.icon));
244247

@@ -249,6 +252,15 @@ class HistoryItemRenderer implements ITreeRenderer<SCMHistoryItemViewModelTreeEl
249252
}
250253
}
251254

255+
private getLabels(repository: ISCMRepository): string[] {
256+
const currentHistoryItemGroup = repository.provider.historyProvider.get()?.currentHistoryItemGroup.get();
257+
if (!currentHistoryItemGroup) {
258+
return [];
259+
}
260+
261+
return [currentHistoryItemGroup.name, currentHistoryItemGroup.remote?.name ?? '', currentHistoryItemGroup.base?.name ?? ''];
262+
}
263+
252264
private getTooltip(element: SCMHistoryItemViewModelTreeElement): IManagedHoverTooltipMarkdownString {
253265
const colorTheme = this.themeService.getColorTheme();
254266
const historyItem = element.historyItemViewModel.historyItem;
@@ -519,10 +531,10 @@ class SCMHistoryTreeKeyboardNavigationLabelProvider implements IKeyboardNavigati
519531
}
520532
}
521533

522-
type HistoryItemCacheEntry = { items: ISCMHistoryItem[]; loadMore: boolean };
534+
type HistoryItemState = { currentHistoryItemGroup: ISCMHistoryItemGroup; items: ISCMHistoryItem[]; loadMore: boolean };
523535

524536
class SCMHistoryTreeDataSource extends Disposable implements IAsyncDataSource<ISCMViewService, TreeElement> {
525-
private readonly _historyItems = new Map<ISCMRepository, HistoryItemCacheEntry>();
537+
private readonly _state = new Map<ISCMRepository, HistoryItemState>();
526538

527539
constructor(
528540
@IConfigurationService private readonly _configurationService: IConfigurationService,
@@ -572,47 +584,56 @@ class SCMHistoryTreeDataSource extends Disposable implements IAsyncDataSource<IS
572584
}
573585
}
574586

575-
clearCache(repository?: ISCMRepository): void {
587+
clearState(repository?: ISCMRepository): void {
576588
if (!repository) {
577-
this._historyItems.clear();
589+
this._state.clear();
578590
return;
579591
}
580592

581-
this._historyItems.delete(repository);
593+
this._state.delete(repository);
594+
}
595+
596+
getState(repository: ISCMRepository): HistoryItemState | undefined {
597+
return this._state.get(repository);
582598
}
583599

584600
loadMore(repository: ISCMRepository): void {
585-
const entry = this._historyItems.get(repository);
586-
this._historyItems.set(repository, { items: entry?.items ?? [], loadMore: true });
601+
const state = this._state.get(repository);
602+
if (!state) {
603+
return;
604+
}
605+
606+
this._state.set(repository, { ...state, loadMore: true });
587607
}
588608

589609
private async _getHistoryItems(element: ISCMRepository): Promise<SCMHistoryItemViewModelTreeElement[]> {
610+
let state = this._state.get(element);
590611
const historyProvider = element.provider.historyProvider.get();
591-
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.get();
612+
const currentHistoryItemGroup = state?.currentHistoryItemGroup ?? historyProvider?.currentHistoryItemGroup.get();
592613

593614
if (!historyProvider || !currentHistoryItemGroup) {
594615
return [];
595616
}
596617

597-
let historyItemsCacheEntry = this._historyItems.get(element);
598-
if (!historyItemsCacheEntry || historyItemsCacheEntry.loadMore) {
618+
if (!state || state.loadMore) {
599619
const historyItemGroupIds = [
600-
currentHistoryItemGroup.id,
601-
...currentHistoryItemGroup.remote ? [currentHistoryItemGroup.remote.id] : [],
602-
...currentHistoryItemGroup.base ? [currentHistoryItemGroup.base.id] : [],
620+
currentHistoryItemGroup.revision ?? currentHistoryItemGroup.id,
621+
...currentHistoryItemGroup.remote ? [currentHistoryItemGroup.remote.revision ?? currentHistoryItemGroup.remote.id] : [],
622+
...currentHistoryItemGroup.base ? [currentHistoryItemGroup.base.revision ?? currentHistoryItemGroup.base.id] : [],
603623
];
604624

605-
const existingHistoryItems = historyItemsCacheEntry?.items ?? [];
625+
const existingHistoryItems = state?.items ?? [];
606626
const historyItems = await historyProvider.provideHistoryItems2({
607627
historyItemGroupIds, limit: 50, skip: existingHistoryItems.length
608628
}) ?? [];
609629

610-
historyItemsCacheEntry = {
630+
state = {
631+
currentHistoryItemGroup,
611632
items: [...existingHistoryItems, ...historyItems],
612633
loadMore: false
613634
};
614635

615-
this._historyItems.set(element, historyItemsCacheEntry);
636+
this._state.set(element, state);
616637
}
617638

618639
// Create the color map
@@ -626,7 +647,7 @@ class SCMHistoryTreeDataSource extends Disposable implements IAsyncDataSource<IS
626647
colorMap.set(currentHistoryItemGroup.base.name, historyItemGroupBase);
627648
}
628649

629-
return toISCMHistoryItemViewModelArray(historyItemsCacheEntry.items, colorMap)
650+
return toISCMHistoryItemViewModelArray(state.items, colorMap)
630651
.map(historyItemViewModel => ({
631652
repository: element,
632653
historyItemViewModel,
@@ -635,7 +656,7 @@ class SCMHistoryTreeDataSource extends Disposable implements IAsyncDataSource<IS
635656
}
636657

637658
override dispose(): void {
638-
this._historyItems.clear();
659+
this._state.clear();
639660
super.dispose();
640661
}
641662
}
@@ -721,15 +742,15 @@ export class SCMHistoryViewPane extends ViewPane {
721742
this._tree.scrollTop = 0;
722743
});
723744
} else {
724-
this._treeDataSource.clearCache();
745+
this._treeDataSource.clearState();
725746
this._visibilityDisposables.clear();
726747
this._repositories.clearAndDisposeAll();
727748
}
728749
});
729750
}
730751

731752
async refresh(repository?: ISCMRepository): Promise<void> {
732-
this._treeDataSource.clearCache(repository);
753+
this._treeDataSource.clearState(repository);
733754
this._updateChildren(repository);
734755

735756
this._tree.scrollTop = 0;
@@ -857,7 +878,7 @@ export class SCMHistoryViewPane extends ViewPane {
857878
}
858879

859880
this._tree.scrollTop = 0;
860-
this._treeDataSource.clearCache(repository);
881+
this._treeDataSource.clearState(repository);
861882
this._updateChildren(repository);
862883
}));
863884

@@ -866,7 +887,7 @@ export class SCMHistoryViewPane extends ViewPane {
866887

867888
// Removed repositories
868889
for (const repository of removed) {
869-
this._treeDataSource.clearCache(repository);
890+
this._treeDataSource.clearState(repository);
870891
this._repositories.deleteAndDispose(repository);
871892
}
872893

@@ -906,7 +927,6 @@ export class SCMHistoryViewPane extends ViewPane {
906927
await this._tree.updateChildren(element, undefined, undefined, {
907928
// diffIdentityProvider: this._treeIdentityProvider
908929
});
909-
//}
910930
} else {
911931
// Refresh the entire tree
912932
await this._tree.updateChildren(undefined, undefined, undefined, {

0 commit comments

Comments
 (0)