From f5344080f15b373b7957022e2db14926bdcc6c72 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Jan 2013 17:35:54 -0800 Subject: [PATCH] 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. --- src/app/git.coffee | 14 ++++++++++---- src/packages/status-bar/src/status-bar.coffee | 7 +++++-- src/packages/tree-view/src/file-view.coffee | 10 ++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/app/git.coffee b/src/app/git.coffee index 4cab4bb2b..ea2dc1a0f 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -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() diff --git a/src/packages/status-bar/src/status-bar.coffee b/src/packages/status-bar/src/status-bar.coffee index 841a0bce5..a43302b25 100644 --- a/src/packages/status-bar/src/status-bar.coffee +++ b/src/packages/status-bar/src/status-bar.coffee @@ -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()}") diff --git a/src/packages/tree-view/src/file-view.coffee b/src/packages/tree-view/src/file-view.coffee index c0c7db492..ea75356da 100644 --- a/src/packages/tree-view/src/file-view.coffee +++ b/src/packages/tree-view/src/file-view.coffee @@ -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