From 8280b3a3ff3877a6f10fa63620f45a221c0d9219 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 13 Jun 2013 17:27:43 -0700 Subject: [PATCH] Update repository status to use new task style --- spec/app/git-spec.coffee | 19 ----------------- src/app/git.coffee | 19 +++++++---------- src/app/repository-status-handler.coffee | 27 ++++++++++++------------ src/app/repository-status-task.coffee | 18 ---------------- 4 files changed, 21 insertions(+), 62 deletions(-) delete mode 100644 src/app/repository-status-task.coffee diff --git a/spec/app/git-spec.coffee b/spec/app/git-spec.coffee index 811020694..5dccad3ae 100644 --- a/spec/app/git-spec.coffee +++ b/spec/app/git-spec.coffee @@ -204,22 +204,3 @@ describe "Git", -> expect(statuses[cleanPath]).toBeUndefined() expect(repo.isStatusNew(statuses[newPath])).toBeTruthy() expect(repo.isStatusModified(statuses[modifiedPath])).toBeTruthy() - - it "only starts a single task at a time and schedules a restart if one is already running", => - fsUtils.writeSync(modifiedPath, 'making this path modified') - statusHandler = jasmine.createSpy('statusHandler') - repo.on 'statuses-changed', statusHandler - - spyOn(Task.prototype, "start").andCallThrough() - repo.refreshStatus() - expect(Task.prototype.start.callCount).toBe 1 - repo.refreshStatus() - expect(Task.prototype.start.callCount).toBe 1 - repo.refreshStatus() - expect(Task.prototype.start.callCount).toBe 1 - - waitsFor -> - statusHandler.callCount > 0 - - runs -> - expect(Task.prototype.start.callCount).toBe 2 diff --git a/src/app/git.coffee b/src/app/git.coffee index 4352c76d8..0704cb5a7 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -2,7 +2,7 @@ _ = require 'underscore' fsUtils = require 'fs-utils' Subscriber = require 'subscriber' EventEmitter = require 'event-emitter' -RepositoryStatusTask = require 'repository-status-task' +Task = require 'task' GitUtils = require 'git-utils' # Public: Represents the underlying git operations performed by Atom. @@ -14,6 +14,7 @@ class Git statuses: null upstream: null statusTask: null + task: null ### Internal ### @@ -29,6 +30,7 @@ class Git @statuses = {} @upstream = {ahead: 0, behind: 0} + @task = new Task('repository-status-handler') refreshOnWindowFocus = options.refreshOnWindowFocus ? true if refreshOnWindowFocus @@ -217,16 +219,11 @@ class Git ### Internal ### refreshStatus: -> - if @statusTask? - @statusTask.off() - @statusTask.one 'task:completed', => - @statusTask = null - @refreshStatus() - else - @statusTask = new RepositoryStatusTask(this) - @statusTask.one 'task:completed', => - @statusTask = null - @statusTask.start() + @task.start @getPath(), ({statuses, upstream}) => + statusesUnchanged = _.isEqual(statuses, @statuses) and _.isEqual(upstream, @upstream) + @statuses = statuses + @upstream = upstream + @trigger 'statuses-changed' unless statusesUnchanged _.extend Git.prototype, Subscriber _.extend Git.prototype, EventEmitter diff --git a/src/app/repository-status-handler.coffee b/src/app/repository-status-handler.coffee index 663fa43dc..355a18e46 100644 --- a/src/app/repository-status-handler.coffee +++ b/src/app/repository-status-handler.coffee @@ -2,18 +2,17 @@ Git = require 'git-utils' fsUtils = require 'fs-utils' path = require 'path' -module.exports = - loadStatuses: (repoPath) -> - repo = Git.open(repoPath) - if repo? - workingDirectoryPath = repo.getWorkingDirectory() - statuses = {} - for filePath, status of repo.getStatus() - statuses[path.join(workingDirectoryPath, filePath)] = status - upstream = repo.getAheadBehindCount() - repo.release() - else - upstream = {} - statuses = {} +module.exports = (repoPath) -> + repo = Git.open(repoPath) + if repo? + workingDirectoryPath = repo.getWorkingDirectory() + statuses = {} + for filePath, status of repo.getStatus() + statuses[path.join(workingDirectoryPath, filePath)] = status + upstream = repo.getAheadBehindCount() + repo.release() + else + upstream = {} + statuses = {} - callTaskMethod('statusesLoaded', {statuses, upstream}) + {statuses, upstream} diff --git a/src/app/repository-status-task.coffee b/src/app/repository-status-task.coffee deleted file mode 100644 index 1056a1337..000000000 --- a/src/app/repository-status-task.coffee +++ /dev/null @@ -1,18 +0,0 @@ -Task = require 'task' -_ = require 'underscore' - -### Internal ### -module.exports = -class RepositoryStatusTask extends Task - constructor: (@repo) -> - super('repository-status-handler') - - started: -> - @callWorkerMethod('loadStatuses', @repo.getPath()) - - statusesLoaded: ({statuses, upstream}) -> - @done() - statusesUnchanged = _.isEqual(statuses, @repo.statuses) and _.isEqual(upstream, @repo.upstream) - @repo.statuses = statuses - @repo.upstream = upstream - @repo.trigger 'statuses-changed' unless statusesUnchanged