From f71c0cbf680643a6943f4b8f4ca3f9195c9b3bb4 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Fri, 22 Mar 2019 21:51:42 +0300 Subject: [PATCH] [git] remove usages of GitLogUtil.collectFullDetails and deprecate the method --- .../changes/GitCommittedChangeListProvider.java | 2 +- .../src/git4idea/history/GitHistoryUtils.java | 16 +++++++++++++++- .../src/git4idea/history/GitLogUtil.java | 4 ++++ .../update/GitRebaseOverMergeProblem.java | 3 ++- .../tests/git4idea/history/GitLogUtilTest.kt | 8 ++++---- .../tests/git4idea/revert/GitRevertTest.kt | 3 ++- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java index cf61e11ebba0..2108012a9d7f 100644 --- a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java +++ b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeListProvider.java @@ -204,7 +204,7 @@ public class GitCommittedChangeListProvider implements CommittedChangesProvider< GitVcs gitVcs = GitVcs.getInstance(project); String[] hashParameters = GitHistoryUtils.formHashParameters(gitVcs, Collections.singleton(number.asString())); - List gitCommits = GitLogUtil.collectFullDetails(project, root, hashParameters); + List gitCommits = GitHistoryUtils.history(project, root, hashParameters); if (gitCommits.size() != 1) return null; return gitCommits.get(0); diff --git a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java index a7e04ed7de58..63c333e941b5 100644 --- a/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java +++ b/plugins/git4idea/src/git4idea/history/GitHistoryUtils.java @@ -1,6 +1,7 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package git4idea.history; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Pair; @@ -38,6 +39,8 @@ import static git4idea.history.GitLogParser.GitLogOption.*; * A collection of methods for retrieving history information from native Git. */ public class GitHistoryUtils { + private static final Logger LOG = Logger.getInstance(GitHistoryUtils.class); + private GitHistoryUtils() { } @@ -135,7 +138,18 @@ public class GitHistoryUtils { if (factory == null) { return Collections.emptyList(); } - return GitLogUtil.collectFullDetails(project, root, parameters); + + List commits = ContainerUtil.newArrayList(); + try { + GitLogUtil.readFullDetails(project, root, commits::add, true, true, false, parameters); + } + catch (VcsException e) { + if (commits.isEmpty()) { + throw e; + } + LOG.warn("Error during loading details, returning partially loaded commits\n", e); + } + return commits; } /** diff --git a/plugins/git4idea/src/git4idea/history/GitLogUtil.java b/plugins/git4idea/src/git4idea/history/GitLogUtil.java index 82619dd8aa6b..59bf7cb90a40 100644 --- a/plugins/git4idea/src/git4idea/history/GitLogUtil.java +++ b/plugins/git4idea/src/git4idea/history/GitLogUtil.java @@ -225,6 +225,10 @@ public class GitLogUtil { return ContainerUtil.map(record.getParentsHashes(), factory::createHash); } + /** + * @deprecated use {@link GitHistoryUtils#history(Project, VirtualFile, String...)} instead. + */ + @Deprecated @NotNull public static List collectFullDetails(@NotNull Project project, @NotNull VirtualFile root, diff --git a/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java b/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java index 72d5e6b257db..42c9f83ef223 100644 --- a/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java +++ b/plugins/git4idea/src/git4idea/update/GitRebaseOverMergeProblem.java @@ -27,6 +27,7 @@ import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import git4idea.DialogManager; import git4idea.GitCommit; +import git4idea.history.GitHistoryUtils; import git4idea.history.GitLogUtil; import one.util.streamex.StreamEx; import org.jetbrains.annotations.NotNull; @@ -76,7 +77,7 @@ public class GitRebaseOverMergeProblem { @NotNull String currentRef) { String range = baseRef + ".." + currentRef; try { - List commits = GitLogUtil.collectFullDetails(project, root, range, "--merges"); + List commits = GitHistoryUtils.history(project, root, range, "--merges"); return StreamEx.of(commits).anyMatch(commit -> !commit.getChanges().isEmpty()); } catch (VcsException e) { diff --git a/plugins/git4idea/tests/git4idea/history/GitLogUtilTest.kt b/plugins/git4idea/tests/git4idea/history/GitLogUtilTest.kt index 67cbc1425cc7..5ebd4e355cd4 100644 --- a/plugins/git4idea/tests/git4idea/history/GitLogUtilTest.kt +++ b/plugins/git4idea/tests/git4idea/history/GitLogUtilTest.kt @@ -4,6 +4,7 @@ package git4idea.history import com.intellij.openapi.vcs.Executor.echo import com.intellij.openapi.vcs.Executor.touch import com.intellij.util.CollectConsumer +import com.intellij.util.Consumer import com.intellij.util.containers.ContainerUtil import com.intellij.vcs.log.VcsFullCommitDetails import git4idea.GitCommit @@ -47,10 +48,9 @@ class GitLogUtilTest : GitSingleRepoTest() { } expected.reverse() - val actualHashes = ContainerUtil.map(GitLogUtil.collectFullDetails(myProject, repo.root, - "--max-count=$commitCount") - ) { detail -> detail.id.asString() } - + val actualHashes = mutableListOf() + GitLogUtil.readFullDetails(project, repo.root, Consumer { actualHashes.add(it.id.asString()) }, + true, true, false, "--max-count=$commitCount") assertEquals(expected, actualHashes) } diff --git a/plugins/git4idea/tests/git4idea/revert/GitRevertTest.kt b/plugins/git4idea/tests/git4idea/revert/GitRevertTest.kt index ad202879b29d..c17d316ef516 100644 --- a/plugins/git4idea/tests/git4idea/revert/GitRevertTest.kt +++ b/plugins/git4idea/tests/git4idea/revert/GitRevertTest.kt @@ -21,6 +21,7 @@ import com.intellij.vcs.log.util.VcsLogUtil import com.intellij.vcsUtil.VcsUtil.getFilePath import git4idea.GitContentRevision.createRevision import git4idea.GitRevisionNumber +import git4idea.history.GitHistoryUtils import git4idea.history.GitLogUtil import git4idea.test.* import java.nio.charset.Charset @@ -214,7 +215,7 @@ class GitRevertTest : GitSingleRepoTest() { fun `test reverting commit doesn't preserve authorship of the original commit`() { file("a.txt").create("initial\n").add() git("commit --author='Original Author ' -m original_commit") - val commit = GitLogUtil.collectFullDetails(project, projectRoot, "-1").first() + val commit = GitHistoryUtils.history(project, projectRoot, "-1").first() vcsHelper.onCommit { false }