Skip to content

Commit

Permalink
Adds option to show committer date
Browse files Browse the repository at this point in the history
Fixes #537
  • Loading branch information
MathewKing committed Apr 11, 2019
1 parent 37a7f8b commit ab42de4
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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.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.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.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 |
Expand Down
14 changes: 14 additions & 0 deletions package.json
Expand Up @@ -439,6 +439,20 @@
"markdownDescription": "Specifies how dates will be displayed by default",
"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": {
"type": "string",
"default": "robohash",
Expand Down
3 changes: 2 additions & 1 deletion src/codelens/codeLensController.ts
Expand Up @@ -32,7 +32,8 @@ export class GitCodeLensController implements Disposable {
if (
configuration.changed(e, section, null) ||
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)) {
Logger.log('CodeLens config changed; resetting CodeLens provider');
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Expand Up @@ -30,6 +30,7 @@ export interface Config {
defaultDateFormat: string | null;
defaultDateShortFormat: string | null;
defaultDateStyle: DateStyle;
defaultDateType: DateType;
defaultGravatarsStyle: GravatarDefaultStyle;
heatmap: {
ageThreshold: number;
Expand Down Expand Up @@ -126,6 +127,11 @@ export enum CustomRemoteType {
GitLab = 'GitLab'
}

export enum DateType {
Author = 'author',
Committer = 'committer'
}

export enum DateStyle {
Absolute = 'absolute',
Relative = 'relative'
Expand Down
3 changes: 2 additions & 1 deletion src/git/gitService.ts
Expand Up @@ -167,7 +167,8 @@ export class GitService implements Disposable {
private onConfigurationChanged(e: ConfigurationChangeEvent) {
if (
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();
}
Expand Down
9 changes: 6 additions & 3 deletions src/git/models/blameCommit.ts
Expand Up @@ -7,7 +7,8 @@ export class GitBlameCommit extends GitCommit {
sha: string,
author: string,
email: string | undefined,
date: Date,
authorDate: Date,
committerDate: Date,
message: string,
fileName: string,
originalFileName: string | undefined,
Expand All @@ -21,7 +22,8 @@ export class GitBlameCommit extends GitCommit {
sha,
author,
email,
date,
authorDate,
committerDate,
message,
fileName,
originalFileName,
Expand Down Expand Up @@ -49,7 +51,8 @@ export class GitBlameCommit extends GitCommit {
changes.sha || this.sha,
this.author,
this.email,
this.date,
this.authorDate,
this.committerDate,
this.message,
changes.fileName || this.fileName,
this.getChangedValue(changes.originalFileName, this.originalFileName),
Expand Down
45 changes: 34 additions & 11 deletions src/git/models/commit.ts
Expand Up @@ -7,6 +7,7 @@ import { CommitFormatter } from '../formatters/formatters';
import { Git } from '../git';
import { GitUri } from '../gitUri';
import { getGravatarUri } from '../../gravatar';
import { DateType } from '../../config';

export interface GitAuthor {
name: string;
Expand All @@ -32,10 +33,12 @@ export enum GitCommitType {
export const CommitFormatting = {
dateFormat: undefined! as string | null,
dateStyle: undefined! as DateStyle,
dateType: undefined! as DateType,

reset: () => {
CommitFormatting.dateStyle = configuration.get<DateStyle>(configuration.name('defaultDateStyle').value);
CommitFormatting.dateFormat = configuration.get<string | null>(configuration.name('defaultDateFormat').value);
CommitFormatting.dateType = configuration.get<DateType>(configuration.name('defaultDateType').value);
}
};

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

private _authorDateFormatter: Dates.DateFormatter | undefined;
private _committerDateFormatter: Dates.DateFormatter | undefined;

constructor(
type: GitCommitType,
public readonly repoPath: string,
public readonly sha: string,
public readonly author: string,
public readonly email: string | undefined,
public readonly date: Date,
public readonly authorDate: Date,
public readonly committerDate: Date,
public readonly message: string,
fileName: string,
originalFileName?: string,
Expand All @@ -77,6 +84,30 @@ export abstract class GitCommit {
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 {
return CommitFormatting.dateStyle === DateStyle.Absolute
? this.formatDate(CommitFormatting.dateFormat)
Expand Down Expand Up @@ -149,24 +180,16 @@ export abstract class GitCommit {
return this.workingFileName ? GitUri.resolveToUri(this.workingFileName, this.repoPath) : this.uri;
}

private _dateFormatter?: Dates.DateFormatter;

formatDate(format?: string | null) {
if (format == null) {
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() {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/git/models/logCommit.ts
Expand Up @@ -35,6 +35,7 @@ export class GitLogCommit extends GitCommit {
author,
email,
date,
committedDate,
message,
fileName,
originalFileName,
Expand Down
12 changes: 12 additions & 0 deletions src/git/parsers/blameParser.ts
Expand Up @@ -18,6 +18,9 @@ interface BlameEntry {
authorTimeZone?: string;
authorEmail?: string;

committerDate?: string;
committerTimeZone?: string;

previousSha?: string;
previousFileName?: string;

Expand Down Expand Up @@ -107,6 +110,14 @@ export class GitBlameParser {
entry.authorTimeZone = lineParts[1];
break;

case 'committer-time':
entry.committerDate = lineParts[1];
break;

case 'committer-tz':
entry.committerTimeZone = lineParts[1];
break;

case 'summary':
entry.summary = lineParts
.slice(1)
Expand Down Expand Up @@ -207,6 +218,7 @@ export class GitBlameParser {
entry.author,
entry.authorEmail,
new Date((entry.authorDate as any) * 1000),
new Date((entry.committerDate as any) * 1000),
entry.summary!,
relativeFileName,
relativeFileName !== entry.fileName ? entry.fileName : undefined,
Expand Down

0 comments on commit ab42de4

Please sign in to comment.