Ver código fonte

Adds option to show committer date

Fixes #537
main
Mathew King 5 anos atrás
committed by Eric Amodio
pai
commit
b8d9d7a364
9 arquivos alterados com 78 adições e 16 exclusões
  1. +1
    -0
      README.md
  2. +14
    -0
      package.json
  3. +2
    -1
      src/codelens/codeLensController.ts
  4. +6
    -0
      src/config.ts
  5. +2
    -1
      src/git/gitService.ts
  6. +6
    -3
      src/git/models/blameCommit.ts
  7. +34
    -11
      src/git/models/commit.ts
  8. +1
    -0
      src/git/models/logCommit.ts
  9. +12
    -0
      src/git/parsers/blameParser.ts

+ 1
- 0
README.md Ver arquivo

@ -652,6 +652,7 @@ GitLens is highly customizable and provides many configuration settings to allow
| `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 | | `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 |
| `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 | | `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 |
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default | | `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
| `gitlens.defaultDateType` | Specifies if dates should use author date or committer date |
| `gitlens.defaultGravatarsStyle` | Specifies the style of the gravatar default (fallback) images<br /><br />`identicon` - a geometric pattern<br />`mm` - 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` - a face with differing features and backgrounds | | `gitlens.defaultGravatarsStyle` | Specifies the style of the gravatar default (fallback) images<br /><br />`identicon` - a geometric pattern<br />`mm` - 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` - a face with differing features and backgrounds |
| `gitlens.insiders` | Specifies whether to enable experimental features | | `gitlens.insiders` | Specifies whether to enable experimental features |
| `gitlens.keymap` | Specifies the keymap to use for GitLens shortcut keys<br /><br />`alternate` - adds an alternate set of shortcut keys that start with `Alt` (&#x2325; on macOS)<br />`chorded` - adds a chorded set of shortcut keys that start with `Ctrl+Shift+G` (<code>&#x2325;&#x2318;G</code> on macOS)<br />`none` - no shortcut keys will be added | | `gitlens.keymap` | Specifies the keymap to use for GitLens shortcut keys<br /><br />`alternate` - adds an alternate set of shortcut keys that start with `Alt` (&#x2325; on macOS)<br />`chorded` - adds a chorded set of shortcut keys that start with `Ctrl+Shift+G` (<code>&#x2325;&#x2318;G</code> on macOS)<br />`none` - no shortcut keys will be added |

+ 14
- 0
package.json Ver arquivo

@ -439,6 +439,20 @@
"markdownDescription": "Specifies how dates will be displayed by default", "markdownDescription": "Specifies how dates will be displayed by default",
"scope": "window" "scope": "window"
}, },
"gitlens.defaultDateType": {
"type": "string",
"default": "author",
"enum": [
"author",
"committer"
],
"enumDescriptions": [
"The date that the commit was originally written",
"The date that the commit was applied to the branch"
],
"markdownDescription": "Specifies if dates should use author date or committer date",
"scope": "window"
},
"gitlens.defaultGravatarsStyle": { "gitlens.defaultGravatarsStyle": {
"type": "string", "type": "string",
"default": "robohash", "default": "robohash",

+ 2
- 1
src/codelens/codeLensController.ts Ver arquivo

@ -32,7 +32,8 @@ export class GitCodeLensController implements Disposable {
if ( if (
configuration.changed(e, section, null) || configuration.changed(e, section, null) ||
configuration.changed(e, configuration.name('defaultDateStyle').value) || configuration.changed(e, configuration.name('defaultDateStyle').value) ||
configuration.changed(e, configuration.name('defaultDateFormat').value)
configuration.changed(e, configuration.name('defaultDateFormat').value) ||
configuration.changed(e, configuration.name('defaultDateType').value)
) { ) {
if (!configuration.initializing(e)) { if (!configuration.initializing(e)) {
Logger.log('CodeLens config changed; resetting CodeLens provider'); Logger.log('CodeLens config changed; resetting CodeLens provider');

+ 6
- 0
src/config.ts Ver arquivo

@ -30,6 +30,7 @@ export interface Config {
defaultDateFormat: string | null; defaultDateFormat: string | null;
defaultDateShortFormat: string | null; defaultDateShortFormat: string | null;
defaultDateStyle: DateStyle; defaultDateStyle: DateStyle;
defaultDateType: DateType;
defaultGravatarsStyle: GravatarDefaultStyle; defaultGravatarsStyle: GravatarDefaultStyle;
heatmap: { heatmap: {
ageThreshold: number; ageThreshold: number;
@ -127,6 +128,11 @@ export enum CustomRemoteType {
GitLab = 'GitLab' GitLab = 'GitLab'
} }
export enum DateType {
Author = 'author',
Committer = 'committer'
}
export enum DateStyle { export enum DateStyle {
Absolute = 'absolute', Absolute = 'absolute',
Relative = 'relative' Relative = 'relative'

+ 2
- 1
src/git/gitService.ts Ver arquivo

@ -168,7 +168,8 @@ export class GitService implements Disposable {
private onConfigurationChanged(e: ConfigurationChangeEvent) { private onConfigurationChanged(e: ConfigurationChangeEvent) {
if ( if (
configuration.changed(e, configuration.name('defaultDateStyle').value) || configuration.changed(e, configuration.name('defaultDateStyle').value) ||
configuration.changed(e, configuration.name('defaultDateFormat').value)
configuration.changed(e, configuration.name('defaultDateFormat').value) ||
configuration.changed(e, configuration.name('defaultDateType').value)
) { ) {
CommitFormatting.reset(); CommitFormatting.reset();
} }

+ 6
- 3
src/git/models/blameCommit.ts Ver arquivo

@ -7,7 +7,8 @@ export class GitBlameCommit extends GitCommit {
sha: string, sha: string,
author: string, author: string,
email: string | undefined, email: string | undefined,
date: Date,
authorDate: Date,
committerDate: Date,
message: string, message: string,
fileName: string, fileName: string,
originalFileName: string | undefined, originalFileName: string | undefined,
@ -21,7 +22,8 @@ export class GitBlameCommit extends GitCommit {
sha, sha,
author, author,
email, email,
date,
authorDate,
committerDate,
message, message,
fileName, fileName,
originalFileName, originalFileName,
@ -49,7 +51,8 @@ export class GitBlameCommit extends GitCommit {
changes.sha || this.sha, changes.sha || this.sha,
this.author, this.author,
this.email, this.email,
this.date,
this.authorDate,
this.committerDate,
this.message, this.message,
changes.fileName || this.fileName, changes.fileName || this.fileName,
this.getChangedValue(changes.originalFileName, this.originalFileName), this.getChangedValue(changes.originalFileName, this.originalFileName),

+ 34
- 11
src/git/models/commit.ts Ver arquivo

@ -7,6 +7,7 @@ import { CommitFormatter } from '../formatters/formatters';
import { Git } from '../git'; import { Git } from '../git';
import { GitUri } from '../gitUri'; import { GitUri } from '../gitUri';
import { getGravatarUri } from '../../gravatar'; import { getGravatarUri } from '../../gravatar';
import { DateType } from '../../config';
export interface GitAuthor { export interface GitAuthor {
name: string; name: string;
@ -32,10 +33,12 @@ export enum GitCommitType {
export const CommitFormatting = { export const CommitFormatting = {
dateFormat: undefined! as string | null, dateFormat: undefined! as string | null,
dateStyle: undefined! as DateStyle, dateStyle: undefined! as DateStyle,
dateType: undefined! as DateType,
reset: () => { reset: () => {
CommitFormatting.dateStyle = configuration.get<DateStyle>(configuration.name('defaultDateStyle').value); CommitFormatting.dateStyle = configuration.get<DateStyle>(configuration.name('defaultDateStyle').value);
CommitFormatting.dateFormat = configuration.get<string | null>(configuration.name('defaultDateFormat').value); CommitFormatting.dateFormat = configuration.get<string | null>(configuration.name('defaultDateFormat').value);
CommitFormatting.dateType = configuration.get<DateType>(configuration.name('defaultDateType').value);
} }
}; };
@ -52,13 +55,17 @@ export abstract class GitCommit {
private _isUncommitted: boolean | undefined; private _isUncommitted: boolean | undefined;
private _shortSha: string | undefined; private _shortSha: string | undefined;
private _authorDateFormatter: Dates.DateFormatter | undefined;
private _committerDateFormatter: Dates.DateFormatter | undefined;
constructor( constructor(
type: GitCommitType, type: GitCommitType,
public readonly repoPath: string, public readonly repoPath: string,
public readonly sha: string, public readonly sha: string,
public readonly author: string, public readonly author: string,
public readonly email: string | undefined, public readonly email: string | undefined,
public readonly date: Date,
public readonly authorDate: Date,
public readonly committerDate: Date,
public readonly message: string, public readonly message: string,
fileName: string, fileName: string,
originalFileName?: string, originalFileName?: string,
@ -77,6 +84,30 @@ export abstract class GitCommit {
return this.isFile ? this._fileName : ''; return this.isFile ? this._fileName : '';
} }
get date(): Date {
return CommitFormatting.dateType === DateType.Committer
? this.committerDate : this.authorDate;
}
get authorDateFormatter(): Dates.DateFormatter {
if (this._authorDateFormatter === undefined) {
this._authorDateFormatter = Dates.toFormatter(this.authorDate);
}
return this._authorDateFormatter;
}
get committerDateFormatter(): Dates.DateFormatter {
if (this._committerDateFormatter === undefined) {
this._committerDateFormatter = Dates.toFormatter(this.committerDate);
}
return this._committerDateFormatter;
}
get dateFormatter(): Dates.DateFormatter {
return CommitFormatting.dateType === DateType.Committer
? this.committerDateFormatter : this.authorDateFormatter;
}
get formattedDate(): string { get formattedDate(): string {
return CommitFormatting.dateStyle === DateStyle.Absolute return CommitFormatting.dateStyle === DateStyle.Absolute
? this.formatDate(CommitFormatting.dateFormat) ? this.formatDate(CommitFormatting.dateFormat)
@ -149,24 +180,16 @@ export abstract class GitCommit {
return this.workingFileName ? GitUri.resolveToUri(this.workingFileName, this.repoPath) : this.uri; return this.workingFileName ? GitUri.resolveToUri(this.workingFileName, this.repoPath) : this.uri;
} }
private _dateFormatter?: Dates.DateFormatter;
formatDate(format?: string | null) { formatDate(format?: string | null) {
if (format == null) { if (format == null) {
format = 'MMMM Do, YYYY h:mma'; format = 'MMMM Do, YYYY h:mma';
} }
if (this._dateFormatter === undefined) {
this._dateFormatter = Dates.toFormatter(this.date);
}
return this._dateFormatter.format(format);
return this.dateFormatter.format(format);
} }
fromNow() { fromNow() {
if (this._dateFormatter === undefined) {
this._dateFormatter = Dates.toFormatter(this.date);
}
return this._dateFormatter.fromNow();
return this.dateFormatter.fromNow();
} }
getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string { getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string {

+ 1
- 0
src/git/models/logCommit.ts Ver arquivo

@ -35,6 +35,7 @@ export class GitLogCommit extends GitCommit {
author, author,
email, email,
date, date,
committedDate,
message, message,
fileName, fileName,
originalFileName, originalFileName,

+ 12
- 0
src/git/parsers/blameParser.ts Ver arquivo

@ -18,6 +18,9 @@ interface BlameEntry {
authorTimeZone?: string; authorTimeZone?: string;
authorEmail?: string; authorEmail?: string;
committerDate?: string;
committerTimeZone?: string;
previousSha?: string; previousSha?: string;
previousFileName?: string; previousFileName?: string;
@ -107,6 +110,14 @@ export class GitBlameParser {
entry.authorTimeZone = lineParts[1]; entry.authorTimeZone = lineParts[1];
break; break;
case 'committer-time':
entry.committerDate = lineParts[1];
break;
case 'committer-tz':
entry.committerTimeZone = lineParts[1];
break;
case 'summary': case 'summary':
entry.summary = lineParts entry.summary = lineParts
.slice(1) .slice(1)
@ -207,6 +218,7 @@ export class GitBlameParser {
entry.author, entry.author,
entry.authorEmail, entry.authorEmail,
new Date((entry.authorDate as any) * 1000), new Date((entry.authorDate as any) * 1000),
new Date((entry.committerDate as any) * 1000),
entry.summary!, entry.summary!,
relativeFileName, relativeFileName,
entry.previousFileName !== undefined && entry.previousFileName !== entry.fileName entry.previousFileName !== undefined && entry.previousFileName !== entry.fileName

Carregando…
Cancelar
Salvar