Git: Updating list of branches on external event.

This commit is contained in:
Kirill Likhodedov
2011-08-04 18:07:41 +04:00
parent 4e7e73d7bf
commit c1f9afce84
2 changed files with 23 additions and 1 deletions
@@ -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
*/
@@ -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);
}
});
}
}
}