Skip to content

Commit 61d0d5b

Browse files
committed
Adds a contributors section to comparison results
1 parent 1af2ef6 commit 61d0d5b

14 files changed

+170
-40
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Adds a _Contributors_ section to comparison results in the views
12+
913
## [16.1.1] - 2024-12-20
1014

1115
### Added

contributions.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10138,6 +10138,32 @@
1013810138
]
1013910139
}
1014010140
},
10141+
"gitlens.views.setContributorsStatisticsOff": {
10142+
"label": "Hide Contributors Statistics",
10143+
"icon": "$(graph-line)",
10144+
"menus": {
10145+
"view/item/context": [
10146+
{
10147+
"when": "viewItem == gitlens:contributors && config.gitlens.views.showContributorsStatistics",
10148+
"group": "inline",
10149+
"order": 99
10150+
}
10151+
]
10152+
}
10153+
},
10154+
"gitlens.views.setContributorsStatisticsOn": {
10155+
"label": "Show Contributors Statistics",
10156+
"icon": "$(graph-line)",
10157+
"menus": {
10158+
"view/item/context": [
10159+
{
10160+
"when": "viewItem == gitlens:contributors && !config.gitlens.views.showContributorsStatistics",
10161+
"group": "inline",
10162+
"order": 99
10163+
}
10164+
]
10165+
}
10166+
},
1014110167
"gitlens.views.setResultsCommitsFilterAuthors": {
1014210168
"label": "Filter Commits by Author...",
1014310169
"icon": "$(filter)",

package.json

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,27 @@
15521552
"scope": "window",
15531553
"order": 5
15541554
},
1555+
"gitlens.views.showComparisonContributors": {
1556+
"type": "boolean",
1557+
"default": true,
1558+
"markdownDescription": "Specifies whether to show a _Contributors_ section on comparison results in the views",
1559+
"scope": "window",
1560+
"order": 6
1561+
},
1562+
"gitlens.views.showContributorsStatistics": {
1563+
"type": "boolean",
1564+
"default": false,
1565+
"markdownDescription": "Specifies whether to show contributor statistics in _Contributors_ sections in the views. This can take a while to compute depending on the repository size",
1566+
"scope": "window",
1567+
"order": 7
1568+
},
1569+
"gitlens.views.showRelativeDateMarkers": {
1570+
"type": "boolean",
1571+
"default": true,
1572+
"markdownDescription": "Specifies whether to show relative date markers (_Less than a week ago_, _Over a week ago_, _Over a month ago_, etc) on revision (commit) histories in the views",
1573+
"scope": "window",
1574+
"order": 8
1575+
},
15551576
"gitlens.views.defaultItemLimit": {
15561577
"type": "number",
15571578
"default": 10,
@@ -1566,13 +1587,6 @@
15661587
"scope": "window",
15671588
"order": 11
15681589
},
1569-
"gitlens.views.showRelativeDateMarkers": {
1570-
"type": "boolean",
1571-
"default": true,
1572-
"markdownDescription": "Specifies whether to show relative date markers (_Less than a week ago_, _Over a week ago_, _Over a month ago_, etc) on revision (commit) histories in the views",
1573-
"scope": "window",
1574-
"order": 20
1575-
},
15761590
"gitlens.views.formats.commits.label": {
15771591
"type": "string",
15781592
"default": "${❰ tips|11? ❱➤ }${message}",
@@ -9067,6 +9081,16 @@
90679081
"title": "Compare with Working Tree",
90689082
"icon": "$(compare-changes)"
90699083
},
9084+
{
9085+
"command": "gitlens.views.setContributorsStatisticsOff",
9086+
"title": "Hide Contributors Statistics",
9087+
"icon": "$(graph-line)"
9088+
},
9089+
{
9090+
"command": "gitlens.views.setContributorsStatisticsOn",
9091+
"title": "Show Contributors Statistics",
9092+
"icon": "$(graph-line)"
9093+
},
90709094
{
90719095
"command": "gitlens.views.setResultsCommitsFilterAuthors",
90729096
"title": "Filter Commits by Author...",
@@ -12510,6 +12534,14 @@
1251012534
"command": "gitlens.views.setBranchComparisonToWorking",
1251112535
"when": "false"
1251212536
},
12537+
{
12538+
"command": "gitlens.views.setContributorsStatisticsOff",
12539+
"when": "false"
12540+
},
12541+
{
12542+
"command": "gitlens.views.setContributorsStatisticsOn",
12543+
"when": "false"
12544+
},
1251312545
{
1251412546
"command": "gitlens.views.setResultsCommitsFilterAuthors",
1251512547
"when": "false"
@@ -15849,6 +15881,16 @@
1584915881
"when": "viewItem =~ /gitlens:contributors\\b/ && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",
1585015882
"group": "inline@1"
1585115883
},
15884+
{
15885+
"command": "gitlens.views.setContributorsStatisticsOff",
15886+
"when": "viewItem == gitlens:contributors && config.gitlens.views.showContributorsStatistics",
15887+
"group": "inline@99"
15888+
},
15889+
{
15890+
"command": "gitlens.views.setContributorsStatisticsOn",
15891+
"when": "viewItem == gitlens:contributors && !config.gitlens.views.showContributorsStatistics",
15892+
"group": "inline@99"
15893+
},
1585215894
{
1585315895
"command": "gitlens.views.addAuthors",
1585415896
"when": "viewItem =~ /gitlens:contributors\\b/ && !listMultiSelection && !gitlens:hasVirtualFolders && !gitlens:readonly && !gitlens:untrusted",

src/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,16 @@ export interface ViewsCommonConfig {
673673
readonly tooltip: string;
674674
};
675675
};
676+
readonly openChangesInMultiDiffEditor: boolean;
677+
readonly pageItemLimit: number;
676678
readonly scm: {
677679
grouped: {
678680
readonly default: GroupableTreeViewTypes;
679681
readonly views: Record<GroupableTreeViewTypes, boolean>;
680682
};
681683
};
682-
readonly openChangesInMultiDiffEditor: boolean;
683-
readonly pageItemLimit: number;
684+
readonly showComparisonContributors: boolean;
685+
readonly showContributorsStatistics: boolean;
684686
readonly showCurrentBranchOnTop: boolean;
685687
readonly showRelativeDateMarkers: boolean;
686688
}
@@ -689,7 +691,10 @@ export const viewsCommonConfigKeys: (keyof ViewsCommonConfig)[] = [
689691
'collapseWorktreesWhenPossible',
690692
'defaultItemLimit',
691693
'formats',
694+
'openChangesInMultiDiffEditor',
692695
'pageItemLimit',
696+
'showComparisonContributors',
697+
'showContributorsStatistics',
693698
'showCurrentBranchOnTop',
694699
'showRelativeDateMarkers',
695700
];

