From 2e2462dd466e1f23b0d9ef511147d0dae7502ee6 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 2 Mar 2017 12:49:20 -0500 Subject: [PATCH] Fixes #39 - adds date options for status bar blame Adds data formatting option to blame annotations Preps v2.8.2 --- CHANGELOG.md | 6 ++++++ README.md | 5 ++++- package.json | 24 ++++++++++++++++++++++-- src/blameActiveLineController.ts | 19 ++++++++++++++++++- src/blameAnnotationFormatter.ts | 10 +++++----- src/blameAnnotationProvider.ts | 2 +- src/configuration.ts | 3 +++ 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7ef68d..b7dfa8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Release Notes +### 2.8.2 +- Adds `gitlens.blame.annotation.dateFormat` to specify how absolute commit dates will be shown in the blame annotations +- Adds `gitlens.statusBar.date` to specify whether and how the commit date will be shown in the blame status bar +- Adds `gitlens.statusBar.dateFormat` to specify how absolute commit dates will be shown in the blame status bar +- Fixes [#39](https://github.com/eamodio/vscode-gitlens/issues/39) - Add date format options for status bar blame + ### 2.8.1 - Fixes issue where `Compare with *` commands fail to open when there is no active editor diff --git a/README.md b/README.md index 9217cdd..07732c9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,8 @@ Provides Git CodeLens information (most recent commit, # of authors), on-demand |`gitlens.blame.annotation.highlight`|Specifies whether and how to highlight blame annotations. `none` - no highlight. `gutter` - adds a gutter icon. `line` - adds a full-line highlight. `both` - adds both `gutter` and `line` highlights |`gitlens.blame.annotation.sha`|Specifies whether the commit sha will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles |`gitlens.blame.annotation.author`|Specifies whether the committer will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles -|`gitlens.blame.annotation.date`|Specifies whether and how the commit date will be shown in the blame annotations. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date in `MMMM Do, YYYY h:MMa` format. Applies only to the `expanded` & `trailing` annotation styles +|`gitlens.blame.annotation.date`|Specifies whether and how the commit date will be shown in the blame annotations. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date format specified by `gitlens.blame.annotation.dateFormat`. Applies only to the `expanded` & `trailing` annotation styles +|`gitlens.blame.annotation.dateFormat`|Specifies the date format of how absolute dates will be shown in the blame annotations. See https://momentjs.com/docs/#/displaying/format/ for valid formats |`gitlens.blame.annotation.message`|Specifies whether the commit message will be shown in the blame annotations. Applies only to the `expanded` & `trailing` annotation styles |`gitlens.blame.annotation.activeLine`|Specifies whether and how to show blame annotations on the active line. `off` - no annotation. `inline` - adds a trailing annotation to the active line. `hover` - adds hover annotation to the active line. `both` - adds both `inline` and `hover` annotations |`gitlens.codeLens.visibility`|Specifies when CodeLens will be triggered in the active document. `auto` - automatically. `ondemand` - only when requested. `off` - disables all active document CodeLens @@ -50,6 +51,8 @@ Provides Git CodeLens information (most recent commit, # of authors), on-demand |`gitlens.menus.diff.enabled`|Specifies whether diff commands will be added to the context menus |`gitlens.statusBar.enabled`|Specifies whether blame information is shown in the status bar |`gitlens.statusBar.command`|"Specifies the command executed when the blame status bar item is clicked. `gitlens.toggleBlame` - toggles blame annotations. `gitlens.showBlameHistory` - opens the blame history explorer. `gitlens.showFileHistory` - opens the file history explorer. `gitlens.diffWithPrevious` - compares the current checked-in file with the previous commit. `gitlens.showQuickCommitDetails` - shows a commit details quick pick. `gitlens.showQuickFileHistory` - shows a file history quick pick. `gitlens.showQuickFileHistory` - shows a repository history quick pick +|`gitlens.statusBar.date`|Specifies whether and how the commit date will be shown in the blame status bar. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date format specified by `gitlens.statusBar.dateFormat` +|`gitlens.statusBar.dateFormat`|Specifies the date format of how absolute dates will be shown in the blame status bar. See https://momentjs.com/docs/#/displaying/format/ for valid formats ## Known Issues diff --git a/package.json b/package.json index cfcb9b8..8cac4f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gitlens", - "version": "2.8.1", + "version": "2.8.2", "author": { "name": "Eric Amodio", "email": "eamodio@gmail.com" @@ -81,7 +81,12 @@ "relative", "absolute" ], - "description": "Specifies whether and how the commit date will be shown in the blame annotations. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date in `MMMM Do, YYYY h:MMa` format. Applies only to the `expanded` & `trailing` annotation styles" + "description": "Specifies whether and how the commit date will be shown in the blame annotations. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date format specified by `gitlens.blame.annotation.dateFormat`. Applies only to the `expanded` & `trailing` annotation styles" + }, + "gitlens.blame.annotation.dateFormat": { + "type": "string", + "default": "", + "description": "Specifies the date format of how absolute dates will be shown in the blame annotations. See https://momentjs.com/docs/#/displaying/format/ for valid formats" }, "gitlens.blame.annotation.message": { "type": "boolean", @@ -265,6 +270,21 @@ ], "description": "Specifies the command executed when the blame status bar item is clicked. `gitlens.toggleBlame` - toggles blame annotations. `gitlens.showBlameHistory` - opens the blame history explorer. `gitlens.showFileHistory` - opens the file history explorer. `gitlens.diffWithPrevious` - compares the current checked-in file with the previous commit. `gitlens.showQuickCommitDetails` - shows a commit details quick pick. `gitlens.showQuickFileHistory` - shows a file history quick pick. `gitlens.showQuickFileHistory` - shows a repository history quick pick" }, + "gitlens.statusBar.date": { + "type": "string", + "default": "relative", + "enum": [ + "off", + "relative", + "absolute" + ], + "description": "Specifies whether and how the commit date will be shown in the blame status bar. `off` - no date. `relative` - relative date (e.g. 1 day ago). `absolute` - date format specified by `gitlens.statusBar.dateFormat`" + }, + "gitlens.statusBar.dateFormat": { + "type": "string", + "default": "", + "description": "Specifies the date format of how absolute dates will be shown in the blame status bar. See https://momentjs.com/docs/#/displaying/format/ for valid formats" + }, "gitlens.advanced.caching.enabled": { "type": "boolean", "default": true, diff --git a/src/blameActiveLineController.ts b/src/blameActiveLineController.ts index d642984..de794c1 100644 --- a/src/blameActiveLineController.ts +++ b/src/blameActiveLineController.ts @@ -208,7 +208,24 @@ export default class BlameActiveLineController extends Disposable { async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) { if (this._config.statusBar.enabled) { - this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`; + switch (this._config.statusBar.date) { + case 'off': + this._statusBarItem.text = `$(git-commit) ${commit.author}`; + break; + case 'absolute': + const dateFormat = this._config.statusBar.dateFormat || 'MMMM Do, YYYY h:MMa'; + let date: string; + try { + date = moment(commit.date).format(dateFormat); + } catch (ex) { + date = moment(commit.date).format('MMMM Do, YYYY h:MMa'); + } + this._statusBarItem.text = `$(git-commit) ${commit.author}, ${date}`; + break; + default: + this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`; + break; + } switch (this._config.statusBar.command) { case StatusBarCommand.BlameAnnotate: diff --git a/src/blameAnnotationFormatter.ts b/src/blameAnnotationFormatter.ts index 5f24fda..95311ff 100644 --- a/src/blameAnnotationFormatter.ts +++ b/src/blameAnnotationFormatter.ts @@ -38,7 +38,7 @@ export default class BlameAnnotationFormatter { let message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength); if (format === BlameAnnotationFormat.Unconstrained) { - const authorAndDate = this.getAuthorAndDate(config, commit, 'MMMM Do, YYYY h:MMa'); + const authorAndDate = this.getAuthorAndDate(config, commit, config.annotation.dateFormat || 'MMMM Do, YYYY h:MMa'); if (config.annotation.sha) { message = `${sha}${(authorAndDate ? `${cssPadding}${cssSeparator}${cssPadding}${authorAndDate}` : '')}${(message ? `${cssPadding}${cssSeparator}${cssPadding}${message}` : '')}`; } @@ -50,7 +50,7 @@ export default class BlameAnnotationFormatter { } const author = this.getAuthor(config, commit, defaultAuthorLength); - const date = this.getDate(config, commit, 'MM/DD/YYYY', true); + const date = this.getDate(config, commit, config.annotation.dateFormat || 'MM/DD/YYYY', true); if (config.annotation.sha) { message = `${sha}${(author ? `${cssPadding}${cssSeparator}${cssPadding}${author}` : '')}${(date ? `${cssPadding}${cssSeparator}${cssPadding}${date}` : '')}${(message ? `${cssPadding}${cssSeparator}${cssPadding}${message}` : '')}`; } @@ -70,10 +70,10 @@ export default class BlameAnnotationFormatter { return `\`${'0'.repeat(8)}\`   __Uncommitted changes__`; } - return `\`${commit.sha}\`   __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format('MMMM Do, YYYY h:MMa')})_ \n\n${message}`; + return `\`${commit.sha}\`   __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format(config.annotation.dateFormat || 'MMMM Do, YYYY h:MMa')})_ \n\n${message}`; } - static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format?: string, force: boolean = false) { + static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format: string, force: boolean = false) { if (!force && !config.annotation.author && (!config.annotation.date || config.annotation.date === 'off')) return ''; if (!config.annotation.author) { @@ -101,7 +101,7 @@ export default class BlameAnnotationFormatter { return author + cssPadding.repeat(truncateTo - author.length); } - static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) { + static getDate(config: IBlameConfig, commit: GitCommit, format: string, truncate: boolean = false, force: boolean = false) { if (!force && (!config.annotation.date || config.annotation.date === 'off')) return ''; const date = config.annotation.date === 'relative' diff --git a/src/blameAnnotationProvider.ts b/src/blameAnnotationProvider.ts index 5156313..5e7aed5 100644 --- a/src/blameAnnotationProvider.ts +++ b/src/blameAnnotationProvider.ts @@ -157,7 +157,7 @@ export class BlameAnnotationProvider extends Disposable { gutter = `${cssIndent} ${BlameAnnotationFormatter.getAuthor(this._config, commit, defaultAuthorLength, true)}`; break; case 2: - gutter = `${cssIndent} ${BlameAnnotationFormatter.getDate(this._config, commit, 'MM/DD/YYYY', true, true)}`; + gutter = `${cssIndent} ${BlameAnnotationFormatter.getDate(this._config, commit, this._config.annotation.dateFormat || 'MM/DD/YYYY', true, true)}`; break; default: gutter = `${cssIndent}`; diff --git a/src/configuration.ts b/src/configuration.ts index 29062bc..e5dfb56 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -16,6 +16,7 @@ export interface IBlameConfig { sha: boolean; author: boolean; date: 'off' | 'relative' | 'absolute'; + dateFormat: string; message: boolean; activeLine: 'off' | 'inline' | 'hover' | 'both'; characters: { @@ -89,6 +90,8 @@ export const StatusBarCommand = { export interface IStatusBarConfig { enabled: boolean; command: StatusBarCommand; + date: 'off' | 'relative' | 'absolute'; + dateFormat: string; } export interface IAdvancedConfig {