[diff] DiffRequestFactory.getTitle accepts nulls

This commit is contained in:
Julia Beliaeva
2017-04-14 14:31:35 +03:00
parent 50284989b6
commit 5de57ee32d
2 changed files with 13 additions and 20 deletions
@@ -45,6 +45,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.intellij.util.ObjectUtils.chooseNotNull;
public class DiffRequestFactoryImpl extends DiffRequestFactory {
private final DiffContentFactoryEx myContentFactory = DiffContentFactoryEx.getInstanceEx();
@@ -127,7 +129,13 @@ public class DiffRequestFactoryImpl extends DiffRequestFactory {
}
@NotNull
public static String getTitle(@NotNull FilePath path1, @NotNull FilePath path2, @NotNull String separator) {
public static String getTitle(@Nullable FilePath path1, @Nullable FilePath path2, @NotNull String separator) {
assert path1 != null || path2 != null;
if (path1 == null || path2 == null) {
return getContentTitle(chooseNotNull(path1, path2));
}
if ((path1.isDirectory() || path2.isDirectory()) && path1.getPath().equals(path2.getPath())) {
return path1.getPresentableUrl();
}
@@ -17,7 +17,6 @@ package git4idea.log;
import com.intellij.diff.DiffContentFactoryEx;
import com.intellij.diff.DiffManager;
import com.intellij.diff.DiffRequestFactoryImpl;
import com.intellij.diff.contents.DiffContent;
import com.intellij.diff.contents.EmptyContent;
import com.intellij.diff.requests.DiffRequest;
@@ -51,10 +50,9 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Collections;
import java.util.Objects;
import static com.intellij.diff.DiffRequestFactoryImpl.getTitle;
import static com.intellij.util.ObjectUtils.chooseNotNull;
import static com.intellij.util.ObjectUtils.notNull;
public class GitLogDiffHandler implements VcsLogDiffHandler {
private static final Logger LOG = Logger.getInstance(GitLogDiffHandler.class);
@@ -84,7 +82,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler {
DiffContent leftDiffContent = createDiffContent(root, leftPath, leftHash);
DiffContent rightDiffContent = createDiffContent(root, rightPath, rightHash);
return new SimpleDiffRequest(getTitle(leftPath, rightPath),
return new SimpleDiffRequest(getTitle(leftPath, rightPath, " -> "),
leftDiffContent, rightDiffContent,
leftHash.asString(), rightHash.asString());
}
@@ -110,7 +108,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler {
LOG.assertTrue(file != null);
DiffContent rightDiffContent = myDiffContentFactory.create(myProject, file);
return new SimpleDiffRequest(getTitle(revisionPath, localPath),
return new SimpleDiffRequest(getTitle(revisionPath, localPath, " -> "),
leftDiffContent, rightDiffContent,
revisionHash.asString(), "(Local)");
}
@@ -131,7 +129,7 @@ public class GitLogDiffHandler implements VcsLogDiffHandler {
" and " +
(rightRevision == null ? "current revision" : rightRevision.asString()) +
" in " +
getTitle(directoryPath, directoryPath);
getTitle(directoryPath, directoryPath, " -> ");
VcsDiffUtil.showChangesDialog(myProject, dialogTitle, ContainerUtil.newArrayList(diff));
}, "Calculating Diff for " + directoryPath.getName());
}
@@ -202,17 +200,4 @@ public class GitLogDiffHandler implements VcsLogDiffHandler {
return diffContent;
}
@NotNull
private static String getTitle(@Nullable FilePath leftPath, @Nullable FilePath rightPath) {
LOG.assertTrue(leftPath != null || rightPath != null);
if (Objects.equals(rightPath, leftPath)) {
return DiffRequestFactoryImpl.getContentTitle(notNull(leftPath));
}
if (leftPath == null || rightPath == null) {
return DiffRequestFactoryImpl.getContentTitle(chooseNotNull(leftPath, rightPath));
}
return DiffRequestFactoryImpl.getTitle(leftPath, rightPath, " -> ");
}
}