Skip to content

Commit

Permalink
Git - update base branch revision when it changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru committed Jan 9, 2025
1 parent 0c176cf commit 0e27c34
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions extensions/git/src/historyProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
readonly onDidChangeHistoryItemRefs: Event<SourceControlHistoryItemRefsChangeEvent> = this._onDidChangeHistoryItemRefs.event;

private _HEAD: Branch | undefined;
private historyItemRefs: SourceControlHistoryItemRef[] = [];
private _historyItemRefs: SourceControlHistoryItemRef[] = [];

private historyItemDecorations = new Map<string, FileDecoration>();

Expand All @@ -112,6 +112,14 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return;
}

// Refs (alphabetically)
const historyItemRefs = this.repository.refs
.map(ref => toSourceControlHistoryItemRef(this.repository, ref))
.sort((a, b) => a.id.localeCompare(b.id));

const delta = deltaHistoryItemRefs(this._historyItemRefs, historyItemRefs);
this._historyItemRefs = historyItemRefs;

let historyItemRefId = '';
let historyItemRefName = '';

Expand All @@ -130,8 +138,9 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
icon: new ThemeIcon('cloud')
} : undefined;

// Base - compute only if the branch has changed
// Base
if (this._HEAD?.name !== this.repository.HEAD.name) {
// Compute base if the branch has changed
const mergeBase = await this.resolveHEADMergeBase();

this._currentHistoryItemBaseRef = mergeBase &&
Expand All @@ -142,6 +151,17 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
revision: mergeBase.commit,
icon: new ThemeIcon('cloud')
} : undefined;
} else {
// Update base revision if it has changed
const mergeBaseModified = delta.modified
.find(ref => ref.id === this._currentHistoryItemBaseRef?.id);

if (this._currentHistoryItemBaseRef && mergeBaseModified) {
this._currentHistoryItemBaseRef = {
...this._currentHistoryItemBaseRef,
revision: mergeBaseModified.revision
};
}
}
} else {
// Detached commit
Expand Down Expand Up @@ -178,18 +198,10 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
this.logger.trace(`[GitHistoryProvider][onDidRunWriteOperation] currentHistoryItemRemoteRef: ${JSON.stringify(this._currentHistoryItemRemoteRef)}`);
this.logger.trace(`[GitHistoryProvider][onDidRunWriteOperation] currentHistoryItemBaseRef: ${JSON.stringify(this._currentHistoryItemBaseRef)}`);

// Refs (alphabetically)
const historyItemRefs = this.repository.refs
.map(ref => toSourceControlHistoryItemRef(this.repository, ref))
.sort((a, b) => a.id.localeCompare(b.id));

// Auto-fetch
const silent = result.operation.kind === OperationKind.Fetch && result.operation.showProgress === false;
const delta = deltaHistoryItemRefs(this.historyItemRefs, historyItemRefs);
this._onDidChangeHistoryItemRefs.fire({ ...delta, silent });

this.historyItemRefs = historyItemRefs;

const deltaLog = {
added: delta.added.map(ref => ref.id),
modified: delta.modified.map(ref => ref.id),
Expand Down

0 comments on commit 0e27c34

Please sign in to comment.