public abstract class RefUpdate extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RefUpdate.Result
Status of an update request.
|
Modifier | Constructor and Description |
---|---|
protected |
RefUpdate(Ref ref)
Construct a new update operation for the reference.
|
Modifier and Type | Method and Description |
---|---|
RefUpdate.Result |
delete()
Delete the ref.
|
RefUpdate.Result |
delete(RevWalk walk)
Delete the ref.
|
void |
disableRefLog()
Don't record this update in the ref's associated reflog.
|
protected abstract RefUpdate.Result |
doDelete(RefUpdate.Result desiredResult)
Do delete
|
protected abstract RefUpdate.Result |
doLink(String target)
Do link
|
protected abstract RefUpdate.Result |
doUpdate(RefUpdate.Result desiredResult)
Do update
|
RefUpdate.Result |
forceUpdate()
Force the ref to take the new value.
|
ObjectId |
getExpectedOldObjectId()
Get the expected value of the ref after the lock is taken, but before
update occurs.
|
String |
getName()
Get the name of the ref this update will operate on.
|
ObjectId |
getNewObjectId()
Get the new value the ref will be (or was) updated to.
|
ObjectId |
getOldObjectId()
The old value of the ref, prior to the update being attempted.
|
protected PushCertificate |
getPushCertificate()
Set the push certificate associated with this update.
|
Ref |
getRef()
Get the reference this update will create or modify.
|
protected abstract RefDatabase |
getRefDatabase()
Get the reference database this update modifies.
|
PersonIdent |
getRefLogIdent()
Get identity of the user making the change in the reflog.
|
String |
getRefLogMessage()
Get the message to include in the reflog.
|
protected abstract Repository |
getRepository()
Get the repository storing the database's objects.
|
RefUpdate.Result |
getResult()
Get the status of this update.
|
boolean |
isDetachingSymbolicRef()
Return whether this update is actually detaching a symbolic ref.
|
protected boolean |
isForceRefLog()
Check whether the reflog should be written regardless of repo defaults.
|
boolean |
isForceUpdate()
Check if this update wants to forcefully change the ref.
|
protected boolean |
isRefLogIncludingResult()
Whether the ref log message should show the result.
|
RefUpdate.Result |
link(String target)
Replace this reference with a symbolic reference to another reference.
|
void |
setCheckConflicting(boolean check)
Enable/disable the check for conflicting ref names.
|
void |
setDetachingSymbolicRef()
Tells this RefUpdate that it is actually detaching a symbolic ref.
|
void |
setExpectedOldObjectId(AnyObjectId id)
Set the expected value of the ref after the lock is taken, but before
update occurs.
|
void |
setForceRefLog(boolean force)
Force writing a reflog for the updated ref.
|
void |
setForceUpdate(boolean b)
Set if this update wants to forcefully change the ref.
|
void |
setNewObjectId(AnyObjectId id)
Set the new value the ref will update to.
|
protected void |
setOldObjectId(ObjectId old)
Set the old value of the ref.
|
void |
setPushCertificate(PushCertificate cert)
Set a push certificate associated with this update.
|
void |
setRefLogIdent(PersonIdent pi)
Set the identity of the user appearing in the reflog.
|
void |
setRefLogMessage(String msg,
boolean appendStatus)
Set the message to include in the reflog.
|
protected abstract boolean |
tryLock(boolean deref)
Try to acquire the lock on the reference.
|
protected abstract void |
unlock()
Releases the lock taken by
tryLock(boolean) if it succeeded. |
RefUpdate.Result |
update()
Gracefully update the ref to the new value.
|
RefUpdate.Result |
update(RevWalk walk)
Gracefully update the ref to the new value.
|
protected RefUpdate(Ref ref)
ref.getObjectId()
will be used to seed getOldObjectId()
,
which callers can use as part of their own update logic.
ref
- the reference that will be updated by this operation.protected abstract RefDatabase getRefDatabase()
protected abstract Repository getRepository()
protected abstract boolean tryLock(boolean deref) throws IOException
If the locking was successful the implementor must set the current
identity value by calling setOldObjectId(ObjectId)
.
deref
- true if the lock should be taken against the leaf level
reference; false if it should be taken exactly against the
current reference.IOException
- the lock couldn't be taken due to an unexpected storage
failure, and not because of a concurrent update.protected abstract void unlock()
tryLock(boolean)
if it succeeded.protected abstract RefUpdate.Result doUpdate(RefUpdate.Result desiredResult) throws IOException
desiredResult
- a RefUpdate.Result
object.result
IOException
protected abstract RefUpdate.Result doDelete(RefUpdate.Result desiredResult) throws IOException
desiredResult
- a RefUpdate.Result
object.result
IOException
protected abstract RefUpdate.Result doLink(String target) throws IOException
target
- a String
object.RefUpdate.Result.NEW
on success.IOException
public String getName()
public Ref getRef()
public ObjectId getNewObjectId()
public void setDetachingSymbolicRef()
public boolean isDetachingSymbolicRef()
public void setNewObjectId(AnyObjectId id)
id
- the new value.public ObjectId getExpectedOldObjectId()
ObjectId.zeroId()
to indicate
expectation of a non-existant ref.public void setExpectedOldObjectId(AnyObjectId id)
id
- the expected value of the ref after the lock is taken, but
before update occurs. Null to avoid the compare and swap test.
Use ObjectId.zeroId()
to indicate
expectation of a non-existant ref.public boolean isForceUpdate()
public void setForceUpdate(boolean b)
b
- true if this update should ignore merge tests.public PersonIdent getRefLogIdent()
public void 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.public String getRefLogMessage()
protected boolean isRefLogIncludingResult()
true
if the ref log message should show the result.public void 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)
.
msg
- the message to describe this change. It may be null if
appendStatus is null in order not to append to the reflogappendStatus
- true if the status of the ref change (fast-forward or
forced-update) should be appended to the user supplied
message.public void disableRefLog()
public void setForceRefLog(boolean force)
force
- whether to force.protected boolean isForceRefLog()
public ObjectId getOldObjectId()
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.
protected void setOldObjectId(ObjectId old)
old
- the old value.public void setPushCertificate(PushCertificate cert)
This usually includes a command to update this ref, but is not required to.
cert
- push certificate, may be null.protected PushCertificate getPushCertificate()
This usually includes a command to update this ref, but is not required to.
public RefUpdate.Result getResult()
The same value that was previously returned from an update method.
public RefUpdate.Result forceUpdate() throws IOException
This is just a convenient helper for setting the force flag, and as such the merge test is performed.
IOException
- an unexpected IO error occurred while writing changes.public RefUpdate.Result update() throws IOException
Merge test will be performed according to isForceUpdate()
.
This is the same as:
return update(new RevWalk(getRepository()));
IOException
- an unexpected IO error occurred while writing changes.public RefUpdate.Result update(RevWalk walk) throws IOException
Merge test will be performed according to isForceUpdate()
.
walk
- a RevWalk instance this update command can borrow to perform
the merge test. The walk will be reset to perform the test.IOException
- an unexpected IO error occurred while writing changes.public RefUpdate.Result delete() throws IOException
This is the same as:
return delete(new RevWalk(getRepository()));
IOException
public RefUpdate.Result delete(RevWalk walk) throws IOException
walk
- a RevWalk instance this delete command can borrow to perform
the merge test. The walk will be reset to perform the test.IOException
public RefUpdate.Result link(String target) throws IOException
This exact reference (not its traversed leaf) is replaced with a symbolic reference to the requested name.
target
- name of the new target for this reference. The new target name
must be absolute, so it must begin with refs/
.RefUpdate.Result.NEW
or
RefUpdate.Result.FORCED
on success.IOException
public void setCheckConflicting(boolean check)
check
- whether to enable the check for conflicting ref names.Copyright © 2019 Eclipse JGit Project. All rights reserved.