Skip to content

Commit 915e6bd

Browse files
committed
Adds recognition for Zyck's contribution
Adds clearing of the user cache on config change Fixes lint issues and adds some comments
1 parent 6122550 commit 915e6bd

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111

1212
### Fixed
1313
- Fixes [#462](https://github.com/eamodio/vscode-gitlens/issues/462) - Source Control shortcut on macOS (⌃⇧G) shouldn't be overridden
14+
- Fixes [#457](https://github.com/eamodio/vscode-gitlens/issues/457) - Displays the wrong username (You) — thanks to [PR #460](https://github.com/eamodio/vscode-gitlens/pull/460) by Zyck ([@qzyse2017](https://github.com/qzyse2017))
1415

1516
## [8.5.3] - 2018-07-25
1617
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ A big thanks to the people that have contributed to this project:
801801
- Zack Schuster ([@zackschuster](https://github.com/zackschuster)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zackschuster)
802802
- SpaceEEC ([@SpaceEEC](https://github.com/SpaceEEC)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=SpaceEEC)
803803
- Alexey Vasyukov ([@notmedia](https://github.com/notmedia)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=notmedia)
804+
- Zyck ([@qzyse2017](https://github.com/qzyse2017)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=qzyse2017)
804805

805806
Also special thanks to the people that have provided support, testing, brainstorming, etc:
806807

src/git/parsers/blameParser.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class GitBlameParser {
2828
data: string,
2929
repoPath: string | undefined,
3030
fileName: string,
31-
currentUser: { name?: string, email?: string } | undefined
31+
currentUser: { name?: string; email?: string } | undefined
3232
): GitBlame | undefined {
3333
if (!data) return undefined;
3434

@@ -158,19 +158,23 @@ export class GitBlameParser {
158158
commits: Map<string, GitBlameCommit>,
159159
authors: Map<string, GitAuthor>,
160160
lines: GitCommitLine[],
161-
currentUser: {name?: string, email?: string} | undefined
161+
currentUser: { name?: string; email?: string } | undefined
162162
) {
163163
let commit = commits.get(entry.sha);
164164
if (commit === undefined) {
165165
if (entry.author !== undefined) {
166166
if (
167167
currentUser !== undefined &&
168+
// Name or e-mail is configured
168169
(currentUser.name !== undefined || currentUser.email !== undefined) &&
170+
// Match on name if configured
169171
(currentUser.name === undefined || currentUser.name === entry.author) &&
172+
// Match on email if configured
170173
(currentUser.email === undefined || currentUser.email === entry.authorEmail)
171174
) {
172175
entry.author = 'You';
173176
}
177+
174178
let author = authors.get(entry.author);
175179
if (author === undefined) {
176180
author = {

src/git/parsers/logParser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,22 @@ export class GitLogParser {
237237
commits: Map<string, GitLogCommit>,
238238
authors: Map<string, GitAuthor>,
239239
recentCommit: GitLogCommit | undefined,
240-
currentUser: {name?: string, email?: string} | undefined
240+
currentUser: { name?: string; email?: string } | undefined
241241
): GitLogCommit | undefined {
242242
if (commit === undefined) {
243243
if (entry.author !== undefined) {
244244
if (
245245
currentUser !== undefined &&
246+
// Name or e-mail is configured
246247
(currentUser.name !== undefined || currentUser.email !== undefined) &&
248+
// Match on name if configured
247249
(currentUser.name === undefined || currentUser.name === entry.author) &&
250+
// Match on email if configured
248251
(currentUser.email === undefined || currentUser.email === entry.email)
249252
) {
250253
entry.author = 'You';
251254
}
255+
252256
let author = authors.get(entry.author);
253257
if (author === undefined) {
254258
author = {

src/gitService.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ const RepoSearchWarnings = {
6767
doesNotExist: /no such file or directory/i
6868
};
6969

70+
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
71+
7072
export enum GitRepoSearchBy {
7173
Author = 'author',
7274
ChangedLines = 'changed-lines',
@@ -126,6 +128,10 @@ export class GitService extends Disposable {
126128
private onAnyRepositoryChanged(repo: Repository, reason: RepositoryChange) {
127129
this._trackedCache.clear();
128130

131+
if (reason === RepositoryChange.Config) {
132+
this._userMapCache.delete(repo.path);
133+
}
134+
129135
if (reason === RepositoryChange.Closed) {
130136
// Send a notification that the repositories changed
131137
setImmediate(async () => {
@@ -751,12 +757,7 @@ export class GitService extends Disposable {
751757
startLine: lineToBlame,
752758
endLine: lineToBlame
753759
});
754-
const blame = GitBlameParser.parse(
755-
data,
756-
uri.repoPath,
757-
fileName,
758-
await this.getCurrentUser(uri.repoPath!)
759-
);
760+
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, await this.getCurrentUser(uri.repoPath!));
760761
if (blame === undefined) return undefined;
761762

762763
return {
@@ -924,33 +925,31 @@ export class GitService extends Disposable {
924925
return await Git.config_get(key, repoPath);
925926
}
926927

927-
// TODO: Clear cache when git config changes
928928
private _userMapCache = new Map<string, { name?: string; email?: string } | null>();
929929

930930
async getCurrentUser(repoPath: string) {
931931
let user = this._userMapCache.get(repoPath);
932932
if (user != null) return user;
933+
// If we found the repo, but no user data was found just return
933934
if (user === null) return undefined;
934935

935936
const data = await Git.config_getRegex('user.(name|email)', repoPath);
936937
if (!data) {
938+
// If we found no user data, mark it so we won't bother trying again
937939
this._userMapCache.set(repoPath, null);
938940
return undefined;
939941
}
940942

941943
user = { name: undefined, email: undefined };
942944

943945
let match: RegExpExecArray | null = null;
944-
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
945946
do {
946947
match = userConfigRegex.exec(data);
947-
if (match == null) {
948-
break;
949-
}
948+
if (match == null) break;
950949

951950
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
952951
user[match[1] as 'name' | 'email'] = (' ' + match[2]).substr(1);
953-
} while (match !== null);
952+
} while (match != null);
954953

955954
this._userMapCache.set(repoPath, user);
956955
return user;

0 commit comments

Comments
 (0)