ソースを参照

Adds recognition for Zyck's contribution

Adds clearing of the user cache on config change
Fixes lint issues and adds some comments
main
Eric Amodio 6年前
コミット
915e6bd693
5個のファイルの変更24行の追加15行の削除
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      README.md
  3. +6
    -2
      src/git/parsers/blameParser.ts
  4. +5
    -1
      src/git/parsers/logParser.ts
  5. +11
    -12
      src/gitService.ts

+ 1
- 0
CHANGELOG.md ファイルの表示

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed ### Fixed
- Fixes [#462](https://github.com/eamodio/vscode-gitlens/issues/462) - Source Control shortcut on macOS (⌃⇧G) shouldn't be overridden - Fixes [#462](https://github.com/eamodio/vscode-gitlens/issues/462) - Source Control shortcut on macOS (⌃⇧G) shouldn't be overridden
- 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))
## [8.5.3] - 2018-07-25 ## [8.5.3] - 2018-07-25
### Fixed ### Fixed

+ 1
- 0
README.md ファイルの表示

@ -801,6 +801,7 @@ A big thanks to the people that have contributed to this project:
- Zack Schuster ([@zackschuster](https://github.com/zackschuster)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zackschuster) - Zack Schuster ([@zackschuster](https://github.com/zackschuster)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=zackschuster)
- SpaceEEC ([@SpaceEEC](https://github.com/SpaceEEC)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=SpaceEEC) - SpaceEEC ([@SpaceEEC](https://github.com/SpaceEEC)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=SpaceEEC)
- Alexey Vasyukov ([@notmedia](https://github.com/notmedia)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=notmedia) - Alexey Vasyukov ([@notmedia](https://github.com/notmedia)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=notmedia)
- Zyck ([@qzyse2017](https://github.com/qzyse2017)) — [contributions](https://github.com/eamodio/vscode-gitlens/commits?author=qzyse2017)
Also special thanks to the people that have provided support, testing, brainstorming, etc: Also special thanks to the people that have provided support, testing, brainstorming, etc:

+ 6
- 2
src/git/parsers/blameParser.ts ファイルの表示

@ -28,7 +28,7 @@ export class GitBlameParser {
data: string, data: string,
repoPath: string | undefined, repoPath: string | undefined,
fileName: string, fileName: string,
currentUser: { name?: string, email?: string } | undefined
currentUser: { name?: string; email?: string } | undefined
): GitBlame | undefined { ): GitBlame | undefined {
if (!data) return undefined; if (!data) return undefined;
@ -158,19 +158,23 @@ export class GitBlameParser {
commits: Map<string, GitBlameCommit>, commits: Map<string, GitBlameCommit>,
authors: Map<string, GitAuthor>, authors: Map<string, GitAuthor>,
lines: GitCommitLine[], lines: GitCommitLine[],
currentUser: {name?: string, email?: string} | undefined
currentUser: { name?: string; email?: string } | undefined
) { ) {
let commit = commits.get(entry.sha); let commit = commits.get(entry.sha);
if (commit === undefined) { if (commit === undefined) {
if (entry.author !== undefined) { if (entry.author !== undefined) {
if ( if (
currentUser !== undefined && currentUser !== undefined &&
// Name or e-mail is configured
(currentUser.name !== undefined || currentUser.email !== undefined) && (currentUser.name !== undefined || currentUser.email !== undefined) &&
// Match on name if configured
(currentUser.name === undefined || currentUser.name === entry.author) && (currentUser.name === undefined || currentUser.name === entry.author) &&
// Match on email if configured
(currentUser.email === undefined || currentUser.email === entry.authorEmail) (currentUser.email === undefined || currentUser.email === entry.authorEmail)
) { ) {
entry.author = 'You'; entry.author = 'You';
} }
let author = authors.get(entry.author); let author = authors.get(entry.author);
if (author === undefined) { if (author === undefined) {
author = { author = {

+ 5
- 1
src/git/parsers/logParser.ts ファイルの表示

@ -237,18 +237,22 @@ export class GitLogParser {
commits: Map<string, GitLogCommit>, commits: Map<string, GitLogCommit>,
authors: Map<string, GitAuthor>, authors: Map<string, GitAuthor>,
recentCommit: GitLogCommit | undefined, recentCommit: GitLogCommit | undefined,
currentUser: {name?: string, email?: string} | undefined
currentUser: { name?: string; email?: string } | undefined
): GitLogCommit | undefined { ): GitLogCommit | undefined {
if (commit === undefined) { if (commit === undefined) {
if (entry.author !== undefined) { if (entry.author !== undefined) {
if ( if (
currentUser !== undefined && currentUser !== undefined &&
// Name or e-mail is configured
(currentUser.name !== undefined || currentUser.email !== undefined) && (currentUser.name !== undefined || currentUser.email !== undefined) &&
// Match on name if configured
(currentUser.name === undefined || currentUser.name === entry.author) && (currentUser.name === undefined || currentUser.name === entry.author) &&
// Match on email if configured
(currentUser.email === undefined || currentUser.email === entry.email) (currentUser.email === undefined || currentUser.email === entry.email)
) { ) {
entry.author = 'You'; entry.author = 'You';
} }
let author = authors.get(entry.author); let author = authors.get(entry.author);
if (author === undefined) { if (author === undefined) {
author = { author = {

+ 11
- 12
src/gitService.ts ファイルの表示

@ -67,6 +67,8 @@ const RepoSearchWarnings = {
doesNotExist: /no such file or directory/i doesNotExist: /no such file or directory/i
}; };
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
export enum GitRepoSearchBy { export enum GitRepoSearchBy {
Author = 'author', Author = 'author',
ChangedLines = 'changed-lines', ChangedLines = 'changed-lines',
@ -126,6 +128,10 @@ export class GitService extends Disposable {
private onAnyRepositoryChanged(repo: Repository, reason: RepositoryChange) { private onAnyRepositoryChanged(repo: Repository, reason: RepositoryChange) {
this._trackedCache.clear(); this._trackedCache.clear();
if (reason === RepositoryChange.Config) {
this._userMapCache.delete(repo.path);
}
if (reason === RepositoryChange.Closed) { if (reason === RepositoryChange.Closed) {
// Send a notification that the repositories changed // Send a notification that the repositories changed
setImmediate(async () => { setImmediate(async () => {
@ -751,12 +757,7 @@ export class GitService extends Disposable {
startLine: lineToBlame, startLine: lineToBlame,
endLine: lineToBlame endLine: lineToBlame
}); });
const blame = GitBlameParser.parse(
data,
uri.repoPath,
fileName,
await this.getCurrentUser(uri.repoPath!)
);
const blame = GitBlameParser.parse(data, uri.repoPath, fileName, await this.getCurrentUser(uri.repoPath!));
if (blame === undefined) return undefined; if (blame === undefined) return undefined;
return { return {
@ -924,16 +925,17 @@ export class GitService extends Disposable {
return await Git.config_get(key, repoPath); return await Git.config_get(key, repoPath);
} }
// TODO: Clear cache when git config changes
private _userMapCache = new Map<string, { name?: string; email?: string } | null>(); private _userMapCache = new Map<string, { name?: string; email?: string } | null>();
async getCurrentUser(repoPath: string) { async getCurrentUser(repoPath: string) {
let user = this._userMapCache.get(repoPath); let user = this._userMapCache.get(repoPath);
if (user != null) return user; if (user != null) return user;
// If we found the repo, but no user data was found just return
if (user === null) return undefined; if (user === null) return undefined;
const data = await Git.config_getRegex('user.(name|email)', repoPath); const data = await Git.config_getRegex('user.(name|email)', repoPath);
if (!data) { if (!data) {
// If we found no user data, mark it so we won't bother trying again
this._userMapCache.set(repoPath, null); this._userMapCache.set(repoPath, null);
return undefined; return undefined;
} }
@ -941,16 +943,13 @@ export class GitService extends Disposable {
user = { name: undefined, email: undefined }; user = { name: undefined, email: undefined };
let match: RegExpExecArray | null = null; let match: RegExpExecArray | null = null;
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
do { do {
match = userConfigRegex.exec(data); match = userConfigRegex.exec(data);
if (match == null) {
break;
}
if (match == null) break;
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869 // Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
user[match[1] as 'name' | 'email'] = (' ' + match[2]).substr(1); user[match[1] as 'name' | 'email'] = (' ' + match[2]).substr(1);
} while (match !== null);
} while (match != null);
this._userMapCache.set(repoPath, user); this._userMapCache.set(repoPath, user);
return user; return user;

読み込み中…
キャンセル
保存