From c1f9afce84786e47e191985bf34a9bdaa5dffeb8 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 4 Aug 2011 18:05:45 +0400 Subject: [PATCH] Git: Updating list of branches on external event. --- .../src/git4idea/repo/GitRepositoryFiles.java | 9 +++++++++ .../src/git4idea/repo/GitRepositoryUpdater.java | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java index aef9f937fafd..806133e6733a 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java @@ -34,6 +34,7 @@ public class GitRepositoryFiles { private final String myRebaseMergePath; private final String myPackedRefsPath; private final String myRefsHeadsDirPath; + private final String myRefsRemotesDirPath; public static GitRepositoryFiles getInstance(@NotNull VirtualFile root) { // maybe will be cached later to store a single GitRepositoryFiles for a root. @@ -58,6 +59,7 @@ public class GitRepositoryFiles { myRebaseMergePath = gitDirPath + "/rebase-merge"; myPackedRefsPath = gitDirPath + "/packed-refs"; myRefsHeadsDirPath = gitDirPath + "/refs/heads"; + myRefsRemotesDirPath = gitDirPath + "/refs/remotes"; } /** @@ -81,6 +83,13 @@ public class GitRepositoryFiles { return filePath.startsWith(myRefsHeadsDirPath); } + /** + * Any file in .git/refs/remotes, i.e. a remote branch reference file. + */ + public boolean isRemoteBranchFile(String filePath) { + return filePath.startsWith(myRefsRemotesDirPath); + } + /** * .git/rebase-merge or .git/rebase-apply */ diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java index da0352da4e91..9852cac2fce4 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryUpdater.java @@ -69,7 +69,7 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener { String filePath = GitFileUtils.stripFileProtocolPrefix(file.getPath()); if (myRepositoryFiles.isHeadFile(filePath)) { headChanged = true; - } else if (myRepositoryFiles.isBranchFile(filePath)) { + } else if (myRepositoryFiles.isBranchFile(filePath) || myRepositoryFiles.isRemoteBranchFile(filePath)) { branchFileChanged = true; } else if (myRepositoryFiles.isPackedRefs(filePath)) { packedRefsChanged = true; @@ -84,6 +84,7 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener { boolean updateCurrentBranch = false; boolean updateCurrentRevision = false; boolean updateState = false; + boolean updateBranches = false; if (headChanged) { updateCurrentBranch = true; updateCurrentRevision = true; @@ -91,10 +92,15 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener { } if (branchFileChanged) { updateCurrentRevision = true; + updateBranches = true; } if (rebaseFileChanged || mergeFileChanged) { updateState = true; } + if (packedRefsChanged) { + updateCurrentBranch = true; + updateBranches = true; + } // update GitRepository on pooled thread, because it requires reading from disk and parsing data. if (updateCurrentBranch) { @@ -118,6 +124,13 @@ final class GitRepositoryUpdater implements Disposable, BulkFileListener { } }); } + if (updateBranches) { + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + public void run() { + myRepository.update(GitRepository.TrackedTopic.BRANCHES); + } + }); + } } }