Class RepoView
- java.lang.Object
-
- com.google.gerrit.server.update.RepoView
-
public class RepoView extends Object
Restricted view of aRepository
for use byBatchUpdateOp
implementations.This class serves two purposes in the context of
BatchUpdate
. First, the subset of normal Repository functionality is purely read-only, which prevents implementors from modifying the repository outside ofRepoOnlyOp.updateRepo(com.google.gerrit.server.update.RepoContext)
. Write operations can only be performed by calling methods onRepoContext
.Second, the read methods take into account any pending operations on the repository that implementations have staged using the write methods on
RepoContext
. Callers do not have to worry about whether operations have been performed yet.
-
-
Constructor Summary
Constructors Constructor Description RepoView(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectInserter inserter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.eclipse.jgit.lib.Config
getConfig()
Get this repo's configuration.Optional<org.eclipse.jgit.lib.ObjectId>
getRef(String name)
Read a single ref from the repo.Map<String,org.eclipse.jgit.lib.ObjectId>
getRefs(String prefix)
Look up refs by prefix.org.eclipse.jgit.revwalk.RevWalk
getRevWalk()
Get an open revwalk on the repo.
-
-
-
Method Detail
-
getConfig
public org.eclipse.jgit.lib.Config getConfig()
Get this repo's configuration.This is the storage-level config you would get with
Repository.getConfig()
, not, for example, the Gerrit-level project config.- Returns:
- a defensive copy of the config; modifications have no effect on the underlying config.
-
getRevWalk
public org.eclipse.jgit.revwalk.RevWalk getRevWalk()
Get an open revwalk on the repo.Guaranteed to be able to read back any objects inserted in the repository via
RepoContext.getInserter()
, even if objects have not been flushed to the underlying repo. In particular this includes any object returned bygetRef(String)
, even taking into account not-yet-executed commands.- Returns:
- revwalk.
-
getRef
public Optional<org.eclipse.jgit.lib.ObjectId> getRef(String name) throws IOException
Read a single ref from the repo.Takes into account any ref update commands added during the course of the update using
RepoContext.addRefUpdate(org.eclipse.jgit.transport.ReceiveCommand)
, even if they have not yet been executed on the underlying repo.The results of individual ref lookups are cached: calling this method multiple times with the same ref name will return the same result (unless a command was added in the meantime). The repo is not reread.
- Parameters:
name
- exact ref name.- Returns:
- the value of the ref, if present.
- Throws:
IOException
- if an error occurred.
-
getRefs
public Map<String,org.eclipse.jgit.lib.ObjectId> getRefs(String prefix) throws IOException
Look up refs by prefix.Takes into account any ref update commands added during the course of the update using
RepoContext.addRefUpdate(org.eclipse.jgit.transport.ReceiveCommand)
, even if they have not yet been executed on the underlying repo.For any ref that has previously been accessed with
getRef(String)
, the value in the result map will be that same cached value. Any refs that have not been previously accessed are re-scanned from the repo on each call.- Parameters:
prefix
- ref prefix; must end in '/' or else be empty.- Returns:
- a map of ref suffixes to SHA-1s. The refs are all under
prefix
and have the prefix stripped. - Throws:
IOException
- if an error occurred.
-
-