Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2020-12-30 18:45:42 +0000
committerThomas Wolf2020-12-30 18:45:42 +0000
commite7a09e095b99cb380d9e569fda9e8c5e248fb06d (patch)
treea44810bf35a82536a14806d2d22bed6925bedd6f /org.eclipse.egit.ui
parentd4207273102d4c65e6742c86e8b0fd2c5778ccca (diff)
downloadegit-e7a09e095b99cb380d9e569fda9e8c5e248fb06d.tar.gz
egit-e7a09e095b99cb380d9e569fda9e8c5e248fb06d.tar.xz
egit-e7a09e095b99cb380d9e569fda9e8c5e248fb06d.zip
Fix order of files in DiffEditorOutlinePage
The outline of the DiffEditor sorted files differently than they appeared in the DiffDocument, and also differently than in the CommitFileDiffViewer or in the staging view. Use the same comparator as elsewhere to get consistent sorting. Change-Id: I21e1c3e906b9889c676bc2f94832946240987fa0 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java3
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java28
2 files changed, 17 insertions, 14 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
index c887c575a6..55fae2890b 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commit/DiffEditorOutlinePage.java
@@ -25,7 +25,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.egit.core.internal.Utils;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIUtils;
-import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.commit.DiffRegionFormatter.FileDiffRegion;
@@ -114,7 +113,7 @@ public class DiffEditorOutlinePage extends ContentOutlinePage {
viewer.setContentProvider(new DiffContentProvider());
viewer.setLabelProvider(new DiffLabelProvider());
viewer.setComparator(
- new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR) {
+ new ViewerComparator(FileDiff.PATH_STRING_COMPARATOR) {
@Override
public int category(Object element) {
if (element instanceof DiffContentProvider.Folder) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
index d3960f771b..f9a2f131de 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/FileDiff.java
@@ -62,25 +62,29 @@ import org.eclipse.jgit.util.LfsFactory;
public class FileDiff {
/**
- * Comparator for sorting FileDiffs based on getPath(). Compares first the
- * directory part, if those are equal, the filename part.
+ * Comparator for sorting git paths. Compares first the directory part, if
+ * those are equal, the filename part.
*/
- public static final Comparator<FileDiff> PATH_COMPARATOR = //
+ public static final Comparator<String> PATH_STRING_COMPARATOR = //
(left, right) -> {
- String leftPath = left.getPath();
- String rightPath = right.getPath();
- int i = leftPath.lastIndexOf('/');
- int j = rightPath.lastIndexOf('/');
- int p = leftPath.substring(0, i + 1).replace('/', '\001')
- .compareTo(rightPath.substring(0, j + 1).replace('/',
- '\001'));
+ int i = left.lastIndexOf('/') + 1;
+ int j = right.lastIndexOf('/') + 1;
+ int p = left.substring(0, i).replace('/', '\001')
+ .compareTo(right.substring(0, j).replace('/', '\001'));
if (p != 0) {
return p;
}
- return leftPath.substring(i + 1).compareToIgnoreCase(
- rightPath.substring(j + 1));
+ return left.substring(i)
+ .compareToIgnoreCase(right.substring(j));
};
+ /**
+ * Comparator for sorting FileDiffs based on getPath(). Compares first the
+ * directory part, if those are equal, the filename part.
+ */
+ public static final Comparator<FileDiff> PATH_COMPARATOR = Comparator
+ .comparing(FileDiff::getPath, PATH_STRING_COMPARATOR);
+
private final RevCommit commit;
private final RevCommit base;

Back to the top