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

public abstract Class RefUpdate

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.internal.storage.dfs.DfsRefUpdate, org.eclipse.jgit.internal.storage.file.FileReftableDatabase.FileReftableRefUpdate, org.eclipse.jgit.internal.storage.file.RefDirectoryUpdate
Imports
java.io.IOException, java.text.MessageFormat, org.eclipse.jgit.errors.MissingObjectException, org.eclipse.jgit.internal.JGitText, org.eclipse.jgit.revwalk.RevCommit, .RevObject, .RevWalk, org.eclipse.jgit.transport.PushCertificate, org.eclipse.jgit.util.References

Creates, updates or deletes any reference.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
RefUpdate.Result

Status of an update request.

private abstract static class
RefUpdate.Store

Handle the abstraction of storing a ref update.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
detachingSymbolicRef

Is this RefUpdate detaching a symbolic ref?

private ObjectId
expValue

If non-null, the value oldValue must have to continue.

private boolean
force

Does this specification ask for forced updated (rewind/reset)?

private boolean
forceRefLog

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

private ObjectId
newValue

New value the caller wants this ref to have.

private ObjectId
oldValue

Old value of the ref, obtained after we lock it.

private PushCertificate
pushCert

Push certificate associated with this update.

private final Ref
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 RefUpdate.Result
result

Result of the update operation.

Constructor Summary

AccessConstructor and Description
protected
RefUpdate(Ref
the reference that will be updated by this operation.
ref
)

Construct a new update operation for the reference.

Method Summary

Modifier and TypeMethod and Description
public RefUpdate.Result

Returns:

the result status of the delete.
delete
()

Delete the ref.

public RefUpdate.Result

Returns:

the result status of the delete.
delete
(RevWalk
a RevWalk instance this delete command can borrow to perform the merge test. The walk will be reset to perform the test.
walk
)

Delete the ref.

public void
disableRefLog()

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

protected abstract RefUpdate.Result

Returns:

result
doDelete
(RefUpdate.Result desiredResult)

Do delete

protected abstract RefUpdate.Result

Returns:

result
doUpdate
(RefUpdate.Result desiredResult)

Do update

public RefUpdate.Result

Returns:

the result status of the update.
forceUpdate
()

Force the ref to take the new value.

public ObjectId

Returns:

the expected value of the ref after the lock is taken, but before update occurs. Null to avoid the compare and swap test. Use org.eclipse.jgit.lib.ObjectId#zeroId() to indicate expectation of a non-existant ref.
getExpectedOldObjectId
()

Get the expected value of the ref after the lock is taken, but before update occurs.

public String

Returns:

name of underlying ref.
getName
()

Get the name of the ref this update will operate on.

public ObjectId

Returns:

new value. Null if the caller has not configured it.
getNewObjectId
()

Get the new value the ref will be (or was) updated to.

public ObjectId

Returns:

the value of the ref prior to the update being attempted; null if the updated has not been attempted yet.
getOldObjectId
()

The old value of the ref, prior to the update being attempted.

protected PushCertificate

Returns:

push certificate, may be null.
getPushCertificate
()

Set the push certificate associated with this update.

public Ref

Returns:

the reference this update will create or modify.
getRef
()

Get the reference this update will create or modify.

protected abstract RefDatabase

Returns:

the reference database this update modifies.
getRefDatabase
()

Get the reference database this update modifies.

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 abstract Repository

Returns:

the repository storing the database's objects.
getRepository
()

Get the repository storing the database's objects.

public RefUpdate.Result

Returns:

the status of the update.
getResult
()

Get the status of this update.

public boolean

Returns:

true if detaching a symref.
isDetachingSymbolicRef
()

Return whether this update is actually detaching a symbolic ref.

protected boolean

Returns:

whether force writing is enabled.
isForceRefLog
()

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

public boolean

Returns:

true if this update should ignore merge tests.
isForceUpdate
()

Check if this update wants to forcefully change the ref.

protected boolean

Returns:

true if the ref log message should show the result.
isRefLogIncludingResult
()

Whether the ref log message should show the result.

