Quellcode durchsuchen

Closes #341 - changes author to You when appropriate

main
Eric Amodio vor 6 Jahren
Ursprung
Commit
cd7eeda9d3
4 geänderte Dateien mit 73 neuen und 15 gelöschten Zeilen
  1. +3
    -0
      CHANGELOG.md
  2. +10
    -4
      src/git/parsers/blameParser.ts
  3. +10
    -4
      src/git/parsers/logParser.ts
  4. +50
    -7
      src/gitService.ts

+ 3
- 0
CHANGELOG.md Datei anzeigen

@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added
- Adds an indicator to the *GitLens* explorer's branch history to mark the the tips of all branches
### Changed
- Changes the author name to "You" when appropriate — closes [#341](https://github.com/eamodio/vscode-gitlens/issues/341)
### Fixed
- Fixes [#345](https://github.com/eamodio/vscode-gitlens/issues/345) - Custom date formats don't work in the GitLens view
- Fixes [#336](https://github.com/eamodio/vscode-gitlens/issues/336) - Default Settings Get Added Automatically

+ 10
- 4
src/git/parsers/blameParser.ts Datei anzeigen

@ -25,7 +25,7 @@ interface BlameEntry {
export class GitBlameParser {
static parse(data: string, repoPath: string | undefined, fileName: string): GitBlame | undefined {
static parse(data: string, repoPath: string | undefined, fileName: string, currentUser: string | undefined): GitBlame | undefined {
if (!data) return undefined;
const authors: Map<string, GitAuthor> = new Map();
@ -57,9 +57,15 @@ export class GitBlameParser {
switch (lineParts[0]) {
case 'author':
entry.author = Git.isUncommitted(entry.sha)
? 'You'
: lineParts.slice(1).join(' ').trim();
if (Git.isUncommitted(entry.sha)) {
entry.author = 'You';
}
else {
entry.author = lineParts.slice(1).join(' ').trim();
if (currentUser !== undefined && currentUser === entry.author) {
entry.author = 'You';
}
}
break;
case 'author-mail':

+ 10
- 4
src/git/parsers/logParser.ts Datei anzeigen

@ -28,7 +28,7 @@ const emptyEntry: LogEntry = {};
export class GitLogParser {
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range | undefined): GitLog | undefined {
static parse(data: string, type: GitCommitType, repoPath: string | undefined, fileName: string | undefined, sha: string | undefined, currentUser: string | undefined, maxCount: number | undefined, reverse: boolean, range: Range | undefined): GitLog | undefined {
if (!data) return undefined;
let relativeFileName: string;
@ -74,9 +74,15 @@ export class GitLogParser {
break;
case 97: // 'a': // author
entry.author = Git.isUncommitted(entry.ref)
? 'You'
: line.substring(4);
if (Git.isUncommitted(entry.ref)) {
entry.author = 'You';
}
else {
entry.author = line.substring(4);
if (currentUser !== undefined && currentUser === entry.author) {
entry.author = 'You';
}
}
break;
case 101: // 'e': // author-mail

+ 50
- 7
src/gitService.ts Datei anzeigen

@ -457,7 +457,7 @@ export class GitService extends Disposable {
try {
const data = await Git.blame(root, file, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace });
const blame = GitBlameParser.parse(data, root, file);
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root));
return blame;
}
catch (ex) {
@ -526,7 +526,7 @@ export class GitService extends Disposable {
try {
const data = await Git.blame_contents(root, file, contents, { correlationKey: `:${key}`, ignoreWhitespace: Container.config.blame.ignoreWhitespace });
const blame = GitBlameParser.parse(data, root, file);
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root));
return blame;
}
catch (ex) {
@ -576,7 +576,7 @@ export class GitService extends Disposable {
try {
const data = await Git.blame(uri.repoPath, fileName, uri.sha, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame });
const blame = GitBlameParser.parse(data, uri.repoPath, fileName);
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, await this.getCurrentUsername(uri.repoPath!));
if (blame === undefined) return undefined;
return {
@ -618,7 +618,8 @@ export class GitService extends Disposable {
try {
const data = await Git.blame_contents(uri.repoPath, fileName, contents, { ignoreWhitespace: Container.config.blame.ignoreWhitespace, startLine: lineToBlame, endLine: lineToBlame });
const blame = GitBlameParser.parse(data, uri.repoPath, fileName);
const currentUser = await this.getCurrentUsername(uri.repoPath!);
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, currentUser);
if (blame === undefined) return undefined;
return {
@ -723,6 +724,18 @@ export class GitService extends Disposable {
return await Git.config_get(key, repoPath);
}
// TODO: Clear cache when git config changes
private _userNameMapCache: Map<string, string | undefined> = new Map();
async getCurrentUsername(repoPath: string) {
let user = this._userNameMapCache.get(repoPath);
if (user === undefined) {
user = await Git.config_get('user.name', repoPath);
this._userNameMapCache.set(repoPath, user);
}
return user;
}
async getDiffForFile(uri: GitUri, sha1?: string, sha2?: string): Promise<GitDiff | undefined> {
if (sha1 !== undefined && sha2 === undefined && uri.sha !== undefined) {
sha2 = uri.sha;
@ -868,7 +881,17 @@ export class GitService extends Disposable {
try {
const data = await Git.log(repoPath, { maxCount: maxCount, ref: options.ref, reverse: options.reverse });
const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, options.ref, maxCount, options.reverse!, undefined);
const log = GitLogParser.parse(
data,
GitCommitType.Branch,
repoPath,
undefined,
options.ref,
await this.getCurrentUsername(repoPath),
maxCount,
options.reverse!,
undefined
);
if (log !== undefined) {
const opts = { ...options };
@ -914,7 +937,17 @@ export class GitService extends Disposable {
try {
const data = await Git.log_search(repoPath, searchArgs, { maxCount: maxCount });
const log = GitLogParser.parse(data, GitCommitType.Branch, repoPath, undefined, undefined, maxCount, false, undefined);
const log = GitLogParser.parse(
data,
GitCommitType.Branch,
repoPath,
undefined,
undefined,
await this.getCurrentUsername(repoPath),
maxCount,
false,
undefined
);
if (log !== undefined) {
const opts = { ...options };
@ -1015,7 +1048,17 @@ export class GitService extends Disposable {
: options.maxCount;
const data = await Git.log_file(root, file, { ...opts, maxCount: maxCount, startLine: range && range.start.line + 1, endLine: range && range.end.line + 1 });
const log = GitLogParser.parse(data, GitCommitType.File, root, file, opts.ref, maxCount, opts.reverse!, range);
const log = GitLogParser.parse(
data,
GitCommitType.File,
root,
file,
opts.ref,
await this.getCurrentUsername(root),
maxCount,
opts.reverse!,
range
);
if (log !== undefined) {
const opts = { ...options };

Laden…
Abbrechen
Speichern