Package org.eclipse.jgit.util
Class Paths
java.lang.Object
org.eclipse.jgit.util.Paths
Utility functions for paths inside of a Git repository.
- Since:
- 4.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode) Compare two paths according to Git path sort ordering rules.static intcompareSameName(byte[] aPath, int aPos, int aEnd, byte[] bPath, int bPos, int bEnd, int bMode) Compare two paths, checking for identical name.private static intcoreCompare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode) private static intlastPathChar(int mode) static StringstripTrailingSeparator(String path) Remove trailing'/'if present.
-
Constructor Details
-
Paths
private Paths()
-
-
Method Details
-
stripTrailingSeparator
Remove trailing'/'if present.- Parameters:
path- input path to potentially remove trailing'/'from.- Returns:
- null if
path == null;pathafter removing a trailing'/'.
-
compare
public static int compare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode) Compare two paths according to Git path sort ordering rules.- Parameters:
aPath- first path buffer. The range[aPos, aEnd)is used.aPos- index intoaPathwhere the first path starts.aEnd- 1 past last index ofaPath.aMode- mode of the first file. Trees are sorted as thoughaPath[aEnd] == '/', even if aEnd does not exist.bPath- second path buffer. The range[bPos, bEnd)is used.bPos- index intobPathwhere the second path starts.bEnd- 1 past last index ofbPath.bMode- mode of the second file. Trees are sorted as thoughbPath[bEnd] == '/', even if bEnd does not exist.- Returns:
- <0 if
aPathsorts beforebPath; 0 if the paths are the same; >0 ifaPathsorts afterbPath.
-
compareSameName
public static int compareSameName(byte[] aPath, int aPos, int aEnd, byte[] bPath, int bPos, int bEnd, int bMode) Compare two paths, checking for identical name.Unlike
comparethis method returns0when the paths have the same characters in their names, even if the mode differs. It is intended for use in validation routines detecting duplicate entries.Returns
0if the names are identical and a conflict exists betweenaPathandbPath, as they share the same name.Returns
<0if all possibles occurrences ofaPathsort beforebPathand no conflict can happen. In a properly sorted tree there are no other occurrences ofaPathand therefore there are no duplicate names.Returns
>0when it is possible for a duplicate occurrence ofaPathto appear later, afterbPath. Callers should continue to examine candidates forbPathuntil the method returns one of the other return values.- Parameters:
aPath- first path buffer. The range[aPos, aEnd)is used.aPos- index intoaPathwhere the first path starts.aEnd- 1 past last index ofaPath.bPath- second path buffer. The range[bPos, bEnd)is used.bPos- index intobPathwhere the second path starts.bEnd- 1 past last index ofbPath.bMode- mode of the second file. Trees are sorted as thoughbPath[bEnd] == '/', even if bEnd does not exist.- Returns:
- <0 if no duplicate name could exist;
0 if the paths have the same name;
>0 other
bPathshould still be checked by caller.
-
coreCompare
private static int coreCompare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode) -
lastPathChar
private static int lastPathChar(int mode)
-