private void
private static RevObject
private static RevObject
public void
setCheckConflicting(boolean
whether to enable the check for conflicting ref names.
check
)

Enable/disable the check for conflicting ref names.

public void
setDetachingSymbolicRef()

Tells this RefUpdate that it is actually detaching a symbolic ref.

public void
setExpectedOldObjectId(AnyObjectId
the expected value of the ref after the lock is taken, but before update occurs. Null to avoid the compare and swap test. Use org.eclipse.jgit.lib.ObjectId#zeroId() to indicate expectation of a non-existant ref.
id
)

Set the expected value of the ref after the lock is taken, but before update occurs.

public void
setForceRefLog(boolean
whether to force.
force
)

Force writing a reflog for the updated ref.

public void
setForceUpdate(boolean
true if this update should ignore merge tests.
b
)

Set if this update wants to forcefully change the ref.

public void
setNewObjectId(AnyObjectId
the new value.
id
)

Set the new value the ref will update to.

protected void
setOldObjectId(ObjectId
the old value.
old
)

Set the old value of the ref.

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

Set a push certificate associated with this update.

public void
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 void
setRefLogMessage(String
the message to describe this change. It may be null if appendStatus is null in order not to append to the reflog
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.

protected abstract boolean

Returns:

true if the lock was acquired and the reference is likely protected from concurrent modification; false if it failed.
tryLock
(boolean
true if the lock should be taken against the leaf level reference; false if it should be taken exactly against the current reference.
deref
)

Try to acquire the lock on the reference.

protected abstract void
unlock()

Releases the lock taken by tryLock if it succeeded.

public RefUpdate.Result

Returns:

the result status of the update.
update
()

Gracefully update the ref to the new value.

public RefUpdate.Result

Returns:

the result status of the update.
update
(RevWalk
a RevWalk instance this update command can borrow to perform the merge test. The walk will be reset to perform the test.
walk
)

Gracefully update the ref to the new value.

private RefUpdate.Result
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkConflictingback to summary
private boolean checkConflicting
detachingSymbolicRefback to summary
private boolean detachingSymbolicRef

Is this RefUpdate detaching a symbolic ref? We need this info since this.ref will normally be peeled of in case of detaching a symbolic ref (HEAD for example). Without this flag we cannot decide whether the ref has to be updated or not in case when it was a symbolic ref and the newValue == oldValue.

expValueback to summary
private ObjectId expValue

If non-null, the value oldValue must have to continue.

forceback to summary
private boolean force

Does this specification ask for forced updated (rewind/reset)?

forceRefLogback to summary
private boolean forceRefLog

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

newValueback to summary
private ObjectId newValue

New value the caller wants this ref to have.

oldValueback to summary
private ObjectId oldValue

Old value of the ref, obtained after we lock it.

pushCertback to summary
private PushCertificate pushCert

Push certificate associated with this update.

refback to summary
private final Ref ref
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.

resultback to summary
private RefUpdate.Result result

Result of the update operation.

Constructor Detail

RefUpdateback to summary
protected RefUpdate(Ref ref)

Construct a new update operation for the reference.

ref.getObjectId() will be used to seed getOldObjectId(), which callers can use as part of their own update logic.

Parameters
ref:Ref

the reference that will be updated by this operation.

Method Detail

deleteback to summary
public RefUpdate.Result delete() throws IOException

Delete the ref.

This is the same as:

return delete(new RevWalk(getRepository()));
Returns:RefUpdate.Result

the result status of the delete.

Exceptions
IOException:
if an IO error occurred
deleteback to summary
public RefUpdate.Result delete(RevWalk walk) throws IOException

Delete the ref.

Parameters
walk:RevWalk

a RevWalk instance this delete command can borrow to perform the merge test. The walk will be reset to perform the test.

Returns:RefUpdate.Result

the result status of the delete.

Exceptions
IOException:
if an IO error occurred
disableRefLogback to summary
public void disableRefLog()

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

doDeleteback to summary
protected abstract RefUpdate.Result doDelete(RefUpdate.Result desiredResult) throws IOException

Do delete

Parameters
desiredResult:RefUpdate.Result

a org.eclipse.jgit.lib.RefUpdate.Result object.

Returns:RefUpdate.Result

result

Exceptions
IOException:
if an IO error occurred
doUpdateback to summary
protected abstract RefUpdate.Result doUpdate(RefUpdate.Result desiredResult) throws IOException

Do update

Parameters
desiredResult:RefUpdate.Result

a org.eclipse.jgit.lib.RefUpdate.Result object.

Returns:RefUpdate.Result

result

Exceptions
IOException:
if an IO error occurred
forceUpdateback to summary
public RefUpdate.Result forceUpdate() throws IOException

Force the ref to take the new value.

This is just a convenient helper for setting the force flag, and as such the merge test is performed.

Returns:RefUpdate.Result

the result status of the update.

Exceptions
IOException:
an unexpected IO error occurred while writing changes.
getExpectedOldObjectIdback to summary
public ObjectId getExpectedOldObjectId()

Get the expected value of the ref after the lock is taken, but before update occurs.

Returns:ObjectId

the expected value of the ref after the lock is taken, but before update occurs. Null to avoid the compare and swap test. Use org.eclipse.jgit.lib.ObjectId#zeroId() to indicate expectation of a non-existant ref.

getNameback to summary
public String getName()

Get the name of the ref this update will operate on.

Returns:String

name of underlying ref.

getNewObjectIdback to summary
public ObjectId getNewObjectId()

Get the new value the ref will be (or was) updated to.

Returns:ObjectId

new value. Null if the caller has not configured it.

getOldObjectIdback to summary
public ObjectId getOldObjectId()

The old value of the ref, prior to the update being attempted.

This value may differ before and after the update method. Initially it is populated with the value of the ref before the lock is taken, but the old value may change if someone else modified the ref between the time we last read it and when the ref was locked for update.

Returns:ObjectId

the value of the ref prior to the update being attempted; null if the updated has not been attempted yet.

getPushCertificateback to summary
protected PushCertificate getPushCertificate()

Set the push certificate associated with this update.

This usually includes a command to update this ref, but is not required to.

Returns:PushCertificate

push certificate, may be null.

Since
4.1
getRefback to summary
public Ref getRef()

Get the reference this update will create or modify.

Returns:Ref

the reference this update will create or modify.

getRefDatabaseback to summary
protected abstract RefDatabase getRefDatabase()

Get the reference database this update modifies.

Returns:RefDatabase

the reference database this update modifies.

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.

getRepositoryback to summary
protected abstract Repository getRepository()

Get the repository storing the database's objects.

Returns:Repository

the repository storing the database's objects.

getResultback to summary
public RefUpdate.Result getResult()

Get the status of this update.

The same value that was previously returned from an update method.

Returns:RefUpdate.Result

the status of the update.

isDetachingSymbolicRefback to summary
public boolean isDetachingSymbolicRef()

Return whether this update is actually detaching a symbolic ref.

Returns:boolean

true if detaching a symref.

Since
4.9
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
isForceUpdateback to summary
public boolean isForceUpdate()

Check if this update wants to forcefully change the ref.

Returns:boolean

true if this update should ignore merge tests.

isRefLogIncludingResultback to summary
protected boolean isRefLogIncludingResult()

Whether the ref log message should show the result.

Returns:boolean

true if the ref log message should show the result.

requireCanDoUpdateback to summary
private void requireCanDoUpdate()
safeParseNewback to summary
private static RevObject safeParseNew(RevWalk rw, AnyObjectId newId) throws IOException
safeParseOldback to summary
private static RevObject safeParseOld(RevWalk rw, AnyObjectId oldId) throws IOException
setCheckConflictingback to summary
public void setCheckConflicting(boolean check)

Enable/disable the check for conflicting ref names. By default conflicts are checked explicitly.

Parameters
check:boolean

whether to enable the check for conflicting ref names.

Since
3.0
setDetachingSymbolicRefback to summary
public void setDetachingSymbolicRef()

Tells this RefUpdate that it is actually detaching a symbolic ref.

setExpectedOldObjectIdback to summary
public void setExpectedOldObjectId(AnyObjectId id)

Set the expected value of the ref after the lock is taken, but before update occurs.

Parameters
id:AnyObjectId

the expected value of the ref after the lock is taken, but before update occurs. Null to avoid the compare and swap test. Use org.eclipse.jgit.lib.ObjectId#zeroId() to indicate expectation of a non-existant ref.

setForceRefLogback to summary
public void setForceRefLog(boolean force)

Force writing a reflog for the updated ref.

Parameters
force:boolean

whether to force.

Since
4.9
setForceUpdateback to summary
public void setForceUpdate(boolean b)

Set if this update wants to forcefully change the ref.

Parameters
b:boolean

true if this update should ignore merge tests.

setNewObjectIdback to summary
public void setNewObjectId(AnyObjectId id)

Set the new value the ref will update to.

Parameters
id:AnyObjectId

the new value.

setOldObjectIdback to summary
protected void setOldObjectId(ObjectId old)

Set the old value of the ref.

Parameters
old:ObjectId

the old value.

setPushCertificateback to summary
public void setPushCertificate(PushCertificate cert)

Set a push certificate associated with this update.

This usually includes a command to update this ref, but is not required to.

Parameters
cert:PushCertificate

push certificate, may be null.

Since
4.1
setRefLogIdentback to summary
public void 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.

setRefLogMessageback to summary
public void 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).

