Class RepositoryService

java.lang.Object
io.github.jbastgen.stemma.app.git.RepositoryService
All Implemented Interfaces:
AutoCloseable

public final class RepositoryService extends Object implements AutoCloseable
Application service through which the UI uses the Git backend. All work runs on virtual threads, never on the JavaFX thread, and operations on the same repository are executed one after the other: a push cannot overlap with a commit, and a reload sees a consistent state.
  • Field Details

  • Constructor Details

  • Method Details

    • backend

      public io.github.jbastgen.stemma.git.api.GitBackend backend()
      The Git implementation in use.
    • setBackend

      public void setBackend(io.github.jbastgen.stemma.git.api.GitBackend backend)
      Switches the Git implementation; takes effect for the next operation.
    • load

      public RepositorySnapshot load(Path directory)
      Loads a snapshot synchronously. Never call this on the JavaFX application thread.
    • loadAsync

      public CompletableFuture<RepositorySnapshot> loadAsync(Path directory)
      Loads a snapshot on a virtual thread. Completes exceptionally with a GitException on failure.
    • summaryAsync

      public CompletableFuture<RepositorySnapshot> summaryAsync(Path directory)
      Loads just enough for a library card: branch, changes, last commit, remotes and ahead/behind. Much cheaper than loadAsync(java.nio.file.Path), so a library of many repositories opens quickly.
    • submit

      public <T> CompletableFuture<T> submit(Path directory, Function<io.github.jbastgen.stemma.git.api.GitRepository,T> operation)
      Runs operation on the repository in directory on a virtual thread, after earlier operations on the same repository have finished. The repository is opened for the operation and closed afterwards. The future fails with the GitException thrown by the operation.
    • commitDetails

      public CompletableFuture<io.github.jbastgen.stemma.git.api.CommitDetails> commitDetails(Path directory, String commitId)
      Reads the details of a commit: message body and changed files.
    • diff

      public CompletableFuture<io.github.jbastgen.stemma.git.api.FileDiff> diff(Path directory, io.github.jbastgen.stemma.git.api.DiffTarget target, String path)
      Reads the diff of one file.
    • initAsync

      public CompletableFuture<RepositorySnapshot> initAsync(Path directory, String initialBranch)
      Creates a repository and returns its snapshot.
    • initAsync

      public CompletableFuture<RepositorySnapshot> initAsync(Path directory, String initialBranch, boolean gitFlow)
      Creates a repository and returns its snapshot.
      Parameters:
      gitFlow - also set Git Flow up: initialBranch is the production branch, it gets an empty first commit, develop is created from it and checked out
    • cloneAsync

      public CompletableFuture<RepositorySnapshot> cloneAsync(String url, Path directory)
      Clones a repository and returns its snapshot.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable