Skip to content

Commit 89a79ee

Browse files
committed
Adds gravatarsDefault setting for gravatar fallback
1 parent 8344c33 commit 89a79ee

File tree

9 files changed

+85
-26
lines changed

9 files changed

+85
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111
- Only visible if there is more than 1 repository within the workspace
1212
- Adds [Gravatar](https://en.gravatar.com/) support to the `GitLens` view
1313
- Adds `gitlens.gitExplorer.gravatars` setting to specify whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view
14+
- Adds `gitlens.gitExplorer.gravatarsDefault` setting to specify the style of the gravatar default (fallback) images in the `GitLens` view<br />`identicon` - a geometric pattern<br />`mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)<br />`monsterid` - a monster with different colors, faces, etc<br />`retro` - 8-bit arcade-style pixelated faces<br />`robohash` - a robot with different colors, faces, etc<br />`wavatar` - faces with differing features and backgrounds
15+
- Adds `gitlens.resultsExplorer.gravatars` setting to specify whether or not to show gravatar images instead of commit (or status) icons in the `GitLens Results` view
16+
- Adds `gitlens.resultsExplorer.gravatarsDefault` setting to specify the style of the gravatar default (fallback) images in the `GitLens Results` view<br />`identicon` - a geometric pattern<br />`mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)<br />`monsterid` - a monster with different colors, faces, etc<br />`retro` - 8-bit arcade-style pixelated faces<br />`robohash` - a robot with different colors, faces, etc<br />`wavatar` - faces with differing features and backgrounds
1417
- Adds `Select for Compare` command (`gitlens.explorers.selectForCompare`) to branch and revision (commit) nodes in the `GitLens` view to mark the base revision of a comparision
1518
- Adds `Compare with Selected` command (`gitlens.explorers.compareWithSelected`) to branch and revision (commit) nodes in the `GitLens` view once another branch or revision (commit) node within the same repository has been selected to compare the current selection with the previously selected revision (branch or commit)
1619
- Adds `Apply Changes` option to the commit/stash file quick pick menu -- closes [#232](https://github.com/eamodio/vscode-gitlens/issues/232)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ GitLens is highly customizable and provides many configuration settings to allow
441441
|`gitlens.gitExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens` view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
442442
|`gitlens.gitExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens` view<br />Available tokens<br /> ${directory} - directory name<br /> ${file} - file name<br /> ${filePath} - formatted file name and path<br /> ${path} - full file path
443443
|`gitlens.gitExplorer.gravatars`|Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view
444+
|`gitlens.gitExplorer.gravatarsDefault`|Specifies the style of the gravatar default (fallback) images in the `GitLens` view<br />`identicon` - a geometric pattern<br />`mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)<br />`monsterid` - a monster with different colors, faces, etc<br />`retro` - 8-bit arcade-style pixelated faces<br />`robohash` - a robot with different colors, faces, etc<br />`wavatar` - faces with differing features and backgrounds
444445
|`gitlens.gitExplorer.includeWorkingTree`|Specifies whether or not to include working tree files inside the `Repository Status` node of the `GitLens` view
445446
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` view"
446447
|`gitlens.gitExplorer.stashFormat`|Specifies the format of stashed changes in the `GitLens` view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
@@ -457,6 +458,7 @@ GitLens is highly customizable and provides many configuration settings to allow
457458
|`gitlens.resultsExplorer.commitFormat`|Specifies the format of committed changes in the `GitLens Results` view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
458459
|`gitlens.resultsExplorer.commitFileFormat`|Specifies the format of a committed file in the `GitLens Results` view<br />Available tokens<br /> ${directory} - directory name<br /> ${file} - file name<br /> ${filePath} - formatted file name and path<br /> ${path} - full file path
459460
|`gitlens.resultsExplorer.gravatars`|Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens Results` view
461+
|`gitlens.resultsExplorer.gravatarsDefault`|Specifies the style of the gravatar default (fallback) images in the `GitLens Results` view<br />`identicon` - a geometric pattern<br />`mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)<br />`monsterid` - a monster with different colors, faces, etc<br />`retro` - 8-bit arcade-style pixelated faces<br />`robohash` - a robot with different colors, faces, etc<br />`wavatar` - faces with differing features and backgrounds
460462
|`gitlens.resultsExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens Results` view"
461463
|`gitlens.resultsExplorer.stashFormat`|Specifies the format of stashed changes in the `GitLens Results` view<br />Available tokens<br /> ${id} - commit id<br /> ${author} - commit author<br /> ${message} - commit message<br /> ${ago} - relative commit date (e.g. 1 day ago)<br /> ${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)<br /> ${authorAgo} - commit author, relative commit date<br />See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting
462464
|`gitlens.resultsExplorer.stashFileFormat`|Specifies the format of a stashed file in the `GitLens Results` view<br />Available tokens<br /> ${directory} - directory name<br /> ${file} - file name<br /> ${filePath} - formatted file name and path<br /> ${path} - full file path

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,20 @@
528528
"description": "Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view",
529529
"scope": "window"
530530
},
531+
"gitlens.gitExplorer.gravatarsDefault": {
532+
"type": "string",
533+
"default": "robohash",
534+
"enum": [
535+
"identicon",
536+
"mm",
537+
"monsterid",
538+
"retro",
539+
"robohash",
540+
"wavatar"
541+
],
542+
"description": "Specifies the style of the gravatar default (fallback) images in the `GitLens` view\n `identicon` - a geometric pattern\n `mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)\n `monsterid` - a monster with different colors, faces, etc\n `retro` - 8-bit arcade-style pixelated faces\n `robohash` - a robot with different colors, faces, etc\n `wavatar` - faces with differing features and backgrounds",
543+
"scope": "window"
544+
},
531545
"gitlens.gitExplorer.includeWorkingTree": {
532546
"type": "boolean",
533547
"default": true,
@@ -703,6 +717,20 @@
703717
"description": "Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens Results` view",
704718
"scope": "window"
705719
},
720+
"gitlens.resultsExplorer.gravatarsDefault": {
721+
"type": "string",
722+
"default": "robohash",
723+
"enum": [
724+
"identicon",
725+
"mm",
726+
"monsterid",
727+
"retro",
728+
"robohash",
729+
"wavatar"
730+
],
731+
"description": "Specifies the style of the gravatar default (fallback) images in the `GitLens Results` view\n `identicon` - a geometric pattern\n `mm` - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)\n `monsterid` - a monster with different colors, faces, etc\n `retro` - 8-bit arcade-style pixelated faces\n `robohash` - a robot with different colors, faces, etc\n `wavatar` - faces with differing features and backgrounds",
732+
"scope": "window"
733+
},
706734
"gitlens.resultsExplorer.showTrackingBranch": {
707735
"type": "boolean",
708736
"default": true,

src/configuration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ export enum ExplorerFilesLayout {
4444
Tree = 'tree'
4545
}
4646

47+
export enum GravatarDefault {
48+
Faces = 'wavatar',
49+
Geometric = 'identicon',
50+
Monster = 'monsterid',
51+
MysteryMan = 'mm',
52+
Retro = 'retro',
53+
Robot = 'robohash'
54+
}
55+
4756
export enum KeyMap {
4857
Standard = 'standard',
4958
Chorded = 'chorded',
@@ -147,6 +156,7 @@ export interface IExplorerConfig {
147156
commitFileFormat: string;
148157
// dateFormat: string | null;
149158
gravatars: boolean;
159+
gravatarsDefault: GravatarDefault;
150160
showTrackingBranch: boolean;
151161
stashFormat: string;
152162
stashFileFormat: string;
@@ -395,6 +405,7 @@ const emptyConfig: IConfig = {
395405
commitFileFormat: '',
396406
// dateFormat: string | null;
397407
gravatars: false,
408+
gravatarsDefault: 'robohash' as GravatarDefault,
398409
includeWorkingTree: false,
399410
showTrackingBranch: false,
400411
stashFormat: '',
@@ -414,6 +425,7 @@ const emptyConfig: IConfig = {
414425
commitFileFormat: '',
415426
// dateFormat: string | null;
416427
gravatars: false,
428+
gravatarsDefault: 'robohash' as GravatarDefault,
417429
showTrackingBranch: false,
418430
stashFormat: '',
419431
stashFileFormat: '',

src/git/models/logCommit.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
import { Strings } from '../../system';
33
import { Uri } from 'vscode';
44
import { GitCommit, GitCommitType } from './commit';
5+
import { GravatarDefault } from '../../configuration';
56
import { Git } from '../git';
67
import { GitStatusFileStatus, IGitStatusFile } from './status';
78
import * as path from 'path';
89

910
const gravatarCache: Map<string, Uri> = new Map();
1011

12+
export function clearGravatarCache() {
13+
gravatarCache.clear();
14+
}
15+
1116
export class GitLogCommit extends GitCommit {
1217

1318
nextSha?: string;
@@ -43,27 +48,6 @@ export class GitLogCommit extends GitCommit {
4348
);
4449
}
4550

46-
get gravatarUri(): Uri {
47-
const key = this.email
48-
? this.email.trim().toLowerCase()
49-
: '';
50-
51-
let gravatar = gravatarCache.get(key);
52-
if (gravatar !== undefined) return gravatar;
53-
54-
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=retro`);
55-
56-
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
57-
const originalToStringFn = gravatar.toString;
58-
gravatar.toString = function(skipEncoding?: boolean | undefined) {
59-
return originalToStringFn.call(gravatar, true);
60-
};
61-
62-
gravatarCache.set(key, gravatar);
63-
64-
return gravatar;
65-
}
66-
6751
get isMerge() {
6852
return this.parentShas && this.parentShas.length > 1;
6953
}
@@ -107,6 +91,27 @@ export class GitLogCommit extends GitCommit {
10791
return `+${added} ~${changed} -${deleted}`;
10892
}
10993

94+
getGravatarUri(fallback: GravatarDefault): Uri {
95+
const key = this.email
96+
? `${ this.email.trim().toLowerCase() }`
97+
: '';
98+
99+
let gravatar = gravatarCache.get(key);
100+
if (gravatar !== undefined) return gravatar;
101+
102+
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=${fallback}`);
103+
104+
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
105+
const originalToStringFn = gravatar.toString;
106+
gravatar.toString = function(skipEncoding?: boolean | undefined) {
107+
return originalToStringFn.call(gravatar, true);
108+
};
109+
110+
gravatarCache.set(key, gravatar);
111+
112+
return gravatar;
113+
}
114+
110115
toFileCommit(fileName: string): GitLogCommit | undefined;
111116
toFileCommit(status: IGitStatusFile): GitLogCommit;
112117
toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined {

src/views/commitFileNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
33
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
4+
import { GravatarDefault } from '../configuration';
45
import { Explorer, ExplorerNode, ResourceType } from './explorerNode';
56
import { CommitFormatter, getGitStatusIcon, GitBranch, GitLogCommit, GitUri, ICommitFormatOptions, IGitStatusFile, IStatusFormatOptions, StatusFileFormatter } from '../gitService';
67
import * as path from 'path';
@@ -68,7 +69,7 @@ export class CommitFileNode extends ExplorerNode {
6869
};
6970
}
7071
else if ((this.displayAs & CommitFileNodeDisplayAs.Gravatar) === CommitFileNodeDisplayAs.Gravatar) {
71-
item.iconPath = this.commit.gravatarUri;
72+
item.iconPath = this.commit.getGravatarUri(this.explorer.config.gravatarsDefault || GravatarDefault.Robot);
7273
}
7374

7475
item.command = this.getCommand();

src/views/commitNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Arrays, Iterables } from '../system';
33
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
44
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
55
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
6-
import { ExplorerFilesLayout } from '../configuration';
6+
import { ExplorerFilesLayout, GravatarDefault } from '../configuration';
77
import { FolderNode, IFileExplorerNode } from './folderNode';
88
import { Explorer, ExplorerNode, ExplorerRefNode, ResourceType } from './explorerNode';
99
import { CommitFormatter, GitBranch, GitLogCommit, GitService, ICommitFormatOptions } from '../gitService';
@@ -60,7 +60,7 @@ export class CommitNode extends ExplorerRefNode {
6060
: ResourceType.Commit;
6161

6262
if (this.explorer.config.gravatars) {
63-
item.iconPath = this.commit.gravatarUri;
63+
item.iconPath = this.commit.getGravatarUri(this.explorer.config.gravatarsDefault || GravatarDefault.Robot);
6464
} else {
6565
item.iconPath = {
6666
dark: this.explorer.context.asAbsolutePath('images/dark/icon-commit.svg'),

src/views/gitExplorer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { configuration, ExplorerFilesLayout, IGitExplorerConfig } from '../confi
66
import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants';
77
import { ExplorerCommands, RefreshNodeCommandArgs } from './explorerCommands';
88
import { ExplorerNode, HistoryNode, MessageNode, RefreshReason, RepositoriesNode, RepositoryNode } from './explorerNodes';
9-
import { GitChangeEvent, GitChangeReason, GitContextTracker, GitService, GitUri } from '../gitService';
9+
import { clearGravatarCache, GitChangeEvent, GitChangeReason, GitContextTracker, GitService, GitUri } from '../gitService';
1010
import { Logger } from '../logger';
1111

1212
export * from './explorerNodes';
@@ -80,6 +80,10 @@ export class GitExplorer implements TreeDataProvider<ExplorerNode> {
8080

8181
const cfg = configuration.get<IGitExplorerConfig>(section.value);
8282

83+
if (!initializing && (configuration.changed(e, section('gravatars').value) || configuration.changed(e, section('gravatarsDefault').value))) {
84+
clearGravatarCache();
85+
}
86+
8387
if (initializing || configuration.changed(e, section('autoRefresh').value)) {
8488
this.setAutoRefresh(cfg.autoRefresh);
8589
}

src/views/resultsExplorer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { configuration, ExplorerFilesLayout, IExplorerConfig } from '../configur
55
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
66
import { ExplorerCommands, RefreshNodeCommandArgs } from './explorerCommands';
77
import { CommitsResultsNode, ComparisionResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes';
8-
import { GitLog, GitService } from '../gitService';
8+
import { clearGravatarCache, GitLog, GitService } from '../gitService';
99
import { Logger } from '../logger';
1010

1111
export * from './explorerNodes';
@@ -58,6 +58,10 @@ export class ResultsExplorer implements TreeDataProvider<ExplorerNode> {
5858
const section = configuration.name('resultsExplorer');
5959
if (!initializing && !configuration.changed(e, section.value)) return;
6060

61+
if (!initializing && (configuration.changed(e, section('gravatars').value) || configuration.changed(e, section('gravatarsDefault').value))) {
62+
clearGravatarCache();
63+
}
64+
6165
const cfg = configuration.get<IExplorerConfig>(section.value);
6266

6367
if (!initializing && this._roots.length !== 0) {

0 commit comments

Comments
 (0)