Bläddra i källkod

Adds option to show committer date

Fixes #537
main
Mathew King 5 år sedan
committed by Eric Amodio
förälder
incheckning
b8d9d7a364
9 ändrade filer med 78 tillägg och 16 borttagningar
  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 Visa fil

@ -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 |

+ 14
- 0
package.json Visa fil

@ -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",

+ 2
- 1
src/codelens/codeLensController.ts Visa fil

@ -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');

+ 6
- 0
src/config.ts Visa fil

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

+ 2
- 1
src/git/gitService.ts Visa fil

@ -168,7 +168,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();
}

+ 6
- 3
src/git/models/blameCommit.ts Visa fil

@ -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,
@ -21,7 +22,8 @@ export class GitBlameCommit extends GitCommit {
sha,
author,
email,
date,
authorDate,
committerDate,
message,
fileName,
originalFileName,
@ -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),

+ 34
- 11
src/git/models/commit.ts Visa fil

@ -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;
@ -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);
}
};
@ -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,
@ -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)
@ -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 {

+ 1
- 0
src/git/models/logCommit.ts Visa fil

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

+ 12
- 0
src/git/parsers/blameParser.ts Visa fil

@ -18,6 +18,9 @@ interface BlameEntry {
authorTimeZone?: string;
authorEmail?: string;
committerDate?: string;
committerTimeZone?: string;
previousSha?: string;
previousFileName?: string;
@ -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)
@ -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,
entry.previousFileName !== undefined && entry.previousFileName !== entry.fileName

Laddar…
Avbryt
Spara