Package org.eclipse.jgit.util
Class Paths
- java.lang.Object
-
- org.eclipse.jgit.util.Paths
-
public final class Paths extends Object
Utility functions for paths inside of a Git repository.- Since:
- 4.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static int
compareSameName(byte[] aPath, int aPos, int aEnd, byte[] bPath, int bPos, int bEnd, int bMode)
Compare two paths, checking for identical name.static boolean
isEqualOrPrefix(String folder, String path)
Determines whether a git pathfolder
is a prefix of another git pathpath
, or the same aspath
.static String
stripTrailingSeparator(String path)
Remove trailing'/'
if present.
-
-
-
Method Detail
-
stripTrailingSeparator
public static String stripTrailingSeparator(String path)
Remove trailing'/'
if present.- Parameters:
path
- input path to potentially remove trailing'/'
from.- Returns:
- null if
path == null
;path
after removing a trailing'/'
.
-
isEqualOrPrefix
public static boolean isEqualOrPrefix(String folder, String path)
Determines whether a git pathfolder
is a prefix of another git pathpath
, or the same aspath
. An emptyfolder
is not not considered a prefix and matches only ifpath
is also empty.- Parameters:
folder
- a git path for a directory, without trailing slashpath
- a git path- Returns:
true
iffolder
is a directory prefix ofpath
, or is equal topath
,false
otherwise- Since:
- 6.3
-
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 intoaPath
where 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 intobPath
where 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
aPath
sorts beforebPath
; 0 if the paths are the same; >0 ifaPath
sorts 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
compare
this method returns0
when 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
0
if the names are identical and a conflict exists betweenaPath
andbPath
, as they share the same name.Returns
<0
if all possibles occurrences ofaPath
sort beforebPath
and no conflict can happen. In a properly sorted tree there are no other occurrences ofaPath
and therefore there are no duplicate names.Returns
>0
when it is possible for a duplicate occurrence ofaPath
to appear later, afterbPath
. Callers should continue to examine candidates forbPath
until the method returns one of the other return values.- Parameters:
aPath
- first path buffer. The range[aPos, aEnd)
is used.aPos
- index intoaPath
where the first path starts.aEnd
- 1 past last index ofaPath
.bPath
- second path buffer. The range[bPos, bEnd)
is used.bPos
- index intobPath
where 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
bPath
should still be checked by caller.
-
-