[git] IDEA-78347 Show full history only for git 1.9+

For some reason --full-history --simplify-merges doesn't work well
for older gits i.e. still shows a lot of senseless merge commits in
the file history.
This commit is contained in:
Kirill Likhodedov
2015-03-22 17:19:13 +03:00
parent 00e4d9bbaf
commit 5b77fc61eb
2 changed files with 26 additions and 7 deletions
@@ -133,6 +133,13 @@ public enum GitVersionSpecialty {
public boolean existsIn(@NotNull GitVersion version) {
return version.isOlderOrEqual(new GitVersion(1, 7, 2, 0));
}
},
FULL_HISTORY_SIMPLIFY_MERGES_WORKS_CORRECTLY { // for some reason, even with "simplify-merges", it used to show a lot of merges in history
@Override
public boolean existsIn(@NotNull GitVersion version) {
return version.isLaterOrEqual(new GitVersion(1, 9, 0, 0));
}
};
public abstract boolean existsIn(@NotNull GitVersion version);
@@ -43,6 +43,7 @@ import com.intellij.vcs.log.util.StopWatch;
import git4idea.*;
import git4idea.branch.GitBranchUtil;
import git4idea.commands.*;
import git4idea.config.GitVersion;
import git4idea.config.GitVersionSpecialty;
import git4idea.history.browser.GitHeavyCommit;
import git4idea.history.browser.SHAHash;
@@ -285,9 +286,11 @@ public class GitHistoryUtils {
}
};
GitVcs vcs = GitVcs.getInstance(project);
GitVersion version = vcs != null ? vcs.getVersion() : GitVersion.NULL;
final AtomicBoolean criticalFailure = new AtomicBoolean();
while (currentPath.get() != null && firstCommitParent.get() != null) {
logHandler.set(getLogHandler(project, finalRoot, logParser, currentPath.get(), firstCommitParent.get(), parameters));
logHandler.set(getLogHandler(project, version, finalRoot, logParser, currentPath.get(), firstCommitParent.get(), parameters));
final MyTokenAccumulator accumulator = new MyTokenAccumulator(logParser);
final Semaphore semaphore = new Semaphore();
@@ -339,7 +342,7 @@ public class GitHistoryUtils {
try {
Pair<String, FilePath> firstCommitParentAndPath = getFirstCommitParentAndPathIfRename(project, finalRoot, firstCommit.get(),
currentPath.get());
currentPath.get(), version);
currentPath.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.second);
firstCommitParent.set(firstCommitParentAndPath == null ? null : firstCommitParentAndPath.first);
skipFurtherOutput.set(false);
@@ -353,10 +356,19 @@ public class GitHistoryUtils {
}
private static GitLineHandler getLogHandler(Project project, VirtualFile root, GitLogParser parser, FilePath path, String lastCommit, String... parameters) {
private static GitLineHandler getLogHandler(Project project,
@NotNull GitVersion version,
VirtualFile root,
GitLogParser parser,
FilePath path,
String lastCommit,
String... parameters) {
final GitLineHandler h = new GitLineHandler(project, root, GitCommand.LOG);
h.setStdoutSuppressed(true);
h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8", "--full-history", "--simplify-merges", lastCommit);
h.addParameters("--name-status", parser.getPretty(), "--encoding=UTF-8", lastCommit);
if (GitVersionSpecialty.FULL_HISTORY_SIMPLIFY_MERGES_WORKS_CORRECTLY.existsIn(version)) {
h.addParameters("--full-history", "--simplify-merges");
}
if (parameters != null && parameters.length > 0) {
h.addParameters(parameters);
}
@@ -374,15 +386,15 @@ public class GitHistoryUtils {
private static Pair<String, FilePath> getFirstCommitParentAndPathIfRename(Project project,
VirtualFile root,
String commit,
FilePath filePath) throws VcsException {
FilePath filePath,
@NotNull GitVersion version) throws VcsException {
// 'git show -M --name-status <commit hash>' returns the information about commit and detects renames.
// NB: we can't specify the filepath, because then rename detection will work only with the '--follow' option, which we don't wanna use.
final GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
final GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, COMMIT_TIME, PARENTS);
h.setStdoutSuppressed(true);
h.addParameters("-M", "--name-status", parser.getPretty(), "--encoding=UTF-8", commit);
GitVcs vcs = GitVcs.getInstance(project);
if (vcs != null && !GitVersionSpecialty.FOLLOW_IS_BUGGY_IN_THE_LOG.existsIn(vcs.getVersion())) {
if (!GitVersionSpecialty.FOLLOW_IS_BUGGY_IN_THE_LOG.existsIn(version)) {
h.addParameters("--follow");
h.endOptions();
h.addRelativePaths(filePath);