src/constants.commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ export type TreeViewCommands = `gitlens.views.${
662662
| 'openWorktreeInNewWindow'
663663
| 'openWorktreeInNewWindow.multi'
664664
| 'setResultsCommitsFilterAuthors'
665-
| 'setResultsCommitsFilterOff'}`;
665+
| 'setResultsCommitsFilterOff'
666+
| 'setContributorsStatisticsOff'
667+
| 'setContributorsStatisticsOn'}`;
666668

667669
type ExtractSuffix<Prefix extends string, U> = U extends `${Prefix}${infer V}` ? V : never;
668670
type FilterCommands<Prefix extends string, U> = U extends `${Prefix}${infer V}` ? `${Prefix}${V}` : never;

src/views/nodes/compareBranchNode.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { GlyphChars } from '../../constants';
55
import type { StoredBranchComparison, StoredBranchComparisons, StoredNamedRef } from '../../constants.storage';
66
import type { GitUri } from '../../git/gitUri';
77
import type { GitBranch } from '../../git/models/branch';
8-
import { createRevisionRange , shortenRevision } from '../../git/models/revision.utils';
8+
import { createRevisionRange, shortenRevision } from '../../git/models/revision.utils';
99
import type { GitUser } from '../../git/models/user';
1010
import type { CommitsQueryResults, FilesQueryResults } from '../../git/queryResults';
1111
import { getCommitsQuery, getFilesQuery } from '../../git/queryResults';
@@ -118,8 +118,11 @@ export class CompareBranchNode extends SubscribeableViewNode<
118118
if (this._compareWith == null) return [];
119119

120120
if (this.children == null) {
121-
const ahead = this.ahead;
122-
const behind = this.behind;
121+
const ahead = {
122+
...this.ahead,
123+
range: createRevisionRange(this.ahead.ref1, this.compareWithWorkingTree ? '' : this.ahead.ref2, '..'),
124+
};
125+
const behind = { ...this.behind, range: createRevisionRange(this.behind.ref1, this.behind.ref2, '..') };
123126

124127
const counts = await this.view.container.git.getLeftRightCommitCount(
125128
this.branch.repoPath,
@@ -138,7 +141,7 @@ export class CompareBranchNode extends SubscribeableViewNode<
138141
this.repoPath,
139142
'Behind',
140143
{
141-
query: this.getCommitsQuery(createRevisionRange(behind.ref1, behind.ref2, '..')),
144+
query: this.getCommitsQuery(behind.range),
142145
comparison: behind,
143146
direction: 'behind',
144147
files: {
@@ -158,9 +161,7 @@ export class CompareBranchNode extends SubscribeableViewNode<
158161
this.repoPath,
159162
'Ahead',
160163
{
161-
query: this.getCommitsQuery(
162-
createRevisionRange(ahead.ref1, this.compareWithWorkingTree ? '' : ahead.ref2, '..'),
163-
),
164+
query: this.getCommitsQuery(ahead.ref1),
164165
comparison: ahead,
165166
direction: 'ahead',
166167
files: {

src/views/nodes/compareResultsNode.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Disposable, ThemeIcon, TreeItem, TreeItemCheckboxState, TreeItemCollaps
44
import type { StoredNamedRef } from '../../constants.storage';
55
import type { FilesComparison } from '../../git/actions/commit';
66
import { GitUri } from '../../git/gitUri';
7-
import { createRevisionRange , shortenRevision } from '../../git/models/revision.utils';
7+
import { createRevisionRange, shortenRevision } from '../../git/models/revision.utils';
88
import type { GitUser } from '../../git/models/user';
99
import type { CommitsQueryResults, FilesQueryResults } from '../../git/queryResults';
1010
import { getAheadBehindFilesQuery, getCommitsQuery, getFilesQuery } from '../../git/queryResults';
@@ -133,8 +133,11 @@ export class CompareResultsNode extends SubscribeableViewNode<
133133

134134
async getChildren(): Promise<ViewNode[]> {
135135
if (this.children == null) {
136-
const ahead = this.ahead;
137-
const behind = this.behind;
136+
const ahead = {
137+
...this.ahead,
138+
range: createRevisionRange(this.ahead.ref1, this.ahead.ref2, '..'),
139+
};
140+
const behind = { ...this.behind, range: createRevisionRange(this.behind.ref1, this.behind.ref2, '..') };
138141

139142
const counts = await this.view.container.git.getLeftRightCommitCount(
140143
this.repoPath,
@@ -154,7 +157,7 @@ export class CompareResultsNode extends SubscribeableViewNode<
154157
this.repoPath,
155158
'Behind',
156159
{
157-
query: this.getCommitsQuery(createRevisionRange(behind.ref1, behind.ref2, '..')),
160+
query: this.getCommitsQuery(behind.range),
158161
comparison: behind,
159162
direction: 'behind',
160163
files: {
@@ -174,7 +177,7 @@ export class CompareResultsNode extends SubscribeableViewNode<
174177
this.repoPath,
175178
'Ahead',
176179
{
177-
query: this.getCommitsQuery(createRevisionRange(ahead.ref1, ahead.ref2, '..')),
180+
query: this.getCommitsQuery(ahead.range),
178181
comparison: ahead,
179182
direction: 'ahead',
180183
files: {

src/views/nodes/contributorsNode.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ export class ContributorsNode extends CacheableChildrenViewNode<
2424
view: ViewsWithContributorsNode,
2525
protected override readonly parent: ViewNode,
2626
public readonly repo: Repository,
27-
private readonly options?: { all?: boolean; showMergeCommits?: boolean; stats?: boolean },
27+
private readonly options?: {
28+
all?: boolean;
29+
icon?: boolean;
30+
ref?: string;
31+
showMergeCommits?: boolean;
32+
stats?: boolean;
33+
},
2834
) {
2935
super('contributors', uri, view, parent);
3036

@@ -42,11 +48,11 @@ export class ContributorsNode extends CacheableChildrenViewNode<
4248

4349
async getChildren(): Promise<ViewNode[]> {
4450
if (this.children == null) {
45-
const all = this.options?.all ?? configuration.get('views.contributors.showAllBranches');
51+
let ref = this.options?.ref;
52+
const all = ref == null && (this.options?.all ?? configuration.get('views.contributors.showAllBranches'));
4653

47-
let ref: string | undefined;
48-
// If we aren't getting all branches, get the upstream of the current branch if there is one
49-
if (!all) {
54+
// If there is no ref and we aren't getting all branches, get the upstream of the current branch if there is one
55+
if (ref == null && !all) {
5056
try {
5157
const branch = await this.view.container.git.getBranch(this.uri.repoPath);
5258
if (branch?.upstream?.name != null && !branch.upstream.missing) {
@@ -88,7 +94,9 @@ export class ContributorsNode extends CacheableChildrenViewNode<
8894
const item = new TreeItem('Contributors', TreeItemCollapsibleState.Collapsed);
8995
item.id = this.id;
9096
item.contextValue = ContextValues.Contributors;
91-
item.iconPath = new ThemeIcon('organization');
97+
if (this.options?.icon !== false) {
98+
item.iconPath = new ThemeIcon('organization');
99+
}
92100
return item;
93101
}
94102

src/views/nodes/pullRequestNode.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ export async function getPullRequestChildren(
177177
const comparison = {
178178
ref1: refs.base.ref,
179179
ref2: refs.head.ref,
180+
range: createRevisionRange(refs.base.ref, refs.head.ref, '..'),
180181
};
181182

182183
const children = [
@@ -186,11 +187,7 @@ export async function getPullRequestChildren(
186187
repoPath,
187188
'Commits',
188189
{
189-
query: getCommitsQuery(
190-
view.container,
191-
repoPath,
192-
createRevisionRange(comparison.ref1, comparison.ref2, '..'),
193-
),
190+
query: getCommitsQuery(view.container, repoPath, comparison.range),
194191
comparison: comparison,
195192
},
196193
{

src/views/nodes/repositoryNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ export class RepositoryNode extends SubscribeableViewNode<'repository', ViewsWit
189189
}
190190

191191
if (this.view.config.showContributors) {
192-
children.push(new ContributorsNode(this.uri, this.view, this, this.repo));
192+
children.push(
193+
new ContributorsNode(this.uri, this.view, this, this.repo, {
194+
stats: this.view.config.showContributorsStatistics,
195+
}),
196+
);
193197
}
194198

195199
if (this.view.config.showIncomingActivity && !this.repo.provider.virtual) {

0 commit comments

Comments
 (0)