From 61ce8adad0afee507643fdc5eeb4688724b3472c Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 16 Oct 2017 22:43:40 -0400 Subject: [PATCH] Fixes issues with tracked .gitignore'd files --- CHANGELOG.md | 5 + README.md | 1 - package-lock.json | 240 ++++++++++--------------------------------- package.json | 10 +- src/@types/ignore/index.d.ts | 10 -- src/configuration.ts | 3 - src/gitService.ts | 106 ++++++++++--------- 7 files changed, 115 insertions(+), 260 deletions(-) delete mode 100644 src/@types/ignore/index.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b639b4..afc3acd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Removed +- Removes `gitlens.advanced.gitignore.enabled` setting since it usage has been replaced by a tracked file cache + +### Fixed +- Fixes issues with tracked files which are ignored via `.gitignore` not working properly ## [5.6.4] - 2017-10-12 ### Fixed diff --git a/README.md b/README.md index 2378c0f..55d5c19 100644 --- a/README.md +++ b/README.md @@ -430,7 +430,6 @@ GitLens is highly customizable and provides many configuration settings to allow |`gitlens.advanced.caching.enabled`|Specifies whether git output will be cached |`gitlens.advanced.caching.maxLines`|Specifies the threshold for caching larger documents |`gitlens.advanced.git`|Specifies the git path to use -|`gitlens.advanced.gitignore.enabled`|Specifies whether or not to parse the root .gitignore file for better performance (i.e. avoids blaming excluded files) |`gitlens.advanced.maxQuickHistory`|Specifies the maximum number of QuickPick history entries to show |`gitlens.advanced.quickPick.closeOnFocusOut`|Specifies whether or not to close the QuickPick menu when focus is lost diff --git a/package-lock.json b/package-lock.json index 58ae935..e956bff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "integrity": "sha1-qjuL2ivlErGuCgV7lC6GnDcKVWk=", "dev": true, "requires": { - "@types/node": "8.0.34" + "@types/node": "8.0.41" } }, "@types/mocha": { @@ -26,9 +26,9 @@ "dev": true }, "@types/node": { - "version": "8.0.34", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.34.tgz", - "integrity": "sha512-Jnmm57+nHqvJUPwUzt1CLoLzFtF2B2vgG7cWFut+a4nqTp9/L6pL0N+o0Jt3V7AQnCKMsPEqQpLFZYleBCdq3w==", + "version": "8.0.41", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.41.tgz", + "integrity": "sha512-6XPVDfoTQE5O6FRCbSgFg0YEobbsqUuu6Wxnp7g3kydKTTQep/Mo3rT9CCS1igzQeAb1GLB7r3+xTgcHv+4KSQ==", "dev": true }, "@types/tmp": { @@ -861,12 +861,6 @@ "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=", "dev": true }, - "graceful-readlink": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz", - "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=", - "dev": true - }, "growl": { "version": "1.10.3", "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz", @@ -896,9 +890,9 @@ } }, "gulp-gunzip": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/gulp-gunzip/-/gulp-gunzip-0.0.3.tgz", - "integrity": "sha1-e24HsPWP09QlFcSOrVpj3wVy9i8=", + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/gulp-gunzip/-/gulp-gunzip-1.0.0.tgz", + "integrity": "sha1-FbdBFF6Dqcb1CIYkG1fMWHHxUak=", "dev": true, "requires": { "through2": "0.6.5", @@ -1113,68 +1107,59 @@ } }, "gulp-vinyl-zip": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/gulp-vinyl-zip/-/gulp-vinyl-zip-1.4.0.tgz", - "integrity": "sha1-VjgvLMtXIxuwR4x4c3zNVylzvuE=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/gulp-vinyl-zip/-/gulp-vinyl-zip-2.1.0.tgz", + "integrity": "sha1-JOQGhdwFtxSZlSRQmeBZAmO+ja0=", "dev": true, "requires": { "event-stream": "3.3.4", - "queue": "3.1.0", - "through2": "0.6.5", - "vinyl": "0.4.6", + "queue": "4.4.1", + "through2": "2.0.3", + "vinyl": "2.1.0", "vinyl-fs": "2.4.4", "yauzl": "2.8.0", "yazl": "2.4.2" }, "dependencies": { "clone": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/clone/-/clone-0.2.0.tgz", - "integrity": "sha1-xhJqkK1Pctv1rNskPMN3JP6T/B8=", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz", + "integrity": "sha1-0hfR6WERjjrJpLi7oyhVU79kfNs=", "dev": true }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "clone-stats": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-1.0.0.tgz", + "integrity": "sha1-s3gt/4u1R04Yuba/D9/ngvh3doA=", "dev": true }, - "readable-stream": { - "version": "1.0.34", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", - "integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", + "queue": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/queue/-/queue-4.4.1.tgz", + "integrity": "sha512-Lcs97MDk4ewesYBtC6P3hl+klvVmHN2PLzgsQcK29bVQ2+5T0Ef0ZmXhBIINkpJd3LzZK29MWjyTL2lGLYGOPA==", "dev": true, "requires": { - "core-util-is": "1.0.2", - "inherits": "2.0.3", - "isarray": "0.0.1", - "string_decoder": "0.10.31" + "inherits": "2.0.3" } }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", + "replace-ext": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz", + "integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs=", "dev": true }, - "through2": { - "version": "0.6.5", - "resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz", - "integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=", - "dev": true, - "requires": { - "readable-stream": "1.0.34", - "xtend": "4.0.1" - } - }, "vinyl": { - "version": "0.4.6", - "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-0.4.6.tgz", - "integrity": "sha1-LzVsh6VQolVGHza76ypbqL94SEc=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.1.0.tgz", + "integrity": "sha1-Ah+cLPlR1rk5lDyJ617lrdT9kkw=", "dev": true, "requires": { - "clone": "0.2.0", - "clone-stats": "0.0.1" + "clone": "2.1.1", + "clone-buffer": "1.0.0", + "clone-stats": "1.0.0", + "cloneable-readable": "1.0.0", + "remove-trailing-separator": "1.1.0", + "replace-ext": "1.0.0" } } } @@ -1281,11 +1266,6 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" }, - "ignore": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.5.tgz", - "integrity": "sha512-JLH93mL8amZQhh/p6mfQgVBH3M6epNq3DfsXsTSuSrInVjwyYlFE1nv2AgfRCC8PoOhM0jwQ5v8s9LgbK7yGDw==" - }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -1489,12 +1469,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "json3": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz", - "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=", - "dev": true - }, "jsonify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/jsonify/-/jsonify-0.0.0.tgz", @@ -1545,28 +1519,12 @@ "readable-stream": "2.3.3" } }, - "lodash._baseassign": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz", - "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=", - "dev": true, - "requires": { - "lodash._basecopy": "3.0.1", - "lodash.keys": "3.1.2" - } - }, "lodash._basecopy": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz", "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=", "dev": true }, - "lodash._basecreate": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz", - "integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=", - "dev": true - }, "lodash._basetostring": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz", @@ -1620,17 +1578,6 @@ "resolved": "https://registry.npmjs.org/lodash.assign/-/lodash.assign-4.2.0.tgz", "integrity": "sha1-DZnzzNem0mHRm9rrkkUAXShYCOc=" }, - "lodash.create": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz", - "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=", - "dev": true, - "requires": { - "lodash._baseassign": "3.2.0", - "lodash._basecreate": "3.0.3", - "lodash._isiterateecall": "3.0.9" - } - }, "lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", @@ -2350,18 +2297,18 @@ } }, "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "dev": true }, "source-map-support": { - "version": "0.4.18", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", - "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.0.tgz", + "integrity": "sha512-vUoN3I7fHQe0R/SJLKRdKYuEdRGogsviXFkHHo17AWaTGv17VLnxw+CFXvqy+y4ORZ3doWLQcxRYfwKrsd/H7Q==", "dev": true, "requires": { - "source-map": "0.5.7" + "source-map": "0.6.1" } }, "sparkles": { @@ -2814,108 +2761,25 @@ } }, "vscode": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/vscode/-/vscode-1.1.5.tgz", - "integrity": "sha1-EOsQQAGEDD3QgTgV/UoF+PyILRQ=", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/vscode/-/vscode-1.1.6.tgz", + "integrity": "sha1-Ru0a+iwbnWifY5TI8WvR1xkPdfs=", "dev": true, "requires": { "glob": "7.1.2", "gulp-chmod": "2.0.0", "gulp-filter": "5.0.1", - "gulp-gunzip": "0.0.3", + "gulp-gunzip": "1.0.0", "gulp-remote-src": "0.4.3", "gulp-symdest": "1.1.0", "gulp-untar": "0.0.6", - "gulp-vinyl-zip": "1.4.0", - "mocha": "3.5.3", + "gulp-vinyl-zip": "2.1.0", + "mocha": "4.0.1", "request": "2.83.0", "semver": "5.4.1", - "source-map-support": "0.4.18", + "source-map-support": "0.5.0", "url-parse": "1.1.9", "vinyl-source-stream": "1.1.0" - }, - "dependencies": { - "commander": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", - "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=", - "dev": true, - "requires": { - "graceful-readlink": "1.0.1" - } - }, - "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "diff": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", - "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", - "dev": true - }, - "growl": { - "version": "1.9.2", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz", - "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=", - "dev": true - }, - "has-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz", - "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=", - "dev": true - }, - "mocha": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.3.tgz", - "integrity": "sha512-/6na001MJWEtYxHOV1WLfsmR4YIynkUEhBwzsb+fk2qmQ3iqsi258l/Q2MWHJMImAcNpZ8DEdYAK72NHoIQ9Eg==", - "dev": true, - "requires": { - "browser-stdout": "1.3.0", - "commander": "2.9.0", - "debug": "2.6.8", - "diff": "3.2.0", - "escape-string-regexp": "1.0.5", - "glob": "7.1.1", - "growl": "1.9.2", - "he": "1.1.1", - "json3": "3.3.2", - "lodash.create": "3.1.1", - "mkdirp": "0.5.1", - "supports-color": "3.1.2" - }, - "dependencies": { - "glob": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz", - "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=", - "dev": true, - "requires": { - "fs.realpath": "1.0.0", - "inflight": "1.0.6", - "inherits": "2.0.3", - "minimatch": "3.0.4", - "once": "1.4.0", - "path-is-absolute": "1.0.1" - } - } - } - }, - "supports-color": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz", - "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=", - "dev": true, - "requires": { - "has-flag": "1.0.0" - } - } } }, "wrappy": { diff --git a/package.json b/package.json index c7fca5f..874d2bc 100644 --- a/package.json +++ b/package.json @@ -719,11 +719,6 @@ "default": null, "description": "Specifies the git path to use" }, - "gitlens.advanced.gitignore.enabled": { - "type": "boolean", - "default": true, - "description": "Specifies whether or not to parse the root .gitignore file for better performance (i.e. avoids blaming excluded files)" - }, "gitlens.advanced.maxQuickHistory": { "type": "number", "default": 200, @@ -2000,7 +1995,6 @@ "copy-paste": "1.3.0", "date-fns": "1.29.0", "iconv-lite": "0.4.19", - "ignore": "3.3.5", "lodash.debounce": "4.0.8", "lodash.escaperegexp": "4.1.2", "lodash.isequal": "4.5.0", @@ -2012,12 +2006,12 @@ "@types/copy-paste": "1.1.30", "@types/iconv-lite": "0.0.1", "@types/mocha": "2.2.43", - "@types/node": "8.0.34", + "@types/node": "8.0.41", "@types/tmp": "0.0.33", "husky": "^0.14.3", "mocha": "4.0.1", "tslint": "5.7.0", "typescript": "2.5.3", - "vscode": "1.1.5" + "vscode": "1.1.6" } } diff --git a/src/@types/ignore/index.d.ts b/src/@types/ignore/index.d.ts deleted file mode 100644 index 791415a..0000000 --- a/src/@types/ignore/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -declare module "ignore" { - namespace ignore { - interface Ignore { - add(patterns: string | Array | Ignore): Ignore; - filter(paths: Array): Array; - } - } - function ignore(): ignore.Ignore; - export = ignore; -} diff --git a/src/configuration.ts b/src/configuration.ts index e0687d6..6728ef5 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -58,9 +58,6 @@ export interface IAdvancedConfig { maxLines: number; }; git: string; - gitignore: { - enabled: boolean; - }; maxQuickHistory: number; menus: { explorerContext: { diff --git a/src/gitService.ts b/src/gitService.ts index c76679e..8b3ab26 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -8,7 +8,6 @@ import { Git, GitAuthor, GitBlame, GitBlameCommit, GitBlameLine, GitBlameLines, import { GitUri, IGitCommitInfo, IGitUriData } from './git/gitUri'; import { Logger } from './logger'; import * as fs from 'fs'; -import * as ignore from 'ignore'; import * as path from 'path'; export { GitUri, IGitCommitInfo }; @@ -21,14 +20,14 @@ export * from './git/gitContextTracker'; class UriCacheEntry { - constructor(public uri: GitUri) { } + constructor(public readonly uri: GitUri) { } } class GitCacheEntry { private cache: Map = new Map(); - constructor(public key: string) { } + constructor(public readonly key: string) { } get hasErrors(): boolean { return Iterables.every(this.cache.values(), _ => _.errorMessage !== undefined); @@ -98,11 +97,11 @@ export class GitService extends Disposable { private _gitCache: Map; private _remotesCache: Map; private _cacheDisposable: Disposable | undefined; - private _uriCache: Map; + private _trackedCache: Map; + private _versionedUriCache: Map; config: IConfig; private _disposable: Disposable | undefined; - private _gitignore: Promise; private _repoWatcher: FileSystemWatcher | undefined; static EmptyPromise: Promise = Promise.resolve(undefined); @@ -112,7 +111,8 @@ export class GitService extends Disposable { this._gitCache = new Map(); this._remotesCache = new Map(); - this._uriCache = new Map(); + this._trackedCache = new Map(); + this._versionedUriCache = new Map(); this._onConfigurationChanged(); @@ -136,7 +136,8 @@ export class GitService extends Disposable { this._gitCache.clear(); this._remotesCache.clear(); - this._uriCache.clear(); + this._trackedCache.clear(); + this._versionedUriCache.clear(); } public get UseCaching() { @@ -174,28 +175,6 @@ export class GitService extends Disposable { this._gitCache.clear(); } - - this._gitignore = new Promise((resolve, reject) => { - if (!cfg.advanced.gitignore.enabled) { - resolve(undefined); - return; - } - - const gitignorePath = path.join(this.repoPath, '.gitignore'); - fs.exists(gitignorePath, e => { - if (e) { - fs.readFile(gitignorePath, 'utf8', (err, data) => { - if (!err) { - resolve(ignore().add(data)); - return; - } - resolve(undefined); - }); - return; - } - resolve(undefined); - }); - }); } const ignoreWhitespace = this.config && this.config.blame.ignoreWhitespace; @@ -237,6 +216,7 @@ export class GitService extends Disposable { } this._gitCache.clear(); + this._trackedCache.clear(); this._fireRepoChange(); this._fireGitCacheChange(); @@ -431,17 +411,16 @@ export class GitService extends Disposable { } private async _getBlameForFile(uri: GitUri, entry: GitCacheEntry | undefined, key: string): Promise { - const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); - - const ignore = await this._gitignore; - if (ignore && !ignore.filter([file]).length) { - Logger.log(`Skipping blame; '${uri.fsPath}' is gitignored`); + if (!(await this.isTracked(uri))) { + Logger.log(`Skipping blame; '${uri.fsPath}' is not tracked`); if (entry && entry.key) { this._onDidBlameFail.fire(entry.key); } return await GitService.EmptyPromise as GitBlame; } + const [file, root] = Git.splitPath(uri.fsPath, uri.repoPath, false); + try { const data = await Git.blame(root, file, uri.sha, { ignoreWhitespace: this.config.blame.ignoreWhitespace }); const blame = GitBlameParser.parse(data, root, file); @@ -597,7 +576,7 @@ export class GitService extends Disposable { getGitUriForFile(uri: Uri) { const cacheKey = this.getCacheEntryKey(uri); - const entry = this._uriCache.get(cacheKey); + const entry = this._versionedUriCache.get(cacheKey); return entry && entry.uri; } @@ -832,14 +811,13 @@ export class GitService extends Disposable { } private async _getLogForFile(repoPath: string | undefined, fileName: string, sha: string | undefined, options: { maxCount?: number, range?: Range, reverse?: boolean, skipMerges?: boolean }, entry: GitCacheEntry | undefined, key: string): Promise { - const [file, root] = Git.splitPath(fileName, repoPath, false); - - const ignore = await this._gitignore; - if (ignore && !ignore.filter([file]).length) { - Logger.log(`Skipping log; '${fileName}' is gitignored`); + if (!(await this.isTracked(fileName, repoPath))) { + Logger.log(`Skipping log; '${fileName}' is not tracked`); return await GitService.EmptyPromise as GitLog; } + const [file, root] = Git.splitPath(fileName, repoPath, false); + try { const { range, ...opts } = options; const data = await Git.log_file(root, file, sha, { ...opts, ...{ startLine: range && range.start.line + 1, endLine: range && range.end.line + 1 } }); @@ -951,7 +929,7 @@ export class GitService extends Disposable { const cacheKey = this.getCacheEntryKey(file); const entry = new UriCacheEntry(new GitUri(Uri.file(fileName), { sha, repoPath: repoPath!, fileName })); - this._uriCache.set(cacheKey, entry); + this._versionedUriCache.set(cacheKey, entry); return file; } @@ -965,7 +943,7 @@ export class GitService extends Disposable { if (editor === undefined || editor.document === undefined || editor.document.uri === undefined) return false; const cacheKey = this.getCacheEntryKey(editor.document.uri); - return this._uriCache.has(cacheKey); + return this._versionedUriCache.has(cacheKey); } isEditorBlameable(editor: TextEditor): boolean { @@ -979,19 +957,47 @@ export class GitService extends Disposable { return !!status; } - isTrackable(uri: Uri): boolean { - // Logger.log(`isTrackable('${uri.scheme}', '${uri.fsPath}')`); + isTrackable(scheme: string): boolean; + isTrackable(uri: Uri): boolean; + isTrackable(schemeOruri: string | Uri): boolean { + let scheme: string; + if (typeof schemeOruri === 'string') { + scheme = schemeOruri; + } + else { + scheme = schemeOruri.scheme; + } - return uri.scheme === DocumentSchemes.File || uri.scheme === DocumentSchemes.Git || uri.scheme === DocumentSchemes.GitLensGit; + return scheme === DocumentSchemes.File || scheme === DocumentSchemes.Git || scheme === DocumentSchemes.GitLensGit; } - async isTracked(uri: GitUri): Promise { - if (!this.isTrackable(uri)) return false; + async isTracked(fileName: string, repoPath: string | undefined): Promise; + async isTracked(uri: GitUri): Promise; + async isTracked(fileNameOrUri: string | GitUri, repoPath?: string | undefined): Promise { + let cacheKey: string; + let fileName: string; + if (typeof fileNameOrUri === 'string') { + [fileName, repoPath] = Git.splitPath(fileNameOrUri, repoPath); + cacheKey = this.getCacheEntryKey(fileNameOrUri); + } + else { + if (!this.isTrackable(fileNameOrUri)) return false; + + fileName = fileNameOrUri.fsPath; + repoPath = fileNameOrUri.repoPath; + cacheKey = this.getCacheEntryKey(fileNameOrUri); + } + + Logger.log(`isTracked('${fileName}', '${repoPath}')`); + + let tracked = this._trackedCache.get(cacheKey); + if (tracked !== undefined) return tracked; - Logger.log(`isTracked('${uri.fsPath}', '${uri.repoPath}')`); + const result = await Git.ls_files(repoPath === undefined ? '' : repoPath, fileName); + tracked = !!result; + this._trackedCache.set(cacheKey, tracked); - const result = await Git.ls_files(uri.repoPath === undefined ? '' : uri.repoPath, uri.fsPath); - return !!result; + return tracked; } openDiffTool(repoPath: string, uri: Uri, staged: boolean) {