Top Description Fields Constructors Methods
org.eclipse.jgit.lib

public Class BatchRefUpdate

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.internal.storage.file.PackedBatchRefUpdate, org.eclipse.jgit.internal.storage.reftable.ReftableBatchRefUpdate
Static Imports
org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED, .ReceiveCommand.Result.REJECTED_OTHER_REASON

Batch of reference updates to be applied to a repository.

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

Modifier and TypeField and Description
private boolean
allowNonFastForwards

Does the caller permit a forced update on a reference?

private boolean
atomic

Whether updates should be atomic.

private final 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 final Duration
MAX_WAIT

Maximum delay the calling thread will tolerate while waiting for a MonotonicClock to resolve associated ProposedTimestamps.

private PushCertificate
pushCert

Push certificate associated with this update.

private List<String>
pushOptions

Push options associated with this update.

private final RefDatabase
private PersonIdent
refLogIdent

Identity to record action as within the reflog.

private boolean
refLogIncludeResult

Should the result value be appended to refLogMessage.

private String
refLogMessage

Message the caller wants included in the reflog.

private List<ProposedTimestamp>
timestamps

Associated timestamps that should be blocked on before update.

Constructor Summary

AccessConstructor and Description
protected
BatchRefUpdate(RefDatabase
the reference database of the repository to be updated.
refdb
)

Initialize a new batch update.

Method Summary

Modifier and TypeMethod and Description
public BatchRefUpdate

Returns:

this.
addCommand
(ReceiveCommand
the command to add, must not be null.
cmd
)

Add a single command to this batch update.

public BatchRefUpdate

Returns:

this.
addCommand
(ReceiveCommand...
the commands to add, must not be null.
cmd
)

Add commands to this batch update.

public BatchRefUpdate

Returns:

this.
addCommand
(Collection<ReceiveCommand>
the commands to add, must not be null.
cmd
)

Add commands to this batch update.

protected static void
addPrefixesTo(String
ref name.
name
,
Collection<String>
path prefixes of the ref name. For refs/heads/foo, returns refs and refs/heads.
out
)

Add prefixes of a ref name to an existing collection.

public BatchRefUpdate

Returns:

this.
addProposedTimestamp
(ProposedTimestamp ts)

Request the batch to wait for the affected timestamps to resolve.

protected boolean

Returns:

true if timestamps were successfully waited for; false if commands were aborted.
blockUntilTimestamps
(Duration
maximum amount of time to wait for timestamps to resolve.
maxWait
)

Wait for timestamps to be in the past, aborting commands on timeout.

public BatchRefUpdate

Returns:

this.
disableRefLog
()

Don't record this update in the ref's associated reflog.

public void
execute(RevWalk
a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.
walk
,
ProgressMonitor
progress monitor to receive update status on.
monitor
,
List<String>
a list of option strings; set null to execute without
options
)

Execute this batch update.

public void
execute(RevWalk
a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.
walk
,
ProgressMonitor
progress monitor to receive update status on.
monitor
)

Execute this batch update without option strings.

public List<ReceiveCommand>

Returns:

commands this update will process.
getCommands
()

Get commands this update will process.

protected static Collection<String>

Returns:

path prefixes of the ref name. For refs/heads/foo, returns refs and refs/heads.
getPrefixes
(String
ref name.
name
)

Get all path prefixes of a ref name.

public List<ProposedTimestamp>

Returns:

list of timestamps the batch must wait for.
getProposedTimestamps
()

Get list of timestamps the batch must wait for.

protected PushCertificate

Returns:

push certificate, may be null.
getPushCertificate
()

Set the push certificate associated with this update.

public List<String>

Returns:

push options that were passed to execute; prior to calling execute, always returns null.
getPushOptions
()

Gets the list of option strings associated with this update.

protected RefDatabase

Returns:

the ref database.
getRefDatabase
()

Get the ref database associated with this update.

public PersonIdent

Returns:

identity of the user making the change in the reflog.
getRefLogIdent
()

Get identity of the user making the change in the reflog.

public String

Returns:

message the caller wants to include in the reflog; null if the update should not be logged.
getRefLogMessage
()

Get the message to include in the reflog.

protected String

Returns:

reflog message, taking into account the state from this instance as well as overrides in the given command.
getRefLogMessage
(ReceiveCommand
specific command.
cmd
)

Get reflog message for a command.

public boolean

Returns:

true if the batch update will permit a non-fast-forward update to an existing reference.
isAllowNonFastForwards
()

Whether the batch update will permit a non-fast-forward update to an existing reference.

public boolean

Returns:

atomic whether updates should be atomic.
isAtomic
()

Whether updates should be atomic.

protected boolean

Returns:

whether force writing is enabled.
isForceRefLog
()

Check whether the reflog should be written regardless of repo defaults.

protected boolean

Returns:

whether force writing is enabled.
isForceRefLog
(ReceiveCommand
specific command.
cmd
)

Check whether the reflog for a command should be written regardless of repo defaults.

private static boolean
public boolean

Returns:

true if disabled.
isRefLogDisabled
()

Check whether log has been disabled by disableRefLog().

protected boolean

Returns:

whether the reflog is disabled, taking into account the state from this instance as well as overrides in the given command.
isRefLogDisabled
(ReceiveCommand
specific command.
cmd
)

Check whether reflog is disabled for a command.

public boolean

Returns:

true if the message should include the result.
isRefLogIncludingResult
()

Check whether the reflog message should include the result of the update, such as fast-forward or force-update.

protected boolean

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.
isRefLogIncludingResult
(ReceiveCommand
specific command.
cmd
)

Check whether the reflog message for a command should include the result.

protected RefUpdate

Returns:

a single reference update command.
newUpdate
(ReceiveCommand
specific command the update should be created to copy.
cmd
)

Create a new RefUpdate copying the batch settings.

public BatchRefUpdate

Returns:

this.
setAllowNonFastForwards
(boolean
true if this update batch should ignore merge tests.
allow
)

Set if this update wants to permit a forced update.

public BatchRefUpdate

Returns:

this
setAtomic
(boolean
whether updates should be atomic.
atomic
)

Request that all updates in this batch be performed atomically.

public BatchRefUpdate

Returns:

this
setForceRefLog
(boolean
whether to force.
force
)

Force writing a reflog for the updated ref.

public void
setPushCertificate(PushCertificate
push certificate, may be null.
cert
)

Set a push certificate associated with this update.

protected void
setPushOptions(List<String>
options passed to execute.
options
)

Set push options associated with this update.

public BatchRefUpdate

Returns:

this.
setRefLogIdent
(PersonIdent
identity of the user. If null the identity will be automatically determined based on the repository configuration.
pi
)

Set the identity of the user appearing in the reflog.

public BatchRefUpdate

Returns:

this.
setRefLogMessage
(String
the message to describe this change. If null and appendStatus is false, the reflog will not be updated.
msg
,
boolean
true if the status of the ref change (fast-forward or forced-update) should be appended to the user supplied message.
appendStatus
)

Set the message to include in the reflog.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

allowNonFastForwardsback to summary
private boolean allowNonFastForwards

Does the caller permit a forced update on a reference?

atomicback to summary
private boolean atomic

Whether updates should be atomic.

commandsback to summary
private final List<ReceiveCommand> commands

Commands to apply during this batch.

forceRefLogback to summary
private boolean forceRefLog

Should reflogs be written even if the configured default for this ref is not to write it.

MAX_WAITback to summary
protected static final Duration MAX_WAIT

Maximum delay the calling thread will tolerate while waiting for a MonotonicClock to resolve associated ProposedTimestamps.

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
pushCertback to summary
private PushCertificate pushCert

Push certificate associated with this update.

pushOptionsback to summary
private List<String> pushOptions

Push options associated with this update.

refdbback to summary
private final RefDatabase refdb
refLogIdentback to summary
private PersonIdent refLogIdent

Identity to record action as within the reflog.

refLogIncludeResultback to summary
private boolean refLogIncludeResult

Should the result value be appended to refLogMessage.

refLogMessageback to summary
private String refLogMessage

Message the caller wants included in the reflog.

timestampsback to summary
private List<ProposedTimestamp> timestamps

Associated timestamps that should be blocked on before update.

Constructor Detail

BatchRefUpdateback to summary
protected BatchRefUpdate(RefDatabase refdb)

Initialize a new batch update.

Parameters
refdb:RefDatabase

the reference database of the repository to be updated.

Method Detail

addCommandback to summary
public BatchRefUpdate addCommand(ReceiveCommand cmd)

