Package com.google.gerrit.server.update
Class ChainedReceiveCommands
- java.lang.Object
-
- com.google.gerrit.server.update.ChainedReceiveCommands
-
- All Implemented Interfaces:
RefCache
public class ChainedReceiveCommands extends Object implements RefCache
Collection ofReceiveCommand
s that supports multiple updates per ref.The underlying behavior of
BatchRefUpdate
is undefined (an implementations vary) when more than one command per ref is added. This class works around that limitation by allowing multiple updates per ref, as long as the previous new SHA-1 matches the next old SHA-1.
-
-
Constructor Summary
Constructors Constructor Description ChainedReceiveCommands(RepoRefCache refCache)
ChainedReceiveCommands(org.eclipse.jgit.lib.Repository repo)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(org.eclipse.jgit.transport.ReceiveCommand cmd)
Add a command.void
addTo(org.eclipse.jgit.lib.BatchRefUpdate bru)
Add commands from this instance to a native JGit batch update.void
close()
Closes this cache, releasing the references to any underlying resources.Optional<org.eclipse.jgit.lib.ObjectId>
get(String refName)
Get the latest value of a ref according to this sequence of commands.Map<String,org.eclipse.jgit.transport.ReceiveCommand>
getCommands()
Returns an unmodifiable view of commands.RepoRefCache
getRepoRefCache()
boolean
isEmpty()
-
-
-
Constructor Detail
-
ChainedReceiveCommands
public ChainedReceiveCommands(org.eclipse.jgit.lib.Repository repo)
-
ChainedReceiveCommands
public ChainedReceiveCommands(RepoRefCache refCache)
-
-
Method Detail
-
getRepoRefCache
public RepoRefCache getRepoRefCache()
-
isEmpty
public boolean isEmpty()
-
add
public void add(org.eclipse.jgit.transport.ReceiveCommand cmd)
Add a command.- Parameters:
cmd
- command to add. If a command has been previously added for the same ref, the new SHA-1 of the most recent previous command must match the old SHA-1 of this command.
-
get
public Optional<org.eclipse.jgit.lib.ObjectId> get(String refName) throws IOException
Get the latest value of a ref according to this sequence of commands.After the value for a ref is read from the repo once, it is cached as in
RepoRefCache
.- Specified by:
get
in interfaceRefCache
- Parameters:
refName
- name of the ref.- Returns:
- value of the ref; absent if the ref does not exist in the repo. Never null, and never
present with a value of
ObjectId.zeroId()
. - Throws:
IOException
- See Also:
RefCache.get(String)
-
addTo
public void addTo(org.eclipse.jgit.lib.BatchRefUpdate bru)
Add commands from this instance to a native JGit batch update.Exactly one command per ref will be added to the update. The old SHA-1 will be the old SHA-1 of the first command added to this instance for that ref; the new SHA-1 will be the new SHA-1 of the last command.
- Parameters:
bru
- batch update
-
getCommands
public Map<String,org.eclipse.jgit.transport.ReceiveCommand> getCommands()
Returns an unmodifiable view of commands.
-
-