From 409bf22ffd2d1f247ef1eb69c5bdba598c5f0fd6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Thu, 23 Mar 2017 13:00:41 +0000 Subject: [PATCH] Update Git repository info synchronously after fetch GitRepositoryFiles.refresh() refreshes the VFS, which generate VFS events, which are handled by GitRepositoryUpdater, which _schedules_ the real update(). So even if the VFS refresh is synchronous, actual update of the repo info happens later. It is important to update repository info immediately after fetch, since this information is used in e.g. GitUpdateProcess. But we don't want both refresh() and update(), because it will cause reading .git twice. Thus introducing a separate method to refresh information which is not covered by update(). The remaining refresh() method doesn't need the "async" parameter anymore, since it is async at any case. --- .../src/git4idea/branch/GitBranchWorker.java | 2 +- .../src/git4idea/repo/GitRepositoryFiles.java | 20 +++++++++++++++++-- .../src/git4idea/ui/GitTagDialog.java | 2 +- .../src/git4idea/update/GitFetcher.java | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/plugins/git4idea/src/git4idea/branch/GitBranchWorker.java b/plugins/git4idea/src/git4idea/branch/GitBranchWorker.java index 2d6676b941be..d33261eeb2ac 100644 --- a/plugins/git4idea/src/git4idea/branch/GitBranchWorker.java +++ b/plugins/git4idea/src/git4idea/branch/GitBranchWorker.java @@ -84,7 +84,7 @@ public final class GitBranchWorker { public void createNewTag(@NotNull final String name, @NotNull final String reference, @NotNull final List repositories) { for (GitRepository repository : repositories) { myGit.createNewTag(repository, name, null, reference); - repository.getRepositoryFiles().refresh(false); + repository.getRepositoryFiles().refresh(); } } diff --git a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java index 017d47c2889c..0b7d62f4b6de 100644 --- a/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java +++ b/plugins/git4idea/src/git4idea/repo/GitRepositoryFiles.java @@ -308,8 +308,24 @@ public class GitRepositoryFiles { return path.equals(myExcludePath); } - public void refresh(boolean async) { - VfsUtil.markDirtyAndRefresh(async, true, false, myMainDir, myWorktreeDir); + /** + * Refresh all .git repository files asynchronously and recursively. + * + * @see #refreshNonTrackedData() if you need the "main" data (branches, HEAD, etc.) to be updated synchronously. + */ + public void refresh() { + VfsUtil.markDirtyAndRefresh(true, true, false, myMainDir, myWorktreeDir); + } + + /** + * Refresh that part of .git repository files, which is not covered by {@link GitRepository#update()}, e.g. the {@code refs/tags/} dir. + * + * The call to this method should be probably be done together with a call to update(): thus all information will be updated, + * but some of it will be updated synchronously, the rest - asynchronously. + */ + public void refreshNonTrackedData() { + VirtualFile tagsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(myRefsTagsPath); + VfsUtil.markDirtyAndRefresh(true, true, false, tagsDir); } @NotNull diff --git a/plugins/git4idea/src/git4idea/ui/GitTagDialog.java b/plugins/git4idea/src/git4idea/ui/GitTagDialog.java index 441f3b5216d6..2572a7704b41 100644 --- a/plugins/git4idea/src/git4idea/ui/GitTagDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitTagDialog.java @@ -214,7 +214,7 @@ public class GitTagDialog extends DialogWrapper { GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(getGitRoot()); if (repository != null) { - repository.getRepositoryFiles().refresh(true); + repository.getRepositoryFiles().refresh(); } else { LOG.error("No repository registered for root: " + getGitRoot()); diff --git a/plugins/git4idea/src/git4idea/update/GitFetcher.java b/plugins/git4idea/src/git4idea/update/GitFetcher.java index 131cfbdbbc24..a684f760c4a0 100644 --- a/plugins/git4idea/src/git4idea/update/GitFetcher.java +++ b/plugins/git4idea/src/git4idea/update/GitFetcher.java @@ -81,7 +81,8 @@ public class GitFetcher { public GitFetchResult fetch(@NotNull GitRepository repository) { // TODO need to have a fair compound result here GitFetchResult fetchResult = myFetchAll ? fetchAll(repository) : fetchCurrentRemote(repository); - repository.getRepositoryFiles().refresh(false); + repository.update(); + repository.getRepositoryFiles().refreshNonTrackedData(); return fetchResult; }