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

    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 path folder is a prefix of another git path path, or the same as path.
    static String
    Remove trailing '/' if present.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • 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 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 - a git path for a directory, without trailing slash
      path - a git path
      Returns:
      true if folder is a directory prefix of path, or is equal to path, 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 into aPath where the first path starts.
      aEnd - 1 past last index of aPath.
      aMode - mode of the first file. Trees are sorted as though aPath[aEnd] == '/', even if aEnd does not exist.
      bPath - second path buffer. The range [bPos, bEnd) is used.
      bPos - index into bPath where the second path starts.
      bEnd - 1 past last index of bPath.
      bMode - mode of the second file. Trees are sorted as though bPath[bEnd] == '/', even if bEnd does not exist.
      Returns:
      <0 if aPath sorts before bPath; 0 if the paths are the same; >0 if aPath sorts after bPath.
    • 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 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 - first path buffer. The range [aPos, aEnd) is used.
      aPos - index into aPath where the first path starts.
      aEnd - 1 past last index of aPath.
      bPath - second path buffer. The range [bPos, bEnd) is used.
      bPos - index into bPath where the second path starts.
      bEnd - 1 past last index of bPath.
      bMode - mode of the second file. Trees are sorted as though bPath[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.