Top Description Constructors Methods
org.eclipse.jgit.util

public final Class Paths

extends Object
Class Inheritance
Static Imports
org.eclipse.jgit.lib.FileMode.TYPE_MASK, .FileMode.TYPE_TREE

Utility functions for paths inside of a Git repository.
Since
4.2

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

<0 if aPath sorts before bPath; 0 if the paths are the same; >0 if aPath sorts after bPath.
compare
(byte[]
first path buffer. The range [aPos, aEnd) is used.
aPath
,
int
index into aPath where the first path starts.
aPos
,
int
1 past last index of aPath.
aEnd
,
int
mode of the first file. Trees are sorted as though aPath[aEnd] == '/', even if aEnd does not exist.
aMode
,
byte[]
second path buffer. The range [bPos, bEnd) is used.
bPath
,
int
index into bPath where the second path starts.
bPos
,
int
1 past last index of bPath.
bEnd
,
int
mode of the second file. Trees are sorted as though bPath[bEnd] == '/', even if bEnd does not exist.
bMode
)

Compare two paths according to Git path sort ordering rules.

public static int

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.
compareSameName
(byte[]
first path buffer. The range [aPos, aEnd) is used.
aPath
,
int
index into aPath where the first path starts.
aPos
,
int
1 past last index of aPath.
aEnd
,
byte[]
second path buffer. The range [bPos, bEnd) is used.
bPath
,
int
index into bPath where the second path starts.
bPos
,
int
1 past last index of bPath.
bEnd
,
int
mode of the second file. Trees are sorted as though bPath[bEnd] == '/', even if bEnd does not exist.
bMode
)

Compare two paths, checking for identical name.

private static int
coreCompare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode)

public static boolean

Returns:

true if folder is a directory prefix of path, or is equal to path, false otherwise
isEqualOrPrefix
(String
a git path for a directory, without trailing slash
folder
,
String
a git path
path
)

Determines whether a git path folder is a prefix of another git path path, or the same as path.

private static int
lastPathChar(int mode)

public static String

Returns:

null if path == null; path after removing a trailing '/'.
stripTrailingSeparator
(String
input path to potentially remove trailing '/' from.
path
)

Remove trailing '/' if present.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Pathsback to summary
private Paths()

Method Detail

compareback to summary
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:byte[]

first path buffer. The range [aPos, aEnd) is used.

aPos:int

index into aPath where the first path starts.

aEnd:int

1 past last index of aPath.

aMode:int

mode of the first file. Trees are sorted as though aPath[aEnd] == '/', even if aEnd does not exist.

bPath:byte[]

second path buffer. The range [bPos, bEnd) is used.

bPos:int

index into bPath where the second path starts.

bEnd:int

1 past last index of bPath.

bMode:int

mode of the second file. Trees are sorted as though bPath[bEnd] == '/', even if bEnd does not exist.

Returns:int

<0 if aPath sorts before bPath; 0 if the paths are the same; >0 if aPath sorts after bPath.

compareSameNameback to summary
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 returns 0 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 between aPath and bPath, as they share the same name.

Returns <0 if all possibles occurrences of aPath sort before bPath and no conflict can happen. In a properly sorted tree there are no other occurrences of aPath and therefore there are no duplicate names.

Returns >0 when it is possible for a duplicate occurrence of aPath to appear later, after bPath. Callers should continue to examine candidates for bPath until the method returns one of the other return values.

Parameters
aPath:byte[]

first path buffer. The range [aPos, aEnd) is used.

aPos:int

index into aPath where the first path starts.

aEnd:int

1 past last index of aPath.

bPath:byte[]

second path buffer. The range [bPos, bEnd) is used.

bPos:int

index into bPath where the second path starts.

bEnd:int

1 past last index of bPath.

bMode:int

mode of the second file. Trees are sorted as though bPath[bEnd] == '/', even if bEnd does not exist.

Returns:int

<0 if no duplicate name could exist; 0 if the paths have the same name; >0 other bPath should still be checked by caller.

coreCompareback to summary
private static int coreCompare(byte[] aPath, int aPos, int aEnd, int aMode, byte[] bPath, int bPos, int bEnd, int bMode)
isEqualOrPrefixback to summary
public static boolean isEqualOrPrefix(String folder, String path)

Determines whether a git path folder is a prefix of another git path path, or the same as path. An empty folder is not not considered a prefix and matches only if path is also empty.

Parameters
folder:String

a git path for a directory, without trailing slash

path:String

a git path

Returns:boolean

true if folder is a directory prefix of path, or is equal to path, false otherwise

Since
6.3
lastPathCharback to summary
private static int lastPathChar(int mode)
stripTrailingSeparatorback to summary
public static String stripTrailingSeparator(String path)

Remove trailing '/' if present.

Parameters
path:String

input path to potentially remove trailing '/' from.

Returns:String

null if path == null; path after removing a trailing '/'.