Class BatchRefUpdate
- Direct Known Subclasses:
PackedBatchRefUpdate
,ReftableBatchRefUpdate
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Does the caller permit a forced update on a reference?private boolean
Whether updates should be atomic.private final List
<ReceiveCommand> Commands to apply during this batch.private boolean
Should reflogs be written even if the configured default for this ref is not to write it.protected static final Duration
Maximum delay the calling thread will tolerate while waiting for aMonotonicClock
to resolve associatedProposedTimestamp
s.private PushCertificate
Push certificate associated with this update.Push options associated with this update.private final RefDatabase
private PersonIdent
Identity to record action as within the reflog.private boolean
Should the result value be appended torefLogMessage
.private String
Message the caller wants included in the reflog.private List
<ProposedTimestamp> Associated timestamps that should be blocked on before update. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
BatchRefUpdate
(RefDatabase refdb) Initialize a new batch update. -
Method Summary
Modifier and TypeMethodDescriptionAdd commands to this batch update.addCommand
(ReceiveCommand cmd) Add a single command to this batch update.addCommand
(ReceiveCommand... cmd) Add commands to this batch update.protected static void
addPrefixesTo
(String name, Collection<String> out) Add prefixes of a ref name to an existing collection.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.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.Get commands this update will process.protected static Collection
<String> getPrefixes
(String name) Get all path prefixes of a ref name.Get list of timestamps the batch must wait for.protected PushCertificate
Set the push certificate associated with this update.Gets the list of option strings associated with this update.Get identity of the user making the change in the reflog.Get the message to include in the reflog.protected String
Get reflog message for a command.private static Collection
<String> getTakenPrefixes
(Collection<String> names) boolean
Whether the batch update will permit a non-fast-forward update to an existing reference.boolean
isAtomic()
Whether updates should be atomic.protected boolean
Check whether the reflog should be written regardless of repo defaults.protected boolean
Check whether the reflog for a command should be written regardless of repo defaults.private static boolean
boolean
Check whether log has been disabled bydisableRefLog()
.protected boolean
Check whether reflog is disabled for a command.boolean
Check whether the reflog message should include the result of the update, such as fast-forward or force-update.protected boolean
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.setAllowNonFastForwards
(boolean allow) Set if this update wants to permit a forced update.setAtomic
(boolean atomic) Request that all updates in this batch be performed atomically.setForceRefLog
(boolean force) Force writing a reflog for the updated ref.void
Set a push certificate associated with this update.protected void
setPushOptions
(List<String> options) Set push options associated with this update.Set the identity of the user appearing in the reflog.setRefLogMessage
(String msg, boolean appendStatus) Set the message to include in the reflog.toString()
-
Field Details
-
MAX_WAIT
Maximum delay the calling thread will tolerate while waiting for aMonotonicClock
to resolve associatedProposedTimestamp
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.
- Since:
- 4.9
-
refdb
-
commands
Commands to apply during this batch. -
allowNonFastForwards
private boolean allowNonFastForwardsDoes the caller permit a forced update on a reference? -
refLogIdent
Identity to record action as within the reflog. -
refLogMessage
Message the caller wants included in the reflog. -
refLogIncludeResult
private boolean refLogIncludeResultShould the result value be appended torefLogMessage
. -
forceRefLog
private boolean forceRefLogShould reflogs be written even if the configured default for this ref is not to write it. -
pushCert
Push certificate associated with this update. -
atomic
private boolean atomicWhether updates should be atomic. -
pushOptions
Push options associated with this update. -
timestamps
Associated timestamps that should be blocked on before update.
-
-
Constructor Details
-
BatchRefUpdate
Initialize a new batch update.- Parameters:
refdb
- the reference database of the repository to be updated.
-
-
Method Details
-
isAllowNonFastForwards
public boolean isAllowNonFastForwards()Whether the batch update will permit a non-fast-forward update to an existing reference.- Returns:
- true if the batch update will permit a non-fast-forward update to an existing reference.
-
setAllowNonFastForwards
Set if this update wants to permit a forced update.- Parameters:
allow
- true if this update batch should ignore merge tests.- Returns:
this
.
-
getRefLogIdent
Get identity of the user making the change in the reflog.- Returns:
- identity of the user making the change in the reflog.
-
setRefLogIdent
Set the identity of the user appearing in the reflog.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.
- Parameters:
pi
- identity of the user. If null the identity will be automatically determined based on the repository configuration.- Returns:
this
.
-
getRefLogMessage
Get the message to include in the reflog.- Returns:
- message the caller wants to include in the reflog; null if the update should not be logged.
-
isRefLogIncludingResult
public boolean isRefLogIncludingResult()Check whether the reflog message should include the result of the update, such as fast-forward or force-update.Describes the default for commands in this batch that do not override it with
ReceiveCommand.setRefLogMessage(String, boolean)
.- Returns:
- true if the message should include the result.
-
setRefLogMessage
Set the message to include in the reflog.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)
.- Parameters:
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.- Returns:
this
.
-
disableRefLog
Don't record this update in the ref's associated reflog.Equivalent to
setRefLogMessage(null, false)
.- Returns:
this
.
-
setForceRefLog
Force writing a reflog for the updated ref.- Parameters:
force
- whether to force.- Returns:
this
- Since:
- 4.9
-
isRefLogDisabled
public boolean isRefLogDisabled()Check whether log has been disabled bydisableRefLog()
.- Returns:
- true if disabled.
-
isForceRefLog
protected boolean isForceRefLog()Check whether the reflog should be written regardless of repo defaults.- Returns:
- whether force writing is enabled.
- Since:
- 4.9
-
setAtomic
Request that all updates in this batch be performed atomically.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 withREJECTED_OTHER_REASON
.- Parameters:
atomic
- whether updates should be atomic.- Returns:
this
- Since:
- 4.4
-
isAtomic
public boolean isAtomic()Whether updates should be atomic.- Returns:
- atomic whether updates should be atomic.
- Since:
- 4.4
-
setPushCertificate
Set a push certificate associated with this update.This usually includes commands to update the refs in this batch, but is not required to.
- Parameters:
cert
- push certificate, may be null.- Since:
- 4.1
-
getPushCertificate
Set the push certificate associated with this update.This usually includes commands to update the refs in this batch, but is not required to.
- Returns:
- push certificate, may be null.
- Since:
- 4.1
-
getCommands
Get commands this update will process.- Returns:
- commands this update will process.
-
addCommand
Add a single command to this batch update.- Parameters:
cmd
- the command to add, must not be null.- Returns:
this
.
-
addCommand
Add commands to this batch update.- Parameters:
cmd
- the commands to add, must not be null.- Returns:
this
.
-
addCommand
Add commands to this batch update.- Parameters:
cmd
- the commands to add, must not be null.- Returns:
this
.
-
getPushOptions
Gets the list of option strings associated with this update.- Returns:
- push options that were passed to
execute(org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.lib.ProgressMonitor, java.util.List<java.lang.String>)
; prior to callingexecute(org.eclipse.jgit.revwalk.RevWalk, org.eclipse.jgit.lib.ProgressMonitor, java.util.List<java.lang.String>)
, always returns null. - Since:
- 4.5
-
setPushOptions
Set push options associated with this update.Implementations must call this at the top of
execute(RevWalk, ProgressMonitor, List)
.- Parameters:
options
- options passed toexecute
.- Since:
- 4.9
-
getProposedTimestamps
Get list of timestamps the batch must wait for.- Returns:
- list of timestamps the batch must wait for.
- Since:
- 4.6
-
addProposedTimestamp
Request the batch to wait for the affected timestamps to resolve.- Parameters:
ts
- aProposedTimestamp
object.- Returns:
this
.- Since:
- 4.6
-
execute
Execute this batch update.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)
andRefDatabase.performsAtomicTransactions()
.- Parameters:
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 without- Throws:
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.- Since:
- 4.5
-
isMissing
- Throws:
IOException
-
blockUntilTimestamps
Wait for timestamps to be in the past, aborting commands on timeout.- Parameters:
maxWait
- maximum amount of time to wait for timestamps to resolve.- Returns:
- true if timestamps were successfully waited for; false if commands were aborted.
- Since:
- 4.6
-
execute
Execute this batch update without option strings.- Parameters:
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.- Throws:
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.
-
getTakenPrefixes
-
getPrefixes
Get all path prefixes of a ref name.- Parameters:
name
- ref name.- Returns:
- path prefixes of the ref name. For
refs/heads/foo
, returnsrefs
andrefs/heads
. - Since:
- 4.9
-
addPrefixesTo
Add prefixes of a ref name to an existing collection.- Parameters:
name
- ref name.out
- path prefixes of the ref name. Forrefs/heads/foo
, returnsrefs
andrefs/heads
.- Since:
- 4.9
-
newUpdate
Create a new RefUpdate copying the batch settings.- Parameters:
cmd
- specific command the update should be created to copy.- Returns:
- a single reference update command.
- Throws:
IOException
- the reference database cannot make a new update object for the given reference.
-
isRefLogDisabled
Check whether reflog is disabled for a command.- Parameters:
cmd
- specific command.- Returns:
- whether the reflog is disabled, taking into account the state from this instance as well as overrides in the given command.
- Since:
- 4.9
-
getRefLogMessage
Get reflog message for a command.- Parameters:
cmd
- specific command.- Returns:
- reflog message, taking into account the state from this instance as well as overrides in the given command.
- Since:
- 4.9
-
isRefLogIncludingResult
Check whether the reflog message for a command should include the result.- Parameters:
cmd
- specific command.- Returns:
- whether the reflog message should show the result, taking into account the state from this instance as well as overrides in the given command.
- Since:
- 4.9
-
isForceRefLog
Check whether the reflog for a command should be written regardless of repo defaults.- Parameters:
cmd
- specific command.- Returns:
- whether force writing is enabled.
- Since:
- 4.9
-
toString
-