Class GitBlobIndex

java.lang.Object
network.ike.docs.plugin.registry.GitBlobIndex

public final class GitBlobIndex extends Object
Read a BlobIndex from git without opening a file (dev-adoc-packages, IKE-Network/ike-issues#1341). One call, git ls-files -s, lists every tracked path with the blob id of its content as the index holds it. The working tree may differ from the index, so git status is asked for what moved since: every path it names that still exists is hashed on the spot with git hash-object, which costs the same as the parse it causes, and every path it names that is gone is dropped. Untracked and ignored files are included and hashed too, so the index covers exactly the files the full scan would read. Renames are not asked for; a rename is a drop and an add here, and the registry re-keys it by blob.

Nothing here needs the tree to be committed, or clean. A tree that is not inside a git repository, or a machine without git on the path, gives Optional.empty(), and the caller falls back to BlobIndex.hashed(Path).

Since:
136
  • Method Details

    • read

      public static Optional<BlobIndex> read(Path root) throws IOException
      Index the .adoc files under a root from git.
      Parameters:
      root - the registry root, inside a git working tree
      Returns:
      the index, or empty when the root is not in a git working tree or git cannot be run
      Throws:
      IOException - if git runs but fails, or its output cannot be read