Browse Source

Adds e-mail to all commit models

main
Eric Amodio 7 years ago
parent
commit
abf60c2c02
6 changed files with 53 additions and 33 deletions
  1. +1
    -1
      src/git/git.ts
  2. +3
    -0
      src/git/models/blameCommit.ts
  3. +28
    -1
      src/git/models/commit.ts
  4. +2
    -29
      src/git/models/logCommit.ts
  5. +17
    -0
      src/git/parsers/blameParser.ts
  6. +2
    -2
      src/git/parsers/logParser.ts

+ 1
- 1
src/git/git.ts View File

@ -23,7 +23,7 @@ export * from './remotes/provider';
let git: IGit;
const defaultBlameParams = ['blame', '--root', '--incremental'];
const defaultLogParams = ['log', '--name-status', '--full-history', '-M', '--format=%H -%nauthor %an%nauthor-email %ae%nauthor-date %at%nparents %P%nsummary %B%nfilename ?'];
const defaultLogParams = ['log', '--name-status', '--full-history', '-M', '--format=%H -%nauthor %an%nauthor-mail %ae%nauthor-date %at%nparents %P%nsummary %B%nfilename ?'];
const defaultStashParams = ['stash', 'list', '--name-status', '--full-history', '-M', '--format=%H -%nauthor-date %at%nreflog-selector %gd%nsummary %B%nfilename ?'];
const GitWarnings = [

+ 3
- 0
src/git/models/blameCommit.ts View File

@ -7,6 +7,7 @@ export class GitBlameCommit extends GitCommit {
repoPath: string,
sha: string,
author: string,
email: string | undefined,
date: Date,
message: string,
fileName: string,
@ -20,6 +21,7 @@ export class GitBlameCommit extends GitCommit {
repoPath,
sha,
author,
email,
date,
message,
fileName,
@ -40,6 +42,7 @@ export class GitBlameCommit extends GitCommit {
this.repoPath,
changes.sha || this.sha,
this.author,
this.email,
this.date,
this.message,
changes.fileName || this.fileName,

+ 28
- 1
src/git/models/commit.ts View File

@ -1,13 +1,18 @@
'use strict';
import { Dates, Strings } from '../../system';
import { Uri } from 'vscode';
import { configuration, DateStyle } from '../../configuration';
import { configuration, DateStyle, GravatarDefault } from '../../configuration';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import { Git } from '../git';
import { GitUri } from '../gitUri';
import * as path from 'path';
const gravatarCache: Map<string, Uri> = new Map();
export function clearGravatarCache() {
gravatarCache.clear();
}
export interface GitAuthor {
name: string;
lineCount: number;
@ -58,6 +63,7 @@ export abstract class GitCommit {
public readonly repoPath: string,
public readonly sha: string,
public readonly author: string,
public readonly email: string | undefined,
public readonly date: Date,
public readonly message: string,
fileName: string,
@ -165,6 +171,27 @@ export abstract class GitCommit {
return GitUri.getFormattedPath(this.fileName, separator);
}
getGravatarUri(fallback: GravatarDefault): Uri {
const key = this.email
? `${ this.email.trim().toLowerCase() }`
: '';
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email, 'hex') : '00000000000000000000000000000000'}.jpg?s=22&d=${fallback}`);
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
const originalToStringFn = gravatar.toString;
gravatar.toString = function(skipEncoding?: boolean | undefined) {
return originalToStringFn.call(gravatar, true);
};
gravatarCache.set(key, gravatar);
return gravatar;
}
async resolvePreviousFileSha(): Promise<void> {
if (this._resolvedPreviousFileSha !== undefined) return;

+ 2
- 29
src/git/models/logCommit.ts View File

@ -2,17 +2,10 @@
import { Strings } from '../../system';
import { Uri } from 'vscode';
import { GitCommit, GitCommitType } from './commit';
import { GravatarDefault } from '../../configuration';
import { Git } from '../git';
import { GitStatusFileStatus, IGitStatusFile } from './status';
import * as path from 'path';
const gravatarCache: Map<string, Uri> = new Map();
export function clearGravatarCache() {
gravatarCache.clear();
}
export class GitLogCommit extends GitCommit {
nextSha?: string;
@ -23,7 +16,7 @@ export class GitLogCommit extends GitCommit {
repoPath: string,
sha: string,
author: string,
public readonly email: string | undefined,
email: string | undefined,
date: Date,
message: string,
fileName: string,
@ -39,6 +32,7 @@ export class GitLogCommit extends GitCommit {
repoPath,
sha,
author,
email,
date,
message,
fileName,
@ -91,27 +85,6 @@ export class GitLogCommit extends GitCommit {
return `+${added} ~${changed} -${deleted}`;
}
getGravatarUri(fallback: GravatarDefault): Uri {
const key = this.email
? `${ this.email.trim().toLowerCase() }`
: '';
let gravatar = gravatarCache.get(key);
if (gravatar !== undefined) return gravatar;
gravatar = Uri.parse(`https://www.gravatar.com/avatar/${this.email ? Strings.md5(this.email, 'hex') : '00000000000000000000000000000000'}.jpg?s=22&d=${fallback}`);
// HACK: Monkey patch Uri.toString to avoid the unwanted query string encoding
const originalToStringFn = gravatar.toString;
gravatar.toString = function(skipEncoding?: boolean | undefined) {
return originalToStringFn.call(gravatar, true);
};
gravatarCache.set(key, gravatar);
return gravatar;
}
toFileCommit(fileName: string): GitLogCommit | undefined;
toFileCommit(status: IGitStatusFile): GitLogCommit;
toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined {

+ 17
- 0
src/git/parsers/blameParser.ts View File

@ -13,6 +13,7 @@ interface BlameEntry {
author: string;
authorDate?: string;
authorTimeZone?: string;
authorEmail?: string;
previousSha?: string;
previousFileName?: string;
@ -61,6 +62,21 @@ export class GitBlameParser {
: lineParts.slice(1).join(' ').trim();
break;
case 'author-mail':
entry.authorEmail = lineParts.slice(1).join(' ').trim();
const start = entry.authorEmail.indexOf('<');
if (start >= 0) {
const end = entry.authorEmail.indexOf('>', start);
if (end > start) {
entry.authorEmail = entry.authorEmail.substring(start + 1, end);
}
else {
entry.authorEmail = entry.authorEmail.substring(start + 1);
}
}
break;
case 'author-time':
entry.authorDate = lineParts[1];
break;
@ -135,6 +151,7 @@ export class GitBlameParser {
repoPath!,
entry.sha,
entry.author,
entry.authorEmail,
new Date(entry.authorDate as any * 1000),
entry.summary!,
fileName!,

+ 2
- 2
src/git/parsers/logParser.ts View File

@ -9,8 +9,8 @@ interface LogEntry {
sha: string;
author: string;
authorEmail?: string;
authorDate?: string;
authorEmail?: string;
parentShas?: string[];
@ -84,7 +84,7 @@ export class GitLogParser {
: lineParts.slice(1).join(' ').trim();
break;
case 'author-email':
case 'author-mail':
entry.authorEmail = lineParts.slice(1).join(' ').trim();
break;

Loading…
Cancel
Save