From 146ae9d776c7f3cbeba7930a8614ca672e97bc32 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Jan 2013 17:29:20 -0800 Subject: [PATCH] Refresh the Git index when the window gains focus Closes #121 --- native/v8_extensions/git.js | 2 ++ native/v8_extensions/git.mm | 21 ++++++++++++++------- src/app/git.coffee | 5 +++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/native/v8_extensions/git.js b/native/v8_extensions/git.js index a3f772682..1f32038d3 100644 --- a/native/v8_extensions/git.js +++ b/native/v8_extensions/git.js @@ -9,6 +9,7 @@ var $git = {}; native function checkoutHead(path); native function getDiffStats(path); native function isSubmodule(path); + native function refreshIndex(); function GitRepository(path) { var repo = getRepository(path); @@ -24,5 +25,6 @@ var $git = {}; GitRepository.prototype.checkoutHead = checkoutHead; GitRepository.prototype.getDiffStats = getDiffStats; GitRepository.prototype.isSubmodule = isSubmodule; + GitRepository.prototype.refreshIndex = refreshIndex; this.GitRepository = GitRepository; })(); diff --git a/native/v8_extensions/git.mm b/native/v8_extensions/git.mm index c68f23a49..095404d77 100644 --- a/native/v8_extensions/git.mm +++ b/native/v8_extensions/git.mm @@ -69,12 +69,6 @@ public: return CefV8Value::CreateInt(0); } - git_index* index; - if (git_repository_index(&index, repo) == GIT_OK) { - git_index_read(index); - git_index_free(index); - } - unsigned int status = 0; if (git_status_file(&status, repo, path) == GIT_OK) { return CefV8Value::CreateInt(status); @@ -192,7 +186,6 @@ public: BOOL isSubmodule = false; git_index* index; if (git_repository_index(&index, repo) == GIT_OK) { - git_index_read(index); const git_index_entry *entry = git_index_get_bypath(index, path, 0); isSubmodule = entry != NULL && (entry->mode & S_IFMT) == GIT_FILEMODE_COMMIT; git_index_free(index); @@ -201,6 +194,14 @@ public: return CefV8Value::CreateBool(isSubmodule); } + void RefreshIndex() { + git_index* index; + if (exists && git_repository_index(&index, repo) == GIT_OK) { + git_index_read(index); + git_index_free(index); + } + } + IMPLEMENT_REFCOUNTING(GitRepository); }; @@ -264,6 +265,12 @@ bool Git::Execute(const CefString& name, return true; } + if (name == "refreshIndex") { + GitRepository *userData = (GitRepository *)object->GetUserData().get(); + userData->RefreshIndex(); + return true; + } + return false; } diff --git a/src/app/git.coffee b/src/app/git.coffee index 44c69a135..4cab4bb2b 100644 --- a/src/app/git.coffee +++ b/src/app/git.coffee @@ -1,3 +1,5 @@ +$ = require 'jquery' + module.exports = class Git @@ -15,6 +17,9 @@ class Git constructor: (path) -> @repo = new GitRepository(path) + $(window).on 'focus', => @refreshIndex() + + refreshIndex: -> @repo.refreshIndex() getPath: -> @repo.getPath()