org.eclipse.jgit.lib
Class RefUpdate

java.lang.Object
  extended by org.eclipse.jgit.lib.RefUpdate

public class RefUpdate
extends java.lang.Object

Updates any locally stored ref.


Nested Class Summary
static class RefUpdate.Result
          Status of an update request.
 
Method Summary
 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.
 RefUpdate.Result forceUpdate()
          Force the ref to take the new value.
 ObjectId getExpectedOldObjectId()
           
 java.lang.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.
 java.lang.String getOrigName()
          Get the requested name of the ref thit update will operate on
 PersonIdent getRefLogIdent()
           
 java.lang.String getRefLogMessage()
          Get the message to include in the reflog.
 Repository getRepository()
           
 RefUpdate.Result getResult()
          Get the status of this update.
 boolean isForceUpdate()
          Check if this update wants to forcefully change the ref.
 void setExpectedOldObjectId(AnyObjectId id)
           
 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.
 void setRefLogIdent(PersonIdent pi)
          Set the identity of the user appearing in the reflog.
 void setRefLogMessage(java.lang.String msg, boolean appendStatus)
          Set the message to include in the reflog.
 RefUpdate.Result update()
          Gracefully update the ref to the new value.
 RefUpdate.Result update(RevWalk walk)
          Gracefully update the ref to the new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRepository

public Repository getRepository()
Returns:
the repository the updated ref resides in

getName

public java.lang.String getName()
Get the name of the ref this update will operate on.

Returns:
name of underlying ref.

getOrigName

public java.lang.String getOrigName()
Get the requested name of the ref thit update will operate on

Returns:
original (requested) name of the underlying ref.

getNewObjectId

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

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

setNewObjectId

public void setNewObjectId(AnyObjectId id)
Set the new value the ref will update to.

Parameters:
id - the new value.

getExpectedOldObjectId

public ObjectId getExpectedOldObjectId()
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 ObjectId.zeroId() to indicate expectation of a non-existant ref.

setExpectedOldObjectId

public void setExpectedOldObjectId(AnyObjectId id)
Parameters:
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.

isForceUpdate

public boolean isForceUpdate()
Check if this update wants to forcefully change the ref.

Returns:
true if this update should ignore merge tests.

setForceUpdate

public void setForceUpdate(boolean b)
Set if this update wants to forcefully change the ref.

Parameters:
b - true if this update should ignore merge tests.

getRefLogIdent

public PersonIdent getRefLogIdent()
Returns:
identity of the user making the change in the reflog.

setRefLogIdent

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 - identity of the user. If null the identity will be automatically determined based on the repository configuration.

getRefLogMessage

public java.lang.String 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.

setRefLogMessage

public void setRefLogMessage(java.lang.String msg,
                             boolean appendStatus)
Set the message to include in the reflog.

Parameters:
msg - the message to describe this change. It may be null if appendStatus is null in order not to append to the reflog
appendStatus - true if the status of the ref change (fast-forward or forced-update) should be appended to the user supplied message.

disableRefLog

public void disableRefLog()
Don't record this update in the ref's associated reflog.


getOldObjectId

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:
the value of the ref prior to the update being attempted; null if the updated has not been attempted yet.

getResult

public RefUpdate.Result getResult()
Get the status of this update.

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

Returns:
the status of the update.

forceUpdate

public RefUpdate.Result forceUpdate()
                             throws java.io.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:
the result status of the update.
Throws:
java.io.IOException - an unexpected IO error occurred while writing changes.

update

public RefUpdate.Result update()
                        throws java.io.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(repository));
 

Returns:
the result status of the update.
Throws:
java.io.IOException - an unexpected IO error occurred while writing changes.

update

public RefUpdate.Result update(RevWalk walk)
                        throws java.io.IOException
Gracefully update the ref to the new value.

Merge test will be performed according to isForceUpdate().

Parameters:
walk - a RevWalk instance this update command can borrow to perform the merge test. The walk will be reset to perform the test.
Returns:
the result status of the update.
Throws:
java.io.IOException - an unexpected IO error occurred while writing changes.

delete

public RefUpdate.Result delete()
                        throws java.io.IOException
Delete the ref.

This is the same as:

 return delete(new RevWalk(repository));
 

Returns:
the result status of the delete.
Throws:
java.io.IOException

delete

public RefUpdate.Result delete(RevWalk walk)
                        throws java.io.IOException
Delete the ref.

Parameters:
walk - a RevWalk instance this delete command can borrow to perform the merge test. The walk will be reset to perform the test.
Returns:
the result status of the delete.
Throws:
java.io.IOException