Parameters
msg:String

the message to describe this change. It may be null if appendStatus is null in order not to append to the reflog

appendStatus:boolean

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

tryLockback to summary
protected abstract boolean tryLock(boolean deref) throws IOException

Try to acquire the lock on the reference.

If the locking was successful the implementor must set the current identity value by calling setOldObjectId(ObjectId).

Parameters
deref:boolean

true if the lock should be taken against the leaf level reference; false if it should be taken exactly against the current reference.

Returns:boolean

true if the lock was acquired and the reference is likely protected from concurrent modification; false if it failed.

Exceptions
IOException:
the lock couldn't be taken due to an unexpected storage failure, and not because of a concurrent update.
unlockback to summary
protected abstract void unlock()

Releases the lock taken by tryLock if it succeeded.

updateback to summary
public RefUpdate.Result update() throws IOException

Gracefully update the ref to the new value.

Merge test will be performed according to isForceUpdate().

This is the same as:

return update(new RevWalk(getRepository()));
Returns:RefUpdate.Result

the result status of the update.

Exceptions
IOException:
an unexpected IO error occurred while writing changes.
updateback to summary
public RefUpdate.Result update(RevWalk walk) throws IOException

Gracefully update the ref to the new value.

Merge test will be performed according to isForceUpdate().

Parameters
walk:RevWalk

a RevWalk instance this update command can borrow to perform the merge test. The walk will be reset to perform the test.

Returns:RefUpdate.Result

the result status of the update.

Exceptions
IOException:
an unexpected IO error occurred while writing changes.
updateImplback to summary
private RefUpdate.Result updateImpl(RevWalk walk, RefUpdate.Store store) throws IOException
org.eclipse.jgit.lib back to summary

public final Enum RefUpdate.Result

extends Enum<RefUpdate.Result>
Class Inheritance

Status of an update request.

New values may be added to this enum in the future. Callers may assume that unknown values are failures, and may generally treat them the same as REJECTED_OTHER_REASON.

Field Summary

Modifier and TypeField and Description
public static final RefUpdate.Result
FAST_FORWARD

The ref was updated/deleted in a fast-forward way.

public static final RefUpdate.Result
FORCED

The ref had to be forcefully updated/deleted.

public static final RefUpdate.Result
IO_FAILURE

The ref was probably not updated/deleted because of I/O error.

public static final RefUpdate.Result
LOCK_FAILURE

The ref could not be locked for update/delete.

public static final RefUpdate.Result
NEW

The ref was created locally for an update, but ignored for delete.

public static final RefUpdate.Result
NO_CHANGE

Same value already stored.

public static final RefUpdate.Result
NOT_ATTEMPTED

The ref update/delete has not been attempted by the caller.

public static final RefUpdate.Result
REJECTED

Not a fast-forward and not stored.

public static final RefUpdate.Result
REJECTED_CURRENT_BRANCH

Rejected because trying to delete the current branch.

public static final RefUpdate.Result
REJECTED_MISSING_OBJECT

One or more objects aren't in the repository.

public static final RefUpdate.Result
REJECTED_OTHER_REASON

Rejected for some other reason not covered by another enum value.

public static final RefUpdate.Result
RENAMED

The ref was renamed from another name

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static RefUpdate.Result
public static RefUpdate.Result[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FAST_FORWARDback to summary
public static final RefUpdate.Result FAST_FORWARD

The ref was updated/deleted in a fast-forward way.

The tracking ref already existed and its old value was fully merged into the new value. No history was made unreachable.

FORCEDback to summary
public static final RefUpdate.Result FORCED

The ref had to be forcefully updated/deleted.

The ref already existed but its old value was not fully merged into the new value. The configuration permitted a forced update to take place, so ref now contains the new value. History associated with the objects not merged may no longer be reachable.

IO_FAILUREback to summary
public static final RefUpdate.Result IO_FAILURE

The ref was probably not updated/deleted because of I/O error.

Unexpected I/O error occurred when writing new ref. Such error may result in uncertain state, but most probably ref was not updated.

This kind of error doesn't include LOCK_FAILURE, which is a different case.

LOCK_FAILUREback to summary
public static final RefUpdate.Result LOCK_FAILURE

The ref could not be locked for update/delete.

This is generally a transient failure and is usually caused by another process trying to access the ref at the same time as this process was trying to update it. It is possible a future operation will be successful.

NEWback to summary
public static final RefUpdate.Result NEW

The ref was created locally for an update, but ignored for delete.

The ref did not exist when the update started, but it was created successfully with the new value.

NO_CHANGEback to summary
public static final RefUpdate.Result NO_CHANGE

Same value already stored.

Both the old value and the new value are identical. No change was necessary for an update. For delete the branch is removed.

NOT_ATTEMPTEDback to summary
public static final RefUpdate.Result NOT_ATTEMPTED

The ref update/delete has not been attempted by the caller.

REJECTEDback to summary
public static final RefUpdate.Result REJECTED

Not a fast-forward and not stored.

The tracking ref already existed but its old value was not fully merged into the new value. The configuration did not allow a forced update/delete to take place, so ref still contains the old value. No previous history was lost.

Note

Despite the general name, this result only refers to the non-fast-forward case. For more general errors, see REJECTED_OTHER_REASON.

REJECTED_CURRENT_BRANCHback to summary
public static final RefUpdate.Result REJECTED_CURRENT_BRANCH

Rejected because trying to delete the current branch.

Has no meaning for update.

REJECTED_MISSING_OBJECTback to summary
public static final RefUpdate.Result REJECTED_MISSING_OBJECT

One or more objects aren't in the repository.

This is severe indication of either repository corruption on the server side, or a bug in the client wherein the client did not supply all required objects during the pack transfer.

Since
4.9
REJECTED_OTHER_REASONback to summary
public static final RefUpdate.Result REJECTED_OTHER_REASON

Rejected for some other reason not covered by another enum value.

Since
4.9
RENAMEDback to summary
public static final RefUpdate.Result RENAMED

The ref was renamed from another name

Constructor Detail

Resultback to summary
private Result()

Method Detail

valueOfback to summary
public static RefUpdate.Result valueOf(String name)
valuesback to summary
public static RefUpdate.Result[] values()
org.eclipse.jgit.lib back to summary

private abstract Class RefUpdate.Store

extends Object
Class Inheritance

Handle the abstraction of storing a ref update. This is because both updating and deleting of a ref have merge testing in common.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract RefUpdate.Result
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Storeback to summary
private Store()

Method Detail

executeback to summary
pack-priv abstract RefUpdate.Result execute(RefUpdate.Result status) throws IOException