public class BatchRefUpdate extends 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 |
---|---|
protected static Duration |
MAX_WAIT
Maximum delay the calling thread will tolerate while waiting for a
MonotonicClock to resolve associated ProposedTimestamp s. |
Modifier | Constructor and Description |
---|---|
protected |
BatchRefUpdate(RefDatabase refdb)
Initialize a new batch update.
|
Modifier and Type | Method and Description |
---|---|
BatchRefUpdate |
addCommand(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(String name,
Collection<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(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,
List<String> options)
Execute this batch update.
|
List<ReceiveCommand> |
getCommands() |
protected static Collection<String> |
getPrefixes(String name)
Get all path prefixes of a ref name.
|
List<ProposedTimestamp> |
getProposedTimestamps() |
protected PushCertificate |
getPushCertificate()
Set the push certificate associated with this update.
|
List<String> |
getPushOptions()
Gets the list of option strings associated with this update.
|
PersonIdent |
getRefLogIdent() |
String |
getRefLogMessage()
Get the message to include in the reflog.
|
protected String |
getRefLogMessage(ReceiveCommand cmd)
Get reflog message for a command.
|
boolean |
isAllowNonFastForwards() |
boolean |
isAtomic() |
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.
|
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(List<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(String msg,
boolean appendStatus)
Set the message to include in the reflog.
|
String |
toString() |
protected static final 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.
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 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(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 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(Collection<ReceiveCommand> cmd)
cmd
- the commands to add, must not be null.this
.@Nullable public List<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(List<String> options)
Implementations must call this at the top of execute(RevWalk,
ProgressMonitor, List)
.
options
- options passed to execute
.public List<ProposedTimestamp> getProposedTimestamps()
public BatchRefUpdate addProposedTimestamp(ProposedTimestamp ts)
ts
- this
.public void execute(RevWalk walk, ProgressMonitor monitor, List<String> options) throws 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 withoutIOException
- 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.protected boolean blockUntilTimestamps(Duration maxWait)
maxWait
- maximum amount of time to wait for timestamps to resolve.public void execute(RevWalk walk, ProgressMonitor monitor) throws 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.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.protected static Collection<String> getPrefixes(String name)
name
- ref name.refs/heads/foo
, returns
refs
and refs/heads
.protected static void addPrefixesTo(String name, Collection<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 IOException
cmd
- specific command the update should be created to copy.IOException
- the reference database cannot make a new update object for
the given reference.protected boolean isRefLogDisabled(ReceiveCommand cmd)
cmd
- specific command.protected String getRefLogMessage(ReceiveCommand cmd)
cmd
- specific command.protected boolean isRefLogIncludingResult(ReceiveCommand cmd)
cmd
- specific command.protected boolean isForceRefLog(ReceiveCommand cmd)
cmd
- specific command.Copyright © 2017 Eclipse JGit Project. All rights reserved.