From 3d2ed074707cc3e8983850e5cdf2a108ddceabf1 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Mon, 9 Nov 2015 16:56:51 +0100 Subject: [PATCH] Revert "Use our own ::relativize" This reverts commit 0322d8d3dada0334edba74768ce4b54725ca7757. --- src/git-repository-async.js | 105 +++++------------------------------- 1 file changed, 13 insertions(+), 92 deletions(-) diff --git a/src/git-repository-async.js b/src/git-repository-async.js index 532c89292..48fedc888 100644 --- a/src/git-repository-async.js +++ b/src/git-repository-async.js @@ -9,6 +9,11 @@ const newStatusFlags = Git.Status.STATUS.WT_NEW | Git.Status.STATUS.INDEX_NEW const deletedStatusFlags = Git.Status.STATUS.WT_DELETED | Git.Status.STATUS.INDEX_DELETED const indexStatusFlags = Git.Status.STATUS.INDEX_NEW | Git.Status.STATUS.INDEX_MODIFIED | Git.Status.STATUS.INDEX_DELETED | Git.Status.STATUS.INDEX_RENAMED | Git.Status.STATUS.INDEX_TYPECHANGE +// Temporary requires +// ================== +// GitUtils is temporarily used for ::relativize only, because I don't want +// to port it just yet. TODO: remove +const GitUtils = require('git-utils') // Just using this for _.isEqual and _.object, we should impl our own here const _ = require('underscore-plus') @@ -27,6 +32,7 @@ module.exports = class GitRepositoryAsync { this.emitter = new Emitter() this.subscriptions = new CompositeDisposable() this.pathStatusCache = {} + this._gitUtilsRepo = GitUtils.open(path) // TODO remove after porting ::relativize this.repoPromise = Git.Repository.open(path) let {project, refreshOnWindowFocus} = options @@ -90,7 +96,7 @@ module.exports = class GitRepositoryAsync { checkoutHead (_path) { return this.repoPromise.then((repo) => { let checkoutOptions = new Git.CheckoutOptions() - checkoutOptions.paths = [this.relativize(_path, repo.workdir())] + checkoutOptions.paths = [this._gitUtilsRepo.relativize(_path)] checkoutOptions.checkoutStrategy = Git.Checkout.STRATEGY.FORCE | Git.Checkout.STRATEGY.DISABLE_PATHSPEC_MATCH return Git.Checkout.head(repo, checkoutOptions) }).then(() => { @@ -114,32 +120,20 @@ module.exports = class GitRepositoryAsync { }) } - // Returns a Promise that resolves to the status bit of a given path if it has - // one, otherwise 'current'. // Returns a Promise that resolves to the status bit of a given path if it has // one, otherwise 'current'. getPathStatus (_path) { - let relativePath + let relativePath = this._gitUtilsRepo.relativize(_path) return this.repoPromise.then((repo) => { - relativePath = this.relativize(_path, repo.workdir()) return this._filterStatusesByPath(_path) - }).then(statuses => { + }).then((statuses) => { let cachedStatus = this.pathStatusCache[relativePath] || 0 let status = statuses[0] ? statuses[0].statusBit() : Git.Status.STATUS.CURRENT - - if (status > 0) { - this.pathStatusCache[relativePath] = status - } else { - delete this.pathStatusCache[relativePath] - } - if (status !== cachedStatus) { this.emitter.emit('did-change-status', {path: _path, pathStatus: status}) } - + this.pathStatusCache[relativePath] = status return status - }).catch(e => { - console.trace(e) }) } @@ -151,9 +145,10 @@ module.exports = class GitRepositoryAsync { // {::isStatusModified} or {::isStatusNew} to get more information. getDirectoryStatus (directoryPath) { + let relativePath = this._gitUtilsRepo.relativize(directoryPath) // XXX _filterSBD already gets repoPromise return this.repoPromise.then((repo) => { - return this._filterStatusesByDirectory(this.relativize(directoryPath, repo.workdir())) + return this._filterStatusesByDirectory(relativePath) }).then((statuses) => { return Promise.all(statuses.map(function (s) { return s.statusBit() })).then(function (bits) { let directoryStatus = 0 @@ -194,78 +189,6 @@ module.exports = class GitRepositoryAsync { // Section: Private // ================ - relativizeAsync (_path) { - this.repoPromise.then((repo) => { - return this.relativize(_path, repo.workdir()) - }) - } - - relativize (_path, workingDirectory) { - if (!Boolean(workingDirectory)) { - workingDirectory = this.getWorkingDirectorySync() // TODO - } - // Cargo-culted from git-utils. Could use a refactor maybe. Short circuits everywhere! - if (!_path) { - return _path - } - - if (process.platform === 'win32') { - _path = _path.replace(/\\/g, '/') - } else { - if (_path[0] !== '/') { - return _path - } - } - - if (this.isCaseInsensitive) { - let lowerCasePath = _path.toLowerCase() - - if (workingDirectory) { - workingDirectory = workingDirectory.toLowerCase() - if (lowerCasePath.indexOf(`${workingDirectory}/`) === 0) { - return _path.substring(workingDirectory.length + 1) - } else { - if (lowerCasePath === workingDirectory) { - return '' - } - } - } - - if (this.openedWorkingDirectory) { - workingDirectory = this.openedWorkingDirectory.toLowerCase() - if (lowerCasePath.indexOf(`${workingDirectory}/`) === 0) { - return _path.substring(workingDirectory.length + 1) - } else { - if (lowerCasePath === workingDirectory) { - return '' - } - } - } - } else { - workingDirectory = this.getWorkingDirectory() // TODO - if (workingDirectory) { - if (_path.indexOf(`${workingDirectory}/`) === 0) { - return _path.substring(workingDirectory.length + 1) - } else { - if (_path === workingDirectory) { - return '' - } - } - } - - if (this.openedWorkingDirectory) { - if (_path.indexOf(`${this.openedWorkingDirectory}/`) === 0) { - return _path.substring(this.openedWorkingDirectory.length + 1) - } else { - if (_path === this.openedWorkingDirectory) { - return '' - } - } - } - } - return _path - } - subscribeToBuffer (buffer) { let bufferSubscriptions = new CompositeDisposable() @@ -293,9 +216,7 @@ module.exports = class GitRepositoryAsync { } getCachedPathStatus (_path) { - return this.repoPromise.then((repo) => { - return this.pathStatusCache[this.relativize(_path, repo.workdir())] - }) + return this.pathStatusCache[this._gitUtilsRepo.relativize(_path)] } isStatusNew (statusBit) {