Sort email comment groups

In changes involving C++, *.h files should appear before their
corresponding *.cc file, although their lexicographic order is the
reverse. With this change, the relative order of *.h and *.cpp file
pairs in file groups of change comment emails is corrected.

Bug: Issue 4586
Change-Id: Ic9618a07167bde570bdfeb0ea54721c763034863
This commit is contained in:
Wyatt Allen
2016-09-28 11:41:47 -07:00
parent 25afcccd2e
commit 6964572185
5 changed files with 138 additions and 33 deletions

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.client.info;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.common.data.FilenameComparator;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
@@ -30,7 +31,6 @@ public class FileInfo extends JavaScriptObject {
public final native boolean binary() /*-{ return this.binary || false; }-*/;
public final native String status() /*-{ return this.status; }-*/;
// JSNI methods cannot have 'long' as a parameter type or a return type and
// it's suggested to use double in this case:
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#important
@@ -48,37 +48,8 @@ public class FileInfo extends JavaScriptObject {
public final native void _row(int r) /*-{ this._row = r }-*/;
public static void sortFileInfoByPath(JsArray<FileInfo> list) {
Collections.sort(Natives.asList(list), new Comparator<FileInfo>() {
@Override
public int compare(FileInfo a, FileInfo b) {
if (Patch.COMMIT_MSG.equals(a.path())) {
return -1;
} else if (Patch.COMMIT_MSG.equals(b.path())) {
return 1;
}
if (Patch.MERGE_LIST.equals(a.path())) {
return -1;
} else if (Patch.MERGE_LIST.equals(b.path())) {
return 1;
}
// Look at file suffixes to check if it makes sense to use a different order
int s1 = a.path().lastIndexOf('.');
int s2 = b.path().lastIndexOf('.');
if (s1 > 0 && s2 > 0 &&
a.path().substring(0, s1).equals(b.path().substring(0, s2))) {
String suffixA = a.path().substring(s1);
String suffixB = b.path().substring(s2);
// C++ and C: give priority to header files (.h/.hpp/...)
if (suffixA.indexOf(".h") == 0) {
return -1;
} else if (suffixB.indexOf(".h") == 0) {
return 1;
}
}
return a.path().compareTo(b.path());
}
});
Collections.sort(Natives.asList(list),
Comparator.comparing(FileInfo::path, FilenameComparator.INSTANCE));
}
public static String getFileName(String path) {