Browse Source

Adds e-mail to all commit models

main
Eric Amodio 6 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; let git: IGit;
const defaultBlameParams = ['blame', '--root', '--incremental']; 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 defaultStashParams = ['stash', 'list', '--name-status', '--full-history', '-M', '--format=%H -%nauthor-date %at%nreflog-selector %gd%nsummary %B%nfilename ?'];
const GitWarnings = [ const GitWarnings = [

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

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

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

@ -1,13 +1,18 @@
'use strict'; 'use strict';
import { Dates, Strings } from '../../system'; import { Dates, Strings } from '../../system';
import { Uri } from 'vscode'; import { Uri } from 'vscode';
import { configuration, DateStyle } from '../../configuration';
import { configuration, DateStyle, GravatarDefault } from '../../configuration';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { Git } from '../git'; import { Git } from '../git';
import { GitUri } from '../gitUri'; import { GitUri } from '../gitUri';
import * as path from 'path'; import * as path from 'path';
const gravatarCache: Map<string, Uri> = new Map();
export function clearGravatarCache() {
gravatarCache.clear();
}
export interface GitAuthor { export interface GitAuthor {
name: string; name: string;
lineCount: number; lineCount: number;
@ -58,6 +63,7 @@ export abstract class GitCommit {
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 date: Date, public readonly date: Date,
public readonly message: string, public readonly message: string,
fileName: string, fileName: string,
@ -165,6 +171,27 @@ export abstract class GitCommit {
return GitUri.getFormattedPath(this.fileName, separator); 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> { async resolvePreviousFileSha(): Promise<void> {
if (this._resolvedPreviousFileSha !== undefined) return; if (this._resolvedPreviousFileSha !== undefined) return;

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

@ -2,17 +2,10 @@
import { Strings } from '../../system'; import { Strings } from '../../system';
import { Uri } from 'vscode'; import { Uri } from 'vscode';
import { GitCommit, GitCommitType } from './commit'; import { GitCommit, GitCommitType } from './commit';
import { GravatarDefault } from '../../configuration';
import { Git } from '../git'; import { Git } from '../git';
import { GitStatusFileStatus, IGitStatusFile } from './status'; import { GitStatusFileStatus, IGitStatusFile } from './status';
import * as path from 'path'; import * as path from 'path';
const gravatarCache: Map<string, Uri> = new Map();
export function clearGravatarCache() {
gravatarCache.clear();
}
export class GitLogCommit extends GitCommit { export class GitLogCommit extends GitCommit {
nextSha?: string; nextSha?: string;
@ -23,7 +16,7 @@ export class GitLogCommit extends GitCommit {
repoPath: string, repoPath: string,
sha: string, sha: string,
author: string, author: string,
public readonly email: string | undefined,
email: string | undefined,
date: Date, date: Date,
message: string, message: string,
fileName: string, fileName: string,
@ -39,6 +32,7 @@ export class GitLogCommit extends GitCommit {
repoPath, repoPath,
sha, sha,
author, author,
email,
date, date,
message, message,
fileName, fileName,
@ -91,27 +85,6 @@ export class GitLogCommit extends GitCommit {
return `+${added} ~${changed} -${deleted}`; 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(fileName: string): GitLogCommit | undefined;
toFileCommit(status: IGitStatusFile): GitLogCommit; toFileCommit(status: IGitStatusFile): GitLogCommit;
toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined { toFileCommit(fileNameOrStatus: string | IGitStatusFile): GitLogCommit | undefined {

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

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

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

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

Loading…
Cancel
Save