public class BatchRefUpdate
extends java.lang.Object
The batch update is primarily useful in the transport code, where a client or server is making changes to more than one reference at a time.
Modifier and Type | Field and Description |
---|---|
private boolean |
allowNonFastForwards
Does the caller permit a forced update on a reference?
|
private boolean |
atomic
Whether updates should be atomic.
|
private java.util.List<ReceiveCommand> |
commands
Commands to apply during this batch.
|
private boolean |
forceRefLog
Should reflogs be written even if the configured default for this ref is
not to write it.
|
protected static java.time.Duration |
MAX_WAIT
Maximum delay the calling thread will tolerate while waiting for a
MonotonicClock to resolve associated ProposedTimestamp s. |
private PushCertificate |
pushCert
Push certificate associated with this update.
|
private java.util.List<java.lang.String> |
pushOptions
Push options associated with this update.
|
private RefDatabase |
refdb |
private PersonIdent |
refLogIdent
Identity to record action as within the reflog.
|
private boolean |
refLogIncludeResult
Should the result value be appended to
refLogMessage . |
private java.lang.String |
refLogMessage
Message the caller wants included in the reflog.
|
private java.util.List<ProposedTimestamp> |
timestamps
Associated timestamps that should be blocked on before update.
|
Modifier | Constructor and Description |
---|---|
protected |
BatchRefUpdate(RefDatabase refdb)
Initialize a new batch update.
|
Modifier and Type | Method and Description |
---|---|
BatchRefUpdate |
addCommand(java.util.Collection<ReceiveCommand> cmd)
Add commands to this batch update.
|
BatchRefUpdate |
addCommand(ReceiveCommand... cmd)
Add commands to this batch update.
|
BatchRefUpdate |
addCommand(ReceiveCommand cmd)
Add a single command to this batch update.
|
protected static void |
addPrefixesTo(java.lang.String name,
java.util.Collection<java.lang.String> out)
Add prefixes of a ref name to an existing collection.
|
BatchRefUpdate |
addProposedTimestamp(ProposedTimestamp ts)
Request the batch to wait for the affected timestamps to resolve.
|
protected boolean |
blockUntilTimestamps(java.time.Duration maxWait)
Wait for timestamps to be in the past, aborting commands on timeout.
|
BatchRefUpdate |
disableRefLog()
Don't record this update in the ref's associated reflog.
|
void |
execute(RevWalk walk,
ProgressMonitor monitor)
Execute this batch update without option strings.
|
void |
execute(RevWalk walk,
ProgressMonitor monitor,
java.util.List<java.lang.String> options)
Execute this batch update.
|
java.util.List<ReceiveCommand> |
getCommands()
Get commands this update will process.
|
protected static java.util.Collection<java.lang.String> |
getPrefixes(java.lang.String name)
Get all path prefixes of a ref name.
|
java.util.List<ProposedTimestamp> |
getProposedTimestamps()
Get list of timestamps the batch must wait for.
|
protected PushCertificate |
getPushCertificate()
Set the push certificate associated with this update.
|
java.util.List<java.lang.String> |
getPushOptions()
Gets the list of option strings associated with this update.
|
PersonIdent |
getRefLogIdent()
Get identity of the user making the change in the reflog.
|
java.lang.String |
getRefLogMessage()
Get the message to include in the reflog.
|
protected java.lang.String |
getRefLogMessage(ReceiveCommand cmd)
Get reflog message for a command.
|
private static java.util.Collection<java.lang.String> |
getTakenPrefixes(java.util.Collection<java.lang.String> names) |
boolean |
isAllowNonFastForwards()
Whether the batch update will permit a non-fast-forward update to an
existing reference.
|
boolean |
isAtomic()
Whether updates should be atomic.
|
protected boolean |
isForceRefLog()
Check whether the reflog should be written regardless of repo defaults.
|
protected boolean |
isForceRefLog(ReceiveCommand cmd)
Check whether the reflog for a command should be written regardless of repo
defaults.
|
private static boolean |
isMissing(RevWalk walk,
ObjectId id) |
boolean |
isRefLogDisabled()
Check whether log has been disabled by
disableRefLog() . |
protected boolean |
isRefLogDisabled(ReceiveCommand cmd)
Check whether reflog is disabled for a command.
|
boolean |
isRefLogIncludingResult()
Check whether the reflog message should include the result of the update,
such as fast-forward or force-update.
|
protected boolean |
isRefLogIncludingResult(ReceiveCommand cmd)
Check whether the reflog message for a command should include the result.
|
protected RefUpdate |
newUpdate(ReceiveCommand cmd)
Create a new RefUpdate copying the batch settings.
|
BatchRefUpdate |
setAllowNonFastForwards(boolean allow)
Set if this update wants to permit a forced update.
|
BatchRefUpdate |
setAtomic(boolean atomic)
Request that all updates in this batch be performed atomically.
|
BatchRefUpdate |
setForceRefLog(boolean force)
Force writing a reflog for the updated ref.
|
void |
setPushCertificate(PushCertificate cert)
Set a push certificate associated with this update.
|
protected void |
setPushOptions(java.util.List<java.lang.String> options)
Set push options associated with this update.
|
BatchRefUpdate |
setRefLogIdent(PersonIdent pi)
Set the identity of the user appearing in the reflog.
|
BatchRefUpdate |
setRefLogMessage(java.lang.String msg,
boolean appendStatus)
Set the message to include in the reflog.
|
java.lang.String |
toString() |
protected static final java.time.Duration MAX_WAIT
MonotonicClock
to resolve associated ProposedTimestamp
s.
A default of 5 seconds was chosen by guessing. A common assumption is clock skew between machines on the same LAN using an NTP server also on the same LAN should be under 5 seconds. 5 seconds is also not that long for a large `git push` operation to complete.
private final RefDatabase refdb
private final java.util.List<ReceiveCommand> commands
private boolean allowNonFastForwards
private PersonIdent refLogIdent
private java.lang.String refLogMessage
private boolean refLogIncludeResult
refLogMessage
.private boolean forceRefLog
private PushCertificate pushCert
private boolean atomic
private java.util.List<java.lang.String> pushOptions
private java.util.List<ProposedTimestamp> timestamps
protected BatchRefUpdate(RefDatabase refdb)
refdb
- the reference database of the repository to be updated.public boolean isAllowNonFastForwards()
public BatchRefUpdate setAllowNonFastForwards(boolean allow)
allow
- true if this update batch should ignore merge tests.this
.public PersonIdent getRefLogIdent()
public BatchRefUpdate setRefLogIdent(PersonIdent pi)
The timestamp portion of the identity is ignored. A new identity with the current timestamp will be created automatically when the update occurs and the log record is written.
pi
- identity of the user. If null the identity will be
automatically determined based on the repository
configuration.this
.@Nullable public java.lang.String getRefLogMessage()
public boolean isRefLogIncludingResult()
Describes the default for commands in this batch that do not override it
with
ReceiveCommand.setRefLogMessage(String, boolean)
.
public BatchRefUpdate setRefLogMessage(java.lang.String msg, boolean appendStatus)
Repository implementations may limit which reflogs are written by
default, based on the project configuration. If a repo is not configured
to write logs for this ref by default, setting the message alone may have
no effect. To indicate that the repo should write logs for this update in
spite of configured defaults, use setForceRefLog(boolean)
.
Describes the default for commands in this batch that do not override it
with
ReceiveCommand.setRefLogMessage(String, boolean)
.
msg
- the message to describe this change. If null and appendStatus
is false, the reflog will not be updated.appendStatus
- true if the status of the ref change (fast-forward or
forced-update) should be appended to the user supplied
message.this
.public BatchRefUpdate disableRefLog()
Equivalent to setRefLogMessage(null, false)
.
this
.public BatchRefUpdate setForceRefLog(boolean force)
force
- whether to force.this
public boolean isRefLogDisabled()
disableRefLog()
.protected boolean isForceRefLog()
public BatchRefUpdate setAtomic(boolean atomic)
When atomic updates are used, either all commands apply successfully, or
none do. Commands that might have otherwise succeeded are rejected with
REJECTED_OTHER_REASON
.
This method only works if the underlying ref database supports atomic
transactions, i.e.
RefDatabase.performsAtomicTransactions()
returns true. Calling this method with true if the underlying ref
database does not support atomic transactions will cause all commands to
fail with REJECTED_OTHER_REASON
.
atomic
- whether updates should be atomic.this
public boolean isAtomic()
public void setPushCertificate(PushCertificate cert)
This usually includes commands to update the refs in this batch, but is not required to.
cert
- push certificate, may be null.protected PushCertificate getPushCertificate()
This usually includes commands to update the refs in this batch, but is not required to.
public java.util.List<ReceiveCommand> getCommands()
public BatchRefUpdate addCommand(ReceiveCommand cmd)
cmd
- the command to add, must not be null.this
.public BatchRefUpdate addCommand(ReceiveCommand... cmd)
cmd
- the commands to add, must not be null.this
.public BatchRefUpdate addCommand(java.util.Collection<ReceiveCommand> cmd)
cmd
- the commands to add, must not be null.this
.@Nullable public java.util.List<java.lang.String> getPushOptions()
execute(org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.lib.ProgressMonitor, java.util.List<java.lang.String>)
; prior to calling
execute(org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.lib.ProgressMonitor, java.util.List<java.lang.String>)
, always returns null.protected void setPushOptions(java.util.List<java.lang.String> options)
Implementations must call this at the top of execute(RevWalk,
ProgressMonitor, List)
.
options
- options passed to execute
.public java.util.List<ProposedTimestamp> getProposedTimestamps()
public BatchRefUpdate addProposedTimestamp(ProposedTimestamp ts)
ts
- a ProposedTimestamp
object.this
.public void execute(RevWalk walk, ProgressMonitor monitor, java.util.List<java.lang.String> options) throws java.io.IOException
The default implementation of this method performs a sequential reference update over each reference.
Implementations must respect the atomicity requirements of the underlying
database as described in setAtomic(boolean)
and
RefDatabase.performsAtomicTransactions()
.
walk
- a RevWalk to parse tags in case the storage system wants to
store them pre-peeled, a common performance optimization.monitor
- progress monitor to receive update status on.options
- a list of option strings; set null to execute withoutjava.io.IOException
- the database is unable to accept the update. Individual
command status must be tested to determine if there is a
partial failure, or a total failure.private static boolean isMissing(RevWalk walk, ObjectId id) throws java.io.IOException
java.io.IOException
protected boolean blockUntilTimestamps(java.time.Duration maxWait)
maxWait
- maximum amount of time to wait for timestamps to resolve.public void execute(RevWalk walk, ProgressMonitor monitor) throws java.io.IOException
walk
- a RevWalk to parse tags in case the storage system wants to
store them pre-peeled, a common performance optimization.monitor
- progress monitor to receive update status on.java.io.IOException
- the database is unable to accept the update. Individual
command status must be tested to determine if there is a
partial failure, or a total failure.private static java.util.Collection<java.lang.String> getTakenPrefixes(java.util.Collection<java.lang.String> names)
protected static java.util.Collection<java.lang.String> getPrefixes(java.lang.String name)
name
- ref name.refs/heads/foo
, returns
refs
and refs/heads
.protected static void addPrefixesTo(java.lang.String name, java.util.Collection<java.lang.String> out)
name
- ref name.out
- path prefixes of the ref name. For refs/heads/foo
,
returns refs
and refs/heads
.protected RefUpdate newUpdate(ReceiveCommand cmd) throws java.io.IOException
cmd
- specific command the update should be created to copy.java.io.IOException
- the reference database cannot make a new update object for
the given reference.protected boolean isRefLogDisabled(ReceiveCommand cmd)
cmd
- specific command.protected java.lang.String getRefLogMessage(ReceiveCommand cmd)
cmd
- specific command.protected boolean isRefLogIncludingResult(ReceiveCommand cmd)
cmd
- specific command.protected boolean isForceRefLog(ReceiveCommand cmd)
cmd
- specific command.public java.lang.String toString()
toString
in class java.lang.Object