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.
This commit is contained in:
Kirill Likhodedov
2017-03-25 22:05:39 +00:00
parent d940fea566
commit 409bf22ffd
4 changed files with 22 additions and 5 deletions
@@ -84,7 +84,7 @@ public final class GitBranchWorker {
public void createNewTag(@NotNull final String name, @NotNull final String reference, @NotNull final List<GitRepository> repositories) {
for (GitRepository repository : repositories) {
myGit.createNewTag(repository, name, null, reference);
repository.getRepositoryFiles().refresh(false);
repository.getRepositoryFiles().refresh();
}
}
@@ -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
@@ -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());
@@ -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;
}