Skip to content

Commit b8d9d7a

Browse files
MathewKingeamodio
authored andcommitted
Adds option to show committer date
Fixes #537
1 parent c69777e commit b8d9d7a

File tree

9 files changed

+78
-16
lines changed

9 files changed

+78
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ GitLens is highly customizable and provides many configuration settings to allow
652652
| `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 |
653653
| `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 |
654654
| `gitlens.defaultDateStyle` | Specifies how dates will be displayed by default |
655+
| `gitlens.defaultDateType` | Specifies if dates should use author date or committer date |
655656
| `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 |
656657
| `gitlens.insiders` | Specifies whether to enable experimental features |
657658
| `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 |

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,20 @@
439439
"markdownDescription": "Specifies how dates will be displayed by default",
440440
"scope": "window"
441441
},
442+
"gitlens.defaultDateType": {
443+
"type": "string",
444+
"default": "author",
445+
"enum": [
446+
"author",
447+
"committer"
448+
],
449+
"enumDescriptions": [
450+
"The date that the commit was originally written",
451+
"The date that the commit was applied to the branch"
452+
],
453+
"markdownDescription": "Specifies if dates should use author date or committer date",
454+
"scope": "window"
455+
},
442456
"gitlens.defaultGravatarsStyle": {
443457
"type": "string",
444458
"default": "robohash",

src/codelens/codeLensController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ export class GitCodeLensController implements Disposable {
3232
if (
3333
configuration.changed(e, section, null) ||
3434
configuration.changed(e, configuration.name('defaultDateStyle').value) ||
35-
configuration.changed(e, configuration.name('defaultDateFormat').value)
35+
configuration.changed(e, configuration.name('defaultDateFormat').value) ||
36+
configuration.changed(e, configuration.name('defaultDateType').value)
3637
) {
3738
if (!configuration.initializing(e)) {
3839
Logger.log('CodeLens config changed; resetting CodeLens provider');

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface Config {
3030
defaultDateFormat: string | null;
3131
defaultDateShortFormat: string | null;
3232
defaultDateStyle: DateStyle;
33+
defaultDateType: DateType;
3334
defaultGravatarsStyle: GravatarDefaultStyle;
3435
heatmap: {
3536
ageThreshold: number;
@@ -127,6 +128,11 @@ export enum CustomRemoteType {
127128
GitLab = 'GitLab'
128129
}
129130

131+
export enum DateType {
132+
Author = 'author',
133+
Committer = 'committer'
134+
}
135+
130136
export enum DateStyle {
131137
Absolute = 'absolute',
132138
Relative = 'relative'

src/git/gitService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export class GitService implements Disposable {
168168
private onConfigurationChanged(e: ConfigurationChangeEvent) {
169169
if (
170170
configuration.changed(e, configuration.name('defaultDateStyle').value) ||
171-
configuration.changed(e, configuration.name('defaultDateFormat').value)
171+
configuration.changed(e, configuration.name('defaultDateFormat').value) ||
172+
configuration.changed(e, configuration.name('defaultDateType').value)
172173
) {
173174
CommitFormatting.reset();
174175
}

src/git/models/blameCommit.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export class GitBlameCommit extends GitCommit {
77
sha: string,
88
author: string,
99
email: string | undefined,
10-
date: Date,
10+
authorDate: Date,
11+
committerDate: Date,
1112
message: string,
1213
fileName: string,
1314
originalFileName: string | undefined,
@@ -21,7 +22,8 @@ export class GitBlameCommit extends GitCommit {
2122
sha,
2223
author,
2324
email,
24-
date,
25+
authorDate,
26+
committerDate,
2527
message,
2628
fileName,
2729
originalFileName,
@@ -49,7 +51,8 @@ export class GitBlameCommit extends GitCommit {
4951
changes.sha || this.sha,
5052
this.author,
5153
this.email,
52-
this.date,
54+
this.authorDate,
55+
this.committerDate,
5356
this.message,
5457
changes.fileName || this.fileName,
5558
this.getChangedValue(changes.originalFileName, this.originalFileName),

src/git/models/commit.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CommitFormatter } from '../formatters/formatters';
77
import { Git } from '../git';
88
import { GitUri } from '../gitUri';
99
import { getGravatarUri } from '../../gravatar';
10+
import { DateType } from '../../config';
1011

1112
export interface GitAuthor {
1213
name: string;
@@ -32,10 +33,12 @@ export enum GitCommitType {
3233
export const CommitFormatting = {
3334
dateFormat: undefined! as string | null,
3435
dateStyle: undefined! as DateStyle,
36+
dateType: undefined! as DateType,
3537

3638
reset: () => {
3739
CommitFormatting.dateStyle = configuration.get<DateStyle>(configuration.name('defaultDateStyle').value);
3840
CommitFormatting.dateFormat = configuration.get<string | null>(configuration.name('defaultDateFormat').value);
41+
CommitFormatting.dateType = configuration.get<DateType>(configuration.name('defaultDateType').value);
3942
}
4043
};
4144

@@ -52,13 +55,17 @@ export abstract class GitCommit {
5255
private _isUncommitted: boolean | undefined;
5356
private _shortSha: string | undefined;
5457

58+
private _authorDateFormatter: Dates.DateFormatter | undefined;
59+
private _committerDateFormatter: Dates.DateFormatter | undefined;
60+
5561
constructor(
5662
type: GitCommitType,
5763
public readonly repoPath: string,
5864
public readonly sha: string,
5965
public readonly author: string,
6066
public readonly email: string | undefined,
61-
public readonly date: Date,
67+
public readonly authorDate: Date,
68+
public readonly committerDate: Date,
6269
public readonly message: string,
6370
fileName: string,
6471
originalFileName?: string,
@@ -77,6 +84,30 @@ export abstract class GitCommit {
7784
return this.isFile ? this._fileName : '';
7885
}
7986

87+
get date(): Date {
88+
return CommitFormatting.dateType === DateType.Committer
89+
? this.committerDate : this.authorDate;
90+
}
91+
92+
get authorDateFormatter(): Dates.DateFormatter {
93+
if (this._authorDateFormatter === undefined) {
94+
this._authorDateFormatter = Dates.toFormatter(this.authorDate);
95+
}
96+
return this._authorDateFormatter;
97+
}
98+
99+
get committerDateFormatter(): Dates.DateFormatter {
100+
if (this._committerDateFormatter === undefined) {
101+
this._committerDateFormatter = Dates.toFormatter(this.committerDate);
102+
}
103+
return this._committerDateFormatter;
104+
}
105+
106+
get dateFormatter(): Dates.DateFormatter {
107+
return CommitFormatting.dateType === DateType.Committer
108+
? this.committerDateFormatter : this.authorDateFormatter;
109+
}
110+
80111
get formattedDate(): string {
81112
return CommitFormatting.dateStyle === DateStyle.Absolute
82113
? this.formatDate(CommitFormatting.dateFormat)
@@ -149,24 +180,16 @@ export abstract class GitCommit {
149180
return this.workingFileName ? GitUri.resolveToUri(this.workingFileName, this.repoPath) : this.uri;
150181
}
151182

152-
private _dateFormatter?: Dates.DateFormatter;
153-
154183
formatDate(format?: string | null) {
155184
if (format == null) {
156185
format = 'MMMM Do, YYYY h:mma';
157186
}
158187

159-
if (this._dateFormatter === undefined) {
160-
this._dateFormatter = Dates.toFormatter(this.date);
161-
}
162-
return this._dateFormatter.format(format);
188+
return this.dateFormatter.format(format);
163189
}
164190

165191
fromNow() {
166-
if (this._dateFormatter === undefined) {
167-
this._dateFormatter = Dates.toFormatter(this.date);
168-
}
169-
return this._dateFormatter.fromNow();
192+
return this.dateFormatter.fromNow();
170193
}
171194

172195
getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string {

src/git/models/logCommit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class GitLogCommit extends GitCommit {
3535
author,
3636
email,
3737
date,
38+
committedDate,
3839
message,
3940
fileName,
4041
originalFileName,

src/git/parsers/blameParser.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ interface BlameEntry {
1818
authorTimeZone?: string;
1919
authorEmail?: string;
2020

21+
committerDate?: string;
22+
committerTimeZone?: string;
23+
2124
previousSha?: string;
2225
previousFileName?: string;
2326

@@ -107,6 +110,14 @@ export class GitBlameParser {
107110
entry.authorTimeZone = lineParts[1];
108111
break;
109112

113+
case 'committer-time':
114+
entry.committerDate = lineParts[1];
115+
break;
116+
117+
case 'committer-tz':
118+
entry.committerTimeZone = lineParts[1];
119+
break;
120+
110121
case 'summary':
111122
entry.summary = lineParts
112123
.slice(1)
@@ -207,6 +218,7 @@ export class GitBlameParser {
207218
entry.author,
208219
entry.authorEmail,
209220
new Date((entry.authorDate as any) * 1000),
221+
new Date((entry.committerDate as any) * 1000),
210222
entry.summary!,
211223
relativeFileName,
212224
entry.previousFileName !== undefined && entry.previousFileName !== entry.fileName

0 commit comments

Comments
 (0)