Sfoglia il codice sorgente

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 anni fa
parent
commit
915e6bd693
5 ha cambiato i file con 24 aggiunte e 15 eliminazioni
  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 Vedi File

@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- 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
### Fixed

+ 1
- 0
README.md Vedi File

@ -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)
- 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)
- 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:

+ 6
- 2
src/git/parsers/blameParser.ts Vedi File

@ -28,7 +28,7 @@ export class GitBlameParser {
data: string,
repoPath: string | undefined,
fileName: string,
currentUser: { name?: string, email?: string } | undefined
currentUser: { name?: string; email?: string } | undefined
): GitBlame | undefined {
if (!data) return undefined;
@ -158,19 +158,23 @@ export class GitBlameParser {
commits: Map<string, GitBlameCommit>,
authors: Map<string, GitAuthor>,
lines: GitCommitLine[],
currentUser: {name?: string, email?: string} | undefined
currentUser: { name?: string; email?: string } | undefined
) {
let commit = commits.get(entry.sha);
if (commit === undefined) {
if (entry.author !== undefined) {
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';
}
let author = authors.get(entry.author);
if (author === undefined) {
author = {

+ 5
- 1
src/git/parsers/logParser.ts Vedi File

@ -237,18 +237,22 @@ export class GitLogParser {
commits: Map<string, GitLogCommit>,
authors: Map<string, GitAuthor>,
recentCommit: GitLogCommit | undefined,
currentUser: {name?: string, email?: string} | undefined
currentUser: { name?: string; email?: string } | undefined
): GitLogCommit | undefined {
if (commit === undefined) {
if (entry.author !== undefined) {
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.email)
) {
entry.author = 'You';
}
let author = authors.get(entry.author);
if (author === undefined) {
author = {

+ 11
- 12
src/gitService.ts Vedi File

@ -67,6 +67,8 @@ const RepoSearchWarnings = {
doesNotExist: /no such file or directory/i
};
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
export enum GitRepoSearchBy {
Author = 'author',
ChangedLines = 'changed-lines',
@ -126,6 +128,10 @@ export class GitService extends Disposable {
private onAnyRepositoryChanged(repo: Repository, reason: RepositoryChange) {
this._trackedCache.clear();
if (reason === RepositoryChange.Config) {
this._userMapCache.delete(repo.path);
}
if (reason === RepositoryChange.Closed) {
// Send a notification that the repositories changed
setImmediate(async () => {
@ -751,12 +757,7 @@ export class GitService extends Disposable {
startLine: 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;
return {
@ -924,16 +925,17 @@ export class GitService extends Disposable {
return await Git.config_get(key, repoPath);
}
// TODO: Clear cache when git config changes
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;
}
@ -941,16 +943,13 @@ export class GitService extends Disposable {
user = { name: undefined, email: undefined };
let match: RegExpExecArray | null = null;
const userConfigRegex = /^user\.(name|email) (.*)$/gm;
do {
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
user[match[1] as 'name' | 'email'] = (' ' + match[2]).substr(1);
} while (match !== null);
} while (match != null);
this._userMapCache.set(repoPath, user);
return user;

Caricamento…
Annulla
Salva