Add a single command to this batch update.

Parameters
cmd:ReceiveCommand

the command to add, must not be null.

Returns:BatchRefUpdate

this.

addCommandback to summary
public BatchRefUpdate addCommand(ReceiveCommand... cmd)

Add commands to this batch update.

Parameters
cmd:ReceiveCommand[]

the commands to add, must not be null.

Returns:BatchRefUpdate

this.

addCommandback to summary
public BatchRefUpdate addCommand(Collection<ReceiveCommand> cmd)

Add commands to this batch update.

Parameters
cmd:Collection<ReceiveCommand>

the commands to add, must not be null.

Returns:BatchRefUpdate

this.

addPrefixesToback to summary
protected static void addPrefixesTo(String name, Collection<String> out)

Add prefixes of a ref name to an existing collection.

Parameters
name:String

ref name.

out:Collection<String>

path prefixes of the ref name. For refs/heads/foo, returns refs and refs/heads.

Since
4.9
addProposedTimestampback to summary
public BatchRefUpdate addProposedTimestamp(ProposedTimestamp ts)

Request the batch to wait for the affected timestamps to resolve.

Parameters
ts:ProposedTimestamp

a org.eclipse.jgit.util.time.ProposedTimestamp object.

Returns:BatchRefUpdate

this.

Since
4.6
blockUntilTimestampsback to summary
protected boolean blockUntilTimestamps(Duration maxWait)

Wait for timestamps to be in the past, aborting commands on timeout.

Parameters
maxWait:Duration

maximum amount of time to wait for timestamps to resolve.

Returns:boolean

true if timestamps were successfully waited for; false if commands were aborted.

Since
4.6
disableRefLogback to summary
public BatchRefUpdate disableRefLog()

Don't record this update in the ref's associated reflog.

Equivalent to setRefLogMessage(null, false).

Returns:BatchRefUpdate

this.

executeback to summary
public void execute(RevWalk walk, ProgressMonitor monitor, List<String> options) throws IOException

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) and org.eclipse.jgit.lib.RefDatabase#performsAtomicTransactions().

Parameters
walk:RevWalk

a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.

monitor:ProgressMonitor

progress monitor to receive update status on.

options:List<String>

a list of option strings; set null to execute without

Exceptions
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
executeback to summary
public void execute(RevWalk walk, ProgressMonitor monitor) throws IOException

Execute this batch update without option strings.

Parameters
walk:RevWalk

a RevWalk to parse tags in case the storage system wants to store them pre-peeled, a common performance optimization.

monitor:ProgressMonitor

progress monitor to receive update status on.

Exceptions
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.
getCommandsback to summary
public List<ReceiveCommand> getCommands()

Get commands this update will process.

Returns:List<ReceiveCommand>

commands this update will process.

getPrefixesback to summary
protected static Collection<String> getPrefixes(String name)

Get all path prefixes of a ref name.

Parameters
name:String

ref name.

Returns:Collection<String>

path prefixes of the ref name. For refs/heads/foo, returns refs and refs/heads.

Since
4.9
getProposedTimestampsback to summary
public List<ProposedTimestamp> getProposedTimestamps()

Get list of timestamps the batch must wait for.

Returns:List<ProposedTimestamp>

list of timestamps the batch must wait for.

Since
4.6
getPushCertificateback to summary
protected PushCertificate 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:PushCertificate

push certificate, may be null.

Since
4.1
getPushOptionsback to summary
public List<String> getPushOptions()

Gets the list of option strings associated with this update.

Returns:List<String>

push options that were passed to execute; prior to calling execute, always returns null.

Annotations
@Nullable
Since
4.5
getRefDatabaseback to summary
protected RefDatabase getRefDatabase()

Get the ref database associated with this update.

Returns:RefDatabase

the ref database.

Since
6.6
getRefLogIdentback to summary
public PersonIdent getRefLogIdent()

Get identity of the user making the change in the reflog.

Returns:PersonIdent

identity of the user making the change in the reflog.

getRefLogMessageback to summary
public String getRefLogMessage()

Get the message to include in the reflog.

Returns:String

message the caller wants to include in the reflog; null if the update should not be logged.

Annotations
@Nullable
getRefLogMessageback to summary
protected String getRefLogMessage(ReceiveCommand cmd)

Get reflog message for a command.

Parameters
cmd:ReceiveCommand

specific command.

Returns:String

reflog message, taking into account the state from this instance as well as overrides in the given command.

Since
4.9
isAllowNonFastForwardsback to summary
public boolean isAllowNonFastForwards()

Whether the batch update will permit a non-fast-forward update to an existing reference.

Returns:boolean

true if the batch update will permit a non-fast-forward update to an existing reference.

isAtomicback to summary
public boolean isAtomic()

Whether updates should be atomic.

Returns:boolean

atomic whether updates should be atomic.

Since
4.4
isForceRefLogback to summary
protected boolean isForceRefLog()

Check whether the reflog should be written regardless of repo defaults.

Returns:boolean

whether force writing is enabled.

Since
4.9
isForceRefLogback to summary
protected boolean isForceRefLog(ReceiveCommand cmd)

Check whether the reflog for a command should be written regardless of repo defaults.

Parameters
cmd:ReceiveCommand

specific command.

Returns:boolean

whether force writing is enabled.

Since
4.9
isMissingback to summary
private static boolean isMissing(RevWalk walk, ObjectId id) throws IOException
isRefLogDisabledback to summary
public boolean isRefLogDisabled()

Check whether log has been disabled by disableRefLog().

Returns:boolean

true if disabled.

isRefLogDisabledback to summary
protected boolean isRefLogDisabled(ReceiveCommand cmd)

Check whether reflog is disabled for a command.

Parameters
cmd:ReceiveCommand

specific command.

Returns:boolean

whether the reflog is disabled, taking into account the state from this instance as well as overrides in the given command.

Since
4.9
isRefLogIncludingResultback to summary
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 org.eclipse.jgit.transport.ReceiveCommand#setRefLogMessage(String, boolean).

Returns:boolean

true if the message should include the result.

isRefLogIncludingResultback to summary
protected boolean isRefLogIncludingResult(ReceiveCommand cmd)

Check whether the reflog message for a command should include the result.

Parameters
cmd:ReceiveCommand

specific command.

Returns:boolean

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
newUpdateback to summary
protected RefUpdate newUpdate(ReceiveCommand cmd) throws IOException

Create a new RefUpdate copying the batch settings.

Parameters
cmd:ReceiveCommand

specific command the update should be created to copy.

Returns:RefUpdate

a single reference update command.

Exceptions
IOException:
the reference database cannot make a new update object for the given reference.
setAllowNonFastForwardsback to summary
public BatchRefUpdate setAllowNonFastForwards(boolean allow)

Set if this update wants to permit a forced update.

Parameters
allow:boolean

true if this update batch should ignore merge tests.

Returns:BatchRefUpdate

this.

setAtomicback to summary
public BatchRefUpdate setAtomic(boolean atomic)

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. org.eclipse.jgit.lib.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.

Parameters
atomic:boolean

whether updates should be atomic.

Returns:BatchRefUpdate

this

Since
4.4
setForceRefLogback to summary
public BatchRefUpdate setForceRefLog(boolean force)

Force writing a reflog for the updated ref.

Parameters
force:boolean

whether to force.

Returns:BatchRefUpdate

this

Since
4.9
setPushCertificateback to summary
public void setPushCertificate(PushCertificate cert)

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:PushCertificate

push certificate, may be null.

Since
4.1
setPushOptionsback to summary
protected void setPushOptions(List<String> options)

Set push options associated with this update.

Implementations must call this at the top of execute(RevWalk, ProgressMonitor, List).

Parameters
options:List<String>

options passed to execute.

Since
4.9
setRefLogIdentback to summary
public BatchRefUpdate setRefLogIdent(PersonIdent pi)

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:PersonIdent

identity of the user. If null the identity will be automatically determined based on the repository configuration.

Returns:BatchRefUpdate

this.

setRefLogMessageback to summary
public BatchRefUpdate setRefLogMessage(String msg, boolean appendStatus)

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 org.eclipse.jgit.transport.ReceiveCommand#setRefLogMessage(String, boolean).

Parameters
msg:String

the message to describe this change. If null and appendStatus is false, the reflog will not be updated.

appendStatus:boolean

true if the status of the ref change (fast-forward or forced-update) should be appended to the user supplied message.

Returns:BatchRefUpdate

this.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override