Skip to content

Commit b60637f

Browse files
committed
Closes #1335 - improves the contributors view
Contributors view will now show commits from the upstream, if one exists Adds new contributors view options - Sorting options - Option to show all branches
1 parent 44a6bcc commit b60637f

23 files changed

+418
-88
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
883883
| `gitlens.views.contributors.files.threshold` | Specifies when to switch between displaying files as a `tree` or `list` based on the number of files in a nesting level in the _Contributors_ view<br />Only applies when `gitlens.views.commits.files.layout` is set to `auto` |
884884
| `gitlens.views.contributors.pullRequests.enabled` | Specifies whether to query for pull requests associated with the current branch and commits in the _Contributors_ view. Requires a connection to a supported remote service (e.g. GitHub) |
885885
| `gitlens.views.contributors.pullRequests.showForCommits` | Specifies whether to show pull requests (if any) associated with the current branch in the _Contributors_ view. Requires a connection to a supported remote service (e.g. GitHub) |
886+
| `gitlens.views.contributors.showAllBranches` | Specifies whether to show commits from all branches in the _Contributors_ view |
886887

887888
## Search & Compare View Settings [#](#search-&-compare-view-settings- 'Search & Compare View Settings')
888889

@@ -963,8 +964,9 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
963964
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
964965
| `gitlens.defaultDateFormat` | Specifies how absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats |
965966
| `gitlens.defaultDateShortFormat` | Specifies how short absolute dates will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats |
966-
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
967967
| `gitlens.defaultDateSource` | Specifies whether commit dates should use the authored or committed date |
968+
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
969+
| `gitlens.defaultTimeFormat` | Specifies how times will be formatted by default. See the [Moment.js docs](https://momentjs.com/docs/#/displaying/format/) for valid formats |
968970

969971
## Menu & Toolbar Settings [#](#menu--toolbar-settings- 'Menu & Toolbar Settings')
970972

@@ -1003,6 +1005,9 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
10031005
| `gitlens.outputLevel` | Specifies how much (if any) output will be sent to the GitLens output channel |
10041006
| `gitlens.showWelcomeOnInstall` | Specifies whether to show the Welcome (Quick Setup) experience on first install |
10051007
| `gitlens.showWhatsNewAfterUpgrades` | Specifies whether to show the What's New notification after upgrading to new feature releases |
1008+
| `gitlens.sortBranchesBy` | Specifies how branches are sorted in quick pick menus and views |
1009+
| `gitlens.sortContributorsBy` | Specifies how contributors are sorted in quick pick menus and views |
1010+
| `gitlens.sortTagsBy` | Specifies how tags are sorted in quick pick menus and views |
10061011
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of abbreviated commit SHAs (shas) |
10071012
| `gitlens.advanced.abbreviateShaOnCopy` | Specifies whether to copy full or abbreviated commit SHAs to the clipboard. Abbreviates to the length of `gitlens.advanced.abbreviatedShaLength`.. |
10081013
| `gitlens.advanced.blame.customArguments` | Specifies additional arguments to pass to the `git blame` command |

package.json

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,36 +1580,58 @@
15801580
},
15811581
"gitlens.sortBranchesBy": {
15821582
"type": "string",
1583-
"default": "name:asc",
1583+
"default": "date:desc",
15841584
"enum": [
1585-
"name:asc",
1586-
"name:desc",
15871585
"date:desc",
1588-
"date:asc"
1586+
"date:asc",
1587+
"name:asc",
1588+
"name:desc"
15891589
],
15901590
"enumDescriptions": [
1591-
"Sorts branches by name in ascending order",
1592-
"Sorts branches by name in descending order",
15931591
"Sorts branches by the most recent commit date in descending order",
1594-
"Sorts branches by the most recent commit date in ascending order"
1592+
"Sorts branches by the most recent commit date in ascending order",
1593+
"Sorts branches by name in ascending order",
1594+
"Sorts branches by name in descending order"
15951595
],
15961596
"markdownDescription": "Specifies how branches are sorted in quick pick menus and views",
15971597
"scope": "window"
15981598
},
1599+
"gitlens.sortContributorsBy": {
1600+
"type": "string",
1601+
"default": "count:desc",
1602+
"enum": [
1603+
"count:desc",
1604+
"count:asc",
1605+
"date:desc",
1606+
"date:asc",
1607+
"name:asc",
1608+
"name:desc"
1609+
],
1610+
"enumDescriptions": [
1611+
"Sorts contributors by commit count in descending order",
1612+
"Sorts contributors by commit count in ascending order",
1613+
"Sorts contributors by the most recent commit date in descending order",
1614+
"Sorts contributors by the most recent commit date in ascending order",
1615+
"Sorts contributors by name in ascending order",
1616+
"Sorts contributors by name in descending order"
1617+
],
1618+
"markdownDescription": "Specifies how contributors are sorted in quick pick menus and views",
1619+
"scope": "window"
1620+
},
15991621
"gitlens.sortTagsBy": {
16001622
"type": "string",
16011623
"default": "date:desc",
16021624
"enum": [
1603-
"name:asc",
1604-
"name:desc",
16051625
"date:desc",
1606-
"date:asc"
1626+
"date:asc",
1627+
"name:asc",
1628+
"name:desc"
16071629
],
16081630
"enumDescriptions": [
1609-
"Sorts tags by name in ascending order",
1610-
"Sorts tags by name in descending order",
16111631
"Sorts tags by date in descending order",
1612-
"Sorts tags by date in ascending order"
1632+
"Sorts tags by date in ascending order",
1633+
"Sorts tags by name in ascending order",
1634+
"Sorts tags by name in descending order"
16131635
],
16141636
"markdownDescription": "Specifies how tags are sorted in quick pick menus and views",
16151637
"scope": "window"
@@ -1965,6 +1987,12 @@
19651987
"markdownDescription": "Specifies whether to show pull requests (if any) associated with commits in the _Contributors_ view. Requires a connection to a supported remote service (e.g. GitHub)",
19661988
"scope": "window"
19671989
},
1990+
"gitlens.views.contributors.showAllBranches": {
1991+
"type": "boolean",
1992+
"default": false,
1993+
"markdownDescription": "Specifies whether to show commits from all branches in the _Contributors_ view",
1994+
"scope": "window"
1995+
},
19681996
"gitlens.views.defaultItemLimit": {
19691997
"type": "number",
19701998
"default": 10,
@@ -4593,6 +4621,16 @@
45934621
"category": "GitLens",
45944622
"icon": "$(list-flat)"
45954623
},
4624+
{
4625+
"command": "gitlens.views.contributors.setShowAllBranchesOn",
4626+
"title": "Toggle Filter: Only Current Branch",
4627+
"category": "GitLens"
4628+
},
4629+
{
4630+
"command": "gitlens.views.contributors.setShowAllBranchesOff",
4631+
"title": "Toggle Filter: All Branches",
4632+
"category": "GitLens"
4633+
},
45964634
{
45974635
"command": "gitlens.views.contributors.setShowAvatarsOn",
45984636
"title": "Show Avatars",
@@ -6128,6 +6166,14 @@
61286166
"command": "gitlens.views.contributors.setFilesLayoutToTree",
61296167
"when": "false"
61306168
},
6169+
{
6170+
"command": "gitlens.views.contributors.setShowAllBranchesOn",
6171+
"when": "false"
6172+
},
6173+
{
6174+
"command": "gitlens.views.contributors.setShowAllBranchesOff",
6175+
"when": "false"
6176+
},
61316177
{
61326178
"command": "gitlens.views.contributors.setShowAvatarsOn",
61336179
"when": "false"
@@ -7079,6 +7125,16 @@
70797125
"when": "view =~ /^gitlens\\.views\\.contributors/ && config.gitlens.views.contributors.files.layout == list",
70807126
"group": "3_gitlens@0"
70817127
},
7128+
{
7129+
"command": "gitlens.views.contributors.setShowAllBranchesOn",
7130+
"when": "view =~ /^gitlens\\.views\\.contributors/ && !config.gitlens.views.contributors.showAllBranches",
7131+
"group": "3_gitlens@1"
7132+
},
7133+
{
7134+
"command": "gitlens.views.contributors.setShowAllBranchesOff",
7135+
"when": "view =~ /^gitlens\\.views\\.contributors/ && config.gitlens.views.contributors.showAllBranches",
7136+
"group": "3_gitlens@1"
7137+
},
70827138
{
70837139
"command": "gitlens.views.contributors.setShowAvatarsOn",
70847140
"when": "view =~ /^gitlens\\.views\\.contributors/ && !config.gitlens.views.contributors.avatars",

src/config.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export interface Config {
122122
showWelcomeOnInstall: boolean;
123123
showWhatsNewAfterUpgrades: boolean;
124124
sortBranchesBy: BranchSorting;
125+
sortContributorsBy: ContributorSorting;
125126
sortTagsBy: TagSorting;
126127
statusBar: {
127128
alignment: 'left' | 'right';
@@ -170,10 +171,10 @@ export enum BlameHighlightLocations {
170171
}
171172

172173
export enum BranchSorting {
173-
NameDesc = 'name:desc',
174-
NameAsc = 'name:asc',
175174
DateDesc = 'date:desc',
176175
DateAsc = 'date:asc',
176+
NameAsc = 'name:asc',
177+
NameDesc = 'name:desc',
177178
}
178179

179180
export enum ChangesLocations {
@@ -205,6 +206,15 @@ export enum CodeLensScopes {
205206
Blocks = 'blocks',
206207
}
207208

209+
export enum ContributorSorting {
210+
CountDesc = 'count:desc',
211+
CountAsc = 'count:asc',
212+
DateDesc = 'date:desc',
213+
DateAsc = 'date:asc',
214+
NameAsc = 'name:asc',
215+
NameDesc = 'name:desc',
216+
}
217+
208218
export enum CustomRemoteType {
209219
Bitbucket = 'Bitbucket',
210220
BitbucketServer = 'BitbucketServer',
@@ -276,10 +286,10 @@ export enum StatusBarCommand {
276286
}
277287

278288
export enum TagSorting {
279-
NameDesc = 'name:desc',
280-
NameAsc = 'name:asc',
281289
DateDesc = 'date:desc',
282290
DateAsc = 'date:asc',
291+
NameAsc = 'name:asc',
292+
NameDesc = 'name:desc',
283293
}
284294

285295
export enum ViewBranchesLayout {
@@ -552,6 +562,7 @@ export interface ContributorsViewConfig {
552562
enabled: boolean;
553563
showForCommits: boolean;
554564
};
565+
showAllBranches: boolean;
555566
}
556567

557568
export interface FileHistoryViewConfig {

src/git/git.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ export namespace Git {
740740
repoPath: string,
741741
ref: string | undefined,
742742
{
743+
all,
743744
authors,
744745
format = 'default',
745746
limit,
@@ -749,8 +750,9 @@ export namespace Git {
749750
similarityThreshold,
750751
since,
751752
}: {
753+
all?: boolean;
752754
authors?: string[];
753-
format?: 'refs' | 'default';
755+
format?: 'default' | 'refs' | 'shortlog';
754756
limit?: number;
755757
merges?: boolean;
756758
ordering?: string | null;
@@ -761,13 +763,19 @@ export namespace Git {
761763
) {
762764
const params = [
763765
'log',
764-
`--format=${format === 'refs' ? GitLogParser.simpleRefs : GitLogParser.defaultFormat}`,
766+
`--format=${
767+
format === 'refs'
768+
? GitLogParser.simpleRefs
769+
: format === 'shortlog'
770+
? GitLogParser.shortlog
771+
: GitLogParser.defaultFormat
772+
}`,
765773
'--full-history',
766774
`-M${similarityThreshold == null ? '' : `${similarityThreshold}%`}`,
767775
'-m',
768776
];
769777

770-
if (format !== 'refs') {
778+
if (format === 'default') {
771779
params.push('--name-status');
772780
}
773781

@@ -789,6 +797,12 @@ export namespace Git {
789797

790798
if (authors != null && authors.length !== 0) {
791799
params.push('--use-mailmap', ...authors.map(a => `--author=${a}`));
800+
} else if (format === 'shortlog') {
801+
params.push('--use-mailmap');
802+
}
803+
804+
if (all) {
805+
params.push('--all');
792806
}
793807

794808
if (ref && !GitRevision.isUncommittedStaged(ref)) {
@@ -828,7 +842,7 @@ export namespace Git {
828842
all?: boolean;
829843
filters?: GitDiffFilter[];
830844
firstParent?: boolean;
831-
format?: 'refs' | 'simple' | 'default';
845+
format?: 'default' | 'refs' | 'simple';
832846
limit?: number;
833847
ordering?: string | null;
834848
renames?: boolean;

src/git/gitService.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ export class GitService implements Disposable {
248248
CommitDateFormatting.reset();
249249
PullRequestDateFormatting.reset();
250250
}
251+
252+
if (configuration.changed(e, 'views', 'contributors', 'showAllBranches')) {
253+
this._contributorsCache.clear();
254+
}
251255
}
252256

253257
@debug()
@@ -1512,35 +1516,17 @@ export class GitService implements Disposable {
15121516
}
15131517

15141518
@log()
1515-
async getContributors(repoPath: string): Promise<GitContributor[]> {
1519+
async getContributors(repoPath: string, options?: { all?: boolean; ref?: string }): Promise<GitContributor[]> {
15161520
if (repoPath == null) return [];
15171521

15181522
let contributors = this.useCaching ? this._contributorsCache.get(repoPath) : undefined;
15191523
if (contributors == null) {
15201524
try {
1521-
const data = await Git.shortlog(repoPath);
1522-
const shortlog = GitShortLogParser.parse(data, repoPath);
1523-
if (shortlog != null) {
1524-
// Mark the current user
1525-
const currentUser = await this.getCurrentUser(repoPath);
1526-
if (currentUser != null) {
1527-
const index = shortlog.contributors.findIndex(
1528-
c => currentUser.email === c.email && currentUser.name === c.name,
1529-
);
1530-
if (index !== -1) {
1531-
const c = shortlog.contributors[index];
1532-
shortlog.contributors.splice(
1533-
index,
1534-
1,
1535-
new GitContributor(c.repoPath, c.name, c.email, c.count, true),
1536-
);
1537-
}
1538-
}
1525+
const currentUser = await this.getCurrentUser(repoPath);
15391526

1540-
contributors = shortlog.contributors;
1541-
} else {
1542-
contributors = [];
1543-
}
1527+
const data = await Git.log(repoPath, options?.ref, { all: options?.all, format: 'shortlog' });
1528+
const shortlog = GitShortLogParser.parseFromLog(data, repoPath, currentUser);
1529+
contributors = shortlog != null ? shortlog.contributors : [];
15441530

15451531
const repo = await this.getRepository(repoPath);
15461532
if (repo?.supportsChangeEvents) {
@@ -1911,6 +1897,7 @@ export class GitService implements Disposable {
19111897
ref,
19121898
...options
19131899
}: {
1900+
all?: boolean;
19141901
authors?: string[];
19151902
limit?: number;
19161903
merges?: boolean;
@@ -1924,13 +1911,11 @@ export class GitService implements Disposable {
19241911

19251912
try {
19261913
const data = await Git.log(repoPath, ref, {
1927-
authors: options.authors,
1914+
...options,
19281915
limit: limit,
19291916
merges: options.merges == null ? true : options.merges,
19301917
ordering: options.ordering ?? Container.config.advanced.commitOrdering,
1931-
reverse: options.reverse,
19321918
similarityThreshold: Container.config.advanced.similarityThreshold,
1933-
since: options.since,
19341919
});
19351920
const log = GitLogParser.parse(
19361921
data,

0 commit comments

Comments
 (0)