mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Only compute Git status flags once
Previously the status was fetched twice, once for if modified and once for if new. Now the flags are fetched once and Git now provides helpers to check the status flags directly for modified and new status.
This commit is contained in:
@@ -36,19 +36,25 @@ class Git
|
||||
isPathIgnored: (path) ->
|
||||
@repo.isIgnored(@relativize(path))
|
||||
|
||||
isPathModified: (path) ->
|
||||
isStatusModified: (status) ->
|
||||
modifiedFlags = @statusFlags.working_dir_modified |
|
||||
@statusFlags.working_dir_delete |
|
||||
@statusFlags.working_dir_typechange |
|
||||
@statusFlags.index_modified |
|
||||
@statusFlags.index_deleted |
|
||||
@statusFlags.index_typechange
|
||||
(@getPathStatus(path) & modifiedFlags) > 0
|
||||
(status & modifiedFlags) > 0
|
||||
|
||||
isPathNew: (path) ->
|
||||
isPathModified: (path) ->
|
||||
@isStatusModified(@getPathStatus(path))
|
||||
|
||||
isStatusNew: (status) ->
|
||||
newFlags = @statusFlags.working_dir_new |
|
||||
@statusFlags.index_new
|
||||
(@getPathStatus(path) & newFlags) > 0
|
||||
(status & newFlags) > 0
|
||||
|
||||
isPathNew: (path) ->
|
||||
@isStatusNew(@getPathStatus(path))
|
||||
|
||||
relativize: (path) ->
|
||||
workingDirectory = @getWorkingDirectory()
|
||||
|
||||
@@ -76,7 +76,10 @@ class StatusBar extends View
|
||||
|
||||
@gitStatusIcon.addClass('git-status octicons')
|
||||
git = @buffer.getRepo()
|
||||
if git?.isPathModified(path)
|
||||
return unless git
|
||||
|
||||
status = git.getPathStatus(path)
|
||||
if git.isStatusModified(status)
|
||||
@gitStatusIcon.addClass('modified-status-icon')
|
||||
stats = git.getDiffStats(path)
|
||||
if stats.added and stats.deleted
|
||||
@@ -87,7 +90,7 @@ class StatusBar extends View
|
||||
@gitStatusIcon.text("-#{stats.deleted}")
|
||||
else
|
||||
@gitStatusIcon.text('')
|
||||
else if git?.isPathNew(path)
|
||||
else if git.isStatusNew(status)
|
||||
@gitStatusIcon.addClass('new-status-icon')
|
||||
@gitStatusIcon.text("+#{@buffer.getLineCount()}")
|
||||
|
||||
|
||||
@@ -36,10 +36,12 @@ class FileView extends View
|
||||
path = @getPath()
|
||||
if repo.isPathIgnored(path)
|
||||
@addClass('ignored')
|
||||
else if repo.isPathModified(path)
|
||||
@addClass('modified')
|
||||
else if repo.isPathNew(path)
|
||||
@addClass('new')
|
||||
else
|
||||
status = repo.getPathStatus(path)
|
||||
if repo.isStatusModified(status)
|
||||
@addClass('modified')
|
||||
else if repo.isStatusNew(status)
|
||||
@addClass('new')
|
||||
|
||||
getPath: ->
|
||||
@file.path
|
||||
|
||||
Reference in New Issue
Block a user