Browse Source

Adds gravatarsDefault setting for gravatar fallback

main
Eric Amodio 7 years ago
parent
commit
89a79eebc1
9 changed files with 85 additions and 26 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +2
    -0
      README.md
  3. +28
    -0
      package.json
  4. +12
    -0
      src/configuration.ts
  5. +26
    -21
      src/git/models/logCommit.ts
  6. +2
    -1
      src/views/commitFileNode.ts
  7. +2
    -2
      src/views/commitNode.ts
  8. +5
    -1
      src/views/gitExplorer.ts
  9. +5
    -1
      src/views/resultsExplorer.ts

+ 3
- 0
CHANGELOG.md View File

@ -11,6 +11,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Only visible if there is more than 1 repository within the workspace
- Adds [Gravatar](https://en.gravatar.com/) support to the `GitLens` view
- Adds `gitlens.gitExplorer.gravatars` setting to specify whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view
- 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
- 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
- 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
- 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
- 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)
- Adds `Apply Changes` option to the commit/stash file quick pick menu -- closes [#232](https://github.com/eamodio/vscode-gitlens/issues/232)

+ 2
- 0
README.md View File

@ -441,6 +441,7 @@ GitLens is highly customizable and provides many configuration settings to allow
|`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
|`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
|`gitlens.gitExplorer.gravatars`|Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view
|`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
|`gitlens.gitExplorer.includeWorkingTree`|Specifies whether or not to include working tree files inside the `Repository Status` node of the `GitLens` view
|`gitlens.gitExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens` view"
|`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
|`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
|`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
|`gitlens.resultsExplorer.gravatars`|Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens Results` view
|`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
|`gitlens.resultsExplorer.showTrackingBranch`|Specifies whether or not to show the tracking branch when displaying local branches in the `GitLens Results` view"
|`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
|`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

+ 28
- 0
package.json View File

@ -528,6 +528,20 @@
"description": "Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens` view",
"scope": "window"
},
"gitlens.gitExplorer.gravatarsDefault": {
"type": "string",
"default": "robohash",
"enum": [
"identicon",
"mm",
"monsterid",
"retro",
"robohash",
"wavatar"
],
"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",
"scope": "window"
},
"gitlens.gitExplorer.includeWorkingTree": {
"type": "boolean",
"default": true,
@ -703,6 +717,20 @@
"description": "Specifies whether or not to show gravatar images instead of commit (or status) icons in the `GitLens Results` view",
"scope": "window"
},
"gitlens.resultsExplorer.gravatarsDefault": {
"type": "string",
"default": "robohash",
"enum": [
"identicon",
"mm",
"monsterid",
"retro",
"robohash",
"wavatar"
],
"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",
"scope": "window"
},
"gitlens.resultsExplorer.showTrackingBranch": {
"type": "boolean",
"default": true,

+ 12
- 0
src/configuration.ts View File

@ -44,6 +44,15 @@ export enum ExplorerFilesLayout {
Tree = 'tree'
}
export enum GravatarDefault {
Faces = 'wavatar',
Geometric = 'identicon',
Monster = 'monsterid',
MysteryMan = 'mm',
Retro = 'retro',
Robot = 'robohash'
}
export enum KeyMap {
Standard = 'standard',
Chorded = 'chorded',
@ -147,6 +156,7 @@ export interface IExplorerConfig {
commitFileFormat: string;
// dateFormat: string | null;
gravatars: boolean;
gravatarsDefault: GravatarDefault;
showTrackingBranch: boolean;
stashFormat: string;
stashFileFormat: string;
@ -395,6 +405,7 @@ const emptyConfig: IConfig = {
commitFileFormat: '',
// dateFormat: string | null;
gravatars: false,
gravatarsDefault: 'robohash' as GravatarDefault,
includeWorkingTree: false,
showTrackingBranch: false,
stashFormat: '',
@ -414,6 +425,7 @@ const emptyConfig: IConfig = {
commitFileFormat: '',
// dateFormat: string | null;
gravatars: false,
gravatarsDefault: 'robohash' as GravatarDefault,
showTrackingBranch: false,
stashFormat: '',
stashFileFormat: '',

+ 26
- 21
src/git/models/logCommit.ts View File

@ -2,12 +2,17 @@
import { Strings } from '../../system';
import { Uri } from 'vscode';
import { GitCommit, GitCommitType } from './commit';
import { GravatarDefault } from '../../configuration';
import { Git } from '../git';
import { GitStatusFileStatus, IGitStatusFile } from './status';
import * as path from 'path';
const gravatarCache: Map<string, Uri> = new Map();
export function clearGravatarCache() {
gravatarCache.clear();
}
export class GitLogCommit extends GitCommit {
nextSha?: string;
@ -43,27 +48,6 @@ export class GitLogCommit extends GitCommit {
);
}
get gravatarUri(): Uri {
const key = this.email
? this.email.trim().toLowerCase()
: '';
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=retro`);
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
const originalToStringFn = gravatar.toString;
gravatar.toString = function(skipEncoding?: boolean | undefined) {
return originalToStringFn.call(gravatar, true);
};
gravatarCache.set(key, gravatar);
return gravatar;
}
get isMerge() {
return this.parentShas && this.parentShas.length > 1;
}
@ -107,6 +91,27 @@ export class GitLogCommit extends GitCommit {
return `+${added} ~${changed} -${deleted}`;
}
getGravatarUri(fallback: GravatarDefault): Uri {
const key = this.email
? `${ this.email.trim().toLowerCase() }`
: '';
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email) : '00000000000000000000000000000000'}.jpg?s=22&d=${fallback}`);
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
const originalToStringFn = gravatar.toString;
gravatar.toString = function(skipEncoding?: boolean | undefined) {
return originalToStringFn.call(gravatar, true);
};
gravatarCache.set(key, gravatar);
return gravatar;
}
toFileCommit(fileName: string): GitLogCommit | undefined;
toFileCommit(status: IGitStatusFile): GitLogCommit;
toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined {

+ 2
- 1
src/views/commitFileNode.ts View File

@ -1,6 +1,7 @@
'use strict';
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { GravatarDefault } from '../configuration';
import { Explorer, ExplorerNode, ResourceType } from './explorerNode';
import { CommitFormatter, getGitStatusIcon, GitBranch, GitLogCommit, GitUri, ICommitFormatOptions, IGitStatusFile, IStatusFormatOptions, StatusFileFormatter } from '../gitService';
import * as path from 'path';
@ -68,7 +69,7 @@ export class CommitFileNode extends ExplorerNode {
};
}
else if ((this.displayAs & CommitFileNodeDisplayAs.Gravatar) === CommitFileNodeDisplayAs.Gravatar) {
item.iconPath = this.commit.gravatarUri;
item.iconPath = this.commit.getGravatarUri(this.explorer.config.gravatarsDefault || GravatarDefault.Robot);
}
item.command = this.getCommand();

+ 2
- 2
src/views/commitNode.ts View File

@ -3,7 +3,7 @@ import { Arrays, Iterables } from '../system';
import { Command, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { CommitFileNode, CommitFileNodeDisplayAs } from './commitFileNode';
import { ExplorerFilesLayout } from '../configuration';
import { ExplorerFilesLayout, GravatarDefault } from '../configuration';
import { FolderNode, IFileExplorerNode } from './folderNode';
import { Explorer, ExplorerNode, ExplorerRefNode, ResourceType } from './explorerNode';
import { CommitFormatter, GitBranch, GitLogCommit, GitService, ICommitFormatOptions } from '../gitService';
@ -60,7 +60,7 @@ export class CommitNode extends ExplorerRefNode {
: ResourceType.Commit;
if (this.explorer.config.gravatars) {
item.iconPath = this.commit.gravatarUri;
item.iconPath = this.commit.getGravatarUri(this.explorer.config.gravatarsDefault || GravatarDefault.Robot);
} else {
item.iconPath = {
dark: this.explorer.context.asAbsolutePath('images/dark/icon-commit.svg'),

+ 5
- 1
src/views/gitExplorer.ts View File

@ -6,7 +6,7 @@ import { configuration, ExplorerFilesLayout, IGitExplorerConfig } from '../confi
import { CommandContext, GlyphChars, setCommandContext, WorkspaceState } from '../constants';
import { ExplorerCommands, RefreshNodeCommandArgs } from './explorerCommands';
import { ExplorerNode, HistoryNode, MessageNode, RefreshReason, RepositoriesNode, RepositoryNode } from './explorerNodes';
import { GitChangeEvent, GitChangeReason, GitContextTracker, GitService, GitUri } from '../gitService';
import { clearGravatarCache, GitChangeEvent, GitChangeReason, GitContextTracker, GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
export * from './explorerNodes';
@ -80,6 +80,10 @@ export class GitExplorer implements TreeDataProvider {
const cfg = configuration.get<IGitExplorerConfig>(section.value);
if (!initializing && (configuration.changed(e, section('gravatars').value) || configuration.changed(e, section('gravatarsDefault').value))) {
clearGravatarCache();
}
if (initializing || configuration.changed(e, section('autoRefresh').value)) {
this.setAutoRefresh(cfg.autoRefresh);
}

+ 5
- 1
src/views/resultsExplorer.ts View File

@ -5,7 +5,7 @@ import { configuration, ExplorerFilesLayout, IExplorerConfig } from '../configur
import { CommandContext, setCommandContext, WorkspaceState } from '../constants';
import { ExplorerCommands, RefreshNodeCommandArgs } from './explorerCommands';
import { CommitsResultsNode, ComparisionResultsNode, ExplorerNode, MessageNode, RefreshReason, ResourceType } from './explorerNodes';
import { GitLog, GitService } from '../gitService';
import { clearGravatarCache, GitLog, GitService } from '../gitService';
import { Logger } from '../logger';
export * from './explorerNodes';
@ -58,6 +58,10 @@ export class ResultsExplorer implements TreeDataProvider {
const section = configuration.name('resultsExplorer');
if (!initializing && !configuration.changed(e, section.value)) return;
if (!initializing && (configuration.changed(e, section('gravatars').value) || configuration.changed(e, section('gravatarsDefault').value))) {
clearGravatarCache();
}
const cfg = configuration.get<IExplorerConfig>(section.value);
if (!initializing && this._roots.length !== 0) {

Loading…
Cancel
Save