New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix incorrect author display You
(#457)
#460
Changes from 3 commits
784285e
02e5ce7
787ad5c
2a5260e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ export class GitLogParser { | |
repoPath: string | undefined, | ||
fileName: string | undefined, | ||
sha: string | undefined, | ||
currentUser: string | undefined, | ||
currentUser: { name?: string; email?: string } | undefined, | ||
maxCount: number | undefined, | ||
reverse: boolean, | ||
range: Range | undefined | ||
|
@@ -87,9 +87,6 @@ export class GitLogParser { | |
} | ||
else { | ||
entry.author = line.substring(4); | ||
if (currentUser !== undefined && currentUser === entry.author) { | ||
entry.author = 'You'; | ||
} | ||
} | ||
break; | ||
|
||
|
@@ -211,7 +208,8 @@ export class GitLogParser { | |
relativeFileName, | ||
commits, | ||
authors, | ||
recentCommit | ||
recentCommit, | ||
currentUser | ||
); | ||
|
||
break; | ||
|
@@ -238,10 +236,15 @@ export class GitLogParser { | |
relativeFileName: string, | ||
commits: Map<string, GitLogCommit>, | ||
authors: Map<string, GitAuthor>, | ||
recentCommit: GitLogCommit | undefined | ||
recentCommit: GitLogCommit | undefined, | ||
currentUser: {name?: string, email?: string} | undefined | ||
): GitLogCommit | undefined { | ||
if (commit === undefined) { | ||
if (entry.author !== undefined) { | ||
if (currentUser !== undefined && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here if (
currentUser !== undefined &&
// Name or e-mail is configured
(currentUser.name !== undefined || currentUser.email !== undefined) &&
// Match on name if configured
(currentUser.name === undefined || currentUser.name === entry.author) &&
// Match on email if configured
(currentUser.email === undefined || currentUser.email === entry.authorEmail)
) {
entry.author = 'You';
} |
||
currentUser.name === entry.author && currentUser.email === entry.email) { | ||
entry.author = 'You'; | ||
} | ||
let author = authors.get(entry.author); | ||
if (author === undefined) { | ||
author = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -612,7 +612,7 @@ export class GitService extends Disposable { | |
args: Container.config.advanced.blame.customArguments, | ||
ignoreWhitespace: Container.config.blame.ignoreWhitespace | ||
}); | ||
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root)); | ||
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUser(root)); | ||
return blame; | ||
} | ||
catch (ex) { | ||
|
@@ -692,7 +692,7 @@ export class GitService extends Disposable { | |
correlationKey: `:${key}`, | ||
ignoreWhitespace: Container.config.blame.ignoreWhitespace | ||
}); | ||
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUsername(root)); | ||
const blame = GitBlameParser.parse(data, root, file, await this.getCurrentUser(root)); | ||
return blame; | ||
} | ||
catch (ex) { | ||
|
@@ -755,7 +755,7 @@ export class GitService extends Disposable { | |
data, | ||
uri.repoPath, | ||
fileName, | ||
await this.getCurrentUsername(uri.repoPath!) | ||
await this.getCurrentUser(uri.repoPath!) | ||
); | ||
if (blame === undefined) return undefined; | ||
|
||
|
@@ -808,7 +808,7 @@ export class GitService extends Disposable { | |
startLine: lineToBlame, | ||
endLine: lineToBlame | ||
}); | ||
const currentUser = await this.getCurrentUsername(uri.repoPath!); | ||
const currentUser = await this.getCurrentUser(uri.repoPath!); | ||
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, currentUser); | ||
if (blame === undefined) return undefined; | ||
|
||
|
@@ -925,13 +925,17 @@ export class GitService extends Disposable { | |
} | ||
|
||
// TODO: Clear cache when git config changes | ||
private _userNameMapCache: Map<string, string | undefined> = new Map(); | ||
private _userMapCache: Map<string, { name: string, email: string } | undefined> = new Map(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be adapted like so private _userMapCache = new Map<string, { name?: string; email?: string } | null>();
async getCurrentUser(repoPath: string) {
let user = this._userMapCache.get(repoPath);
if (user != null) return user;
// If we found the repo, but no user data was found just return
if (user === null) return undefined;
const data = await Git.config_getRegex('user.(name|email)', repoPath);
if (!data) {
// If we found no user data, mark it so we won't bother trying again
this._userMapCache.set(repoPath, null);
return undefined;
}
user = { name: undefined, email: undefined };
let match: RegExpExecArray | null = null;
do {
match = userConfigRegex.exec(data);
if (match == null) break;
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
user[match[1] as 'name' | 'email'] = (' ' + match[2]).substr(1);
} while (match != null);
this._userMapCache.set(repoPath, user);
return user;
} Allows user name or email to be missing, and avoids calling config each time if we don't find data. It also allows for the last entry to win (since that is "closest" to the repo) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The regex const userConfigRegex = /^user\.(name|email) (.*)$/gm; Can be placed on line 70 in |
||
|
||
async getCurrentUsername(repoPath: string) { | ||
let user = this._userNameMapCache.get(repoPath); | ||
async getCurrentUser(repoPath: string) { | ||
const user = this._userMapCache.get(repoPath); | ||
if (user === undefined) { | ||
user = await Git.config_get('user.name', repoPath); | ||
this._userNameMapCache.set(repoPath, user); | ||
const userName = await Git.config_get('user.name', repoPath); | ||
const userEmail = await Git.config_get('user.email', repoPath); | ||
if (userName !== undefined && userEmail !== undefined) { | ||
this._userMapCache.set(repoPath, {name: userName, email: userEmail}); | ||
return {name: userName, email: userEmail}; | ||
} | ||
} | ||
return user; | ||
} | ||
|
@@ -1120,7 +1124,7 @@ export class GitService extends Disposable { | |
repoPath, | ||
undefined, | ||
options.ref, | ||
await this.getCurrentUsername(repoPath), | ||
await this.getCurrentUser(repoPath), | ||
maxCount, | ||
options.reverse!, | ||
undefined | ||
|
@@ -1179,7 +1183,7 @@ export class GitService extends Disposable { | |
repoPath, | ||
undefined, | ||
undefined, | ||
await this.getCurrentUsername(repoPath), | ||
await this.getCurrentUser(repoPath), | ||
maxCount, | ||
false, | ||
undefined | ||
|
@@ -1334,7 +1338,7 @@ export class GitService extends Disposable { | |
root, | ||
file, | ||
opts.ref, | ||
await this.getCurrentUsername(root), | ||
await this.getCurrentUser(root), | ||
maxCount, | ||
opts.reverse!, | ||
range | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this
if
should look like