Skip to content

Commit 6bf66a4

Browse files
committed
Fixes issues with hovers on Commit Graph
- Branch/Tag tips should now show up properly - Additions/deletions should show properly if the Changes column is on
1 parent ff05d45 commit 6bf66a4

File tree

4 files changed

+17
-45
lines changed

4 files changed

+17
-45
lines changed

src/env/node/git/localGitProvider.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
24602460
const ids = new Set<string>();
24612461
const reachableFromHEAD = new Set<string>();
24622462
const remappedIds = new Map<string, string>();
2463+
const rowStats: GitGraphRowsStats = new Map<string, GitGraphRowStats>();
24632464
let total = 0;
24642465
let iterations = 0;
24652466
let pendingRowsStatsCount = 0;
@@ -2585,7 +2586,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
25852586
let remoteBranchId: string;
25862587
let remoteName: string;
25872588
let stash: GitStashCommit | undefined;
2588-
let stats: GitGraphRowsStats | undefined;
25892589
let tagId: string;
25902590
let tagName: string;
25912591
let tip: string;
@@ -2870,10 +2870,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
28702870
});
28712871

28722872
if (commit.stats != null) {
2873-
if (stats == null) {
2874-
stats = new Map<string, GitGraphRowStats>();
2875-
}
2876-
stats.set(commit.sha, commit.stats);
2873+
rowStats.set(commit.sha, commit.stats);
28772874
}
28782875
}
28792876

@@ -2890,9 +2887,6 @@ export class LocalGitProvider implements GitProvider, Disposable {
28902887
let rowsStatsDeferred: GitGraph['rowsStatsDeferred'];
28912888

28922889
if (deferStats) {
2893-
if (stats == null) {
2894-
stats = new Map<string, GitGraphRowStats>();
2895-
}
28962890
pendingRowsStatsCount++;
28972891

28982892
// eslint-disable-next-line no-async-promise-executor
@@ -2910,7 +2904,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
29102904
if (statsData) {
29112905
const commitStats = statsParser.parse(statsData);
29122906
for (const stat of commitStats) {
2913-
stats!.set(stat.sha, stat.stats);
2907+
rowStats.set(stat.sha, stat.stats);
29142908
}
29152909
}
29162910
} finally {
@@ -2939,7 +2933,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
29392933
worktreesByBranch: worktreesByBranch,
29402934
rows: rows,
29412935
id: sha,
2942-
rowsStats: stats,
2936+
rowsStats: rowStats,
29432937
rowsStatsDeferred: rowsStatsDeferred,
29442938

29452939
paging: {

src/plus/integrations/providers/github/githubGitProvider.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import type {
5858
GitGraphRowContexts,
5959
GitGraphRowHead,
6060
GitGraphRowRemoteHead,
61-
GitGraphRowsStats,
6261
GitGraphRowStats,
6362
GitGraphRowTag,
6463
} from '../../../../git/models/graph';
@@ -1301,7 +1300,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
13011300
const ids = new Set<string>();
13021301
const remote = getSettledValue(remotesResult)![0];
13031302
const remoteMap = remote != null ? new Map([[remote.name, remote]]) : new Map<string, GitRemote>();
1304-
1303+
const rowStats = new Map<string, GitGraphRowStats>();
13051304
const tagTips = new Map<string, string[]>();
13061305
const tags = getSettledValue(tagsResult)?.values;
13071306
if (tags != null) {
@@ -1326,6 +1325,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
13261325
branchTips,
13271326
remote,
13281327
remoteMap,
1328+
rowStats,
13291329
tagTips,
13301330
getSettledValue(currentUserResult),
13311331
avatars,
@@ -1346,6 +1346,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
13461346
branchTips: Map<string, string[]>,
13471347
remote: GitRemote,
13481348
remoteMap: Map<string, GitRemote>,
1349+
rowStats: Map<string, GitGraphRowStats>,
13491350
tagTips: Map<string, string[]>,
13501351
currentUser: GitUser | undefined,
13511352
avatars: Map<string, string>,
@@ -1411,7 +1412,6 @@ export class GitHubGitProvider implements GitProvider, Disposable {
14111412
let refRemoteHeads: GitGraphRowRemoteHead[];
14121413
let refTags: GitGraphRowTag[];
14131414
let remoteBranchId: string;
1414-
let stats: GitGraphRowsStats | undefined;
14151415
let tagId: string;
14161416

14171417
const headRefUpstreamName = headBranch.upstream?.name;
@@ -1615,10 +1615,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
16151615
});
16161616

16171617
if (commit.stats != null) {
1618-
if (stats == null) {
1619-
stats = new Map<string, GitGraphRowStats>();
1620-
}
1621-
stats.set(commit.sha, {
1618+
rowStats.set(commit.sha, {
16221619
files: getChangedFilesCount(commit.stats.changedFiles),
16231620
additions: commit.stats.additions,
16241621
deletions: commit.stats.deletions,
@@ -1662,6 +1659,7 @@ export class GitHubGitProvider implements GitProvider, Disposable {
16621659
branchTips,
16631660
remote,
16641661
remoteMap,
1662+
rowStats,
16651663
tagTips,
16661664
currentUser,
16671665
avatars,

src/plus/webviews/graph/graphWebview.ts

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import { isStash } from '../../../git/models/commit';
6262
import { uncommitted } from '../../../git/models/constants';
6363
import { GitContributor } from '../../../git/models/contributor';
6464
import type { GitGraph, GitGraphRowType } from '../../../git/models/graph';
65-
import { getGkProviderThemeIconString } from '../../../git/models/graph';
6665
import type { PullRequest } from '../../../git/models/pullRequest';
6766
import {
6867
getComparisonRefsForPullRequest,
@@ -283,6 +282,9 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
283282
private _etagSubscription?: number;
284283
private _etagRepository?: number;
285284
private _firstSelection = true;
285+
private _getBranchesAndTagsTips:
286+
| ((sha: string, options?: { compact?: boolean; icons?: boolean }) => string | undefined)
287+
| undefined;
286288
private _graph?: GitGraph;
287289
private _hoverCache = new Map<string, Promise<string>>();
288290

@@ -1180,10 +1182,12 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
11801182
template = configuration.get('views.formats.commits.tooltip');
11811183
}
11821184

1185+
this._getBranchesAndTagsTips ??= await this.container.git.getBranchesAndTagsTipsLookup(commit.repoPath);
1186+
11831187
const tooltip = await CommitFormatter.fromTemplateAsync(template, commit, {
11841188
enrichedAutolinks: enrichedAutolinks,
11851189
dateFormat: configuration.get('defaultDateFormat'),
1186-
getBranchAndTagTips: this.getBranchAndTagTips.bind(this),
1190+
getBranchAndTagTips: this._getBranchesAndTagsTips,
11871191
messageAutolinks: true,
11881192
messageIndent: 4,
11891193
pullRequest: pr,
@@ -1195,32 +1199,6 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
11951199
return tooltip;
11961200
}
11971201

1198-
private getBranchAndTagTips(sha: string, options?: { compact?: boolean; icons?: boolean }): string | undefined {
1199-
if (this._graph == null) return undefined;
1200-
1201-
const row = this._graph.rows.find(r => r.sha === sha);
1202-
if (row == null) return undefined;
1203-
1204-
const tips = [];
1205-
if (row.heads?.length) {
1206-
tips.push(...row.heads.map(h => (options?.icons ? `$(git-branch) ${h.name}` : h.name)));
1207-
}
1208-
1209-
if (row.remotes?.length) {
1210-
tips.push(
1211-
...row.remotes.map(h => {
1212-
const name = `${h.owner ? `${h.owner}/` : ''}${h.name}`;
1213-
return options?.icons ? `$(${getGkProviderThemeIconString(h.hostingServiceType)}) ${name}` : name;
1214-
}),
1215-
);
1216-
}
1217-
if (row.tags?.length) {
1218-
tips.push(...row.tags.map(h => (options?.icons ? `$(tag) ${h.name}` : h.name)));
1219-
}
1220-
1221-
return tips.join(', ') || undefined;
1222-
}
1223-
12241202
@debug()
12251203
private async onEnsureRowRequest<T extends typeof EnsureRowRequest>(requestType: T, msg: IpcCallMessageType<T>) {
12261204
if (this._graph == null) return;
@@ -2949,6 +2927,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
29492927
}
29502928

29512929
private resetRepositoryState() {
2930+
this._getBranchesAndTagsTips = undefined;
29522931
this.setGraph(undefined);
29532932
this.setSelectedRows(undefined);
29542933
}

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ export function GraphWrapper({
355355
setIsLoading(state.loading);
356356
break;
357357
case DidChangeRowsStatsNotification:
358+
hover.current?.reset();
358359
setRowsStats(state.rowsStats);
359360
setRowsStatsLoading(state.rowsStatsLoading);
360361
break;

0 commit comments

Comments
 (0)