mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Update repository status to use new task style
This commit is contained in:
committed by
probablycorey
parent
7dd52995d0
commit
8280b3a3ff
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user