Class SymbolicRef

java.lang.Object
org.eclipse.jgit.lib.SymbolicRef
All Implemented Interfaces:
Ref
Direct Known Subclasses:
RefDirectory.LooseSymbolicRef

public class SymbolicRef extends Object implements Ref
A reference that indirectly points at another Ref.

A symbolic reference always derives its current value from the target reference.

  • Field Details

    • name

      private final String name
    • target

      private final Ref target
    • updateIndex

      private final long updateIndex
  • Constructor Details

    • SymbolicRef

      public SymbolicRef(@NonNull String refName, @NonNull Ref target)
      Create a new ref pairing.
      Parameters:
      refName - name of this ref.
      target - the ref we reference and derive our value from.
    • SymbolicRef

      public SymbolicRef(@NonNull String refName, @NonNull Ref target, long updateIndex)
      Create a new ref pairing.
      Parameters:
      refName - name of this ref.
      target - the ref we reference and derive our value from.
      updateIndex - index that increases with each update of the reference
      Since:
      5.3
  • Method Details

    • getName

      @NonNull public String getName()
      What this ref is called within the repository.
      Specified by:
      getName in interface Ref
      Returns:
      name of this ref.
    • isSymbolic

      public boolean isSymbolic()
      Test if this reference is a symbolic reference.

      A symbolic reference does not have its own ObjectId value, but instead points to another Ref in the same database and always uses that other reference's value as its own.

      Specified by:
      isSymbolic in interface Ref
      Returns:
      true if this is a symbolic reference; false if this reference contains its own ObjectId.
    • getLeaf

      @NonNull public Ref getLeaf()
      Traverse target references until Ref.isSymbolic() is false.

      If Ref.isSymbolic() is false, returns this.

      If Ref.isSymbolic() is true, this method recursively traverses Ref.getTarget() until Ref.isSymbolic() returns false.

      This method is effectively

       return isSymbolic() ? getTarget().getLeaf() : this;
       
      Specified by:
      getLeaf in interface Ref
      Returns:
      the reference that actually stores the ObjectId value.
    • getTarget

      @NonNull public Ref getTarget()
      Get the reference this reference points to, or this.

      If Ref.isSymbolic() is true this method returns the reference it directly names, which might not be the leaf reference, but could be another symbolic reference.

      If this is a leaf level reference that contains its own ObjectId,this method returns this.

      Specified by:
      getTarget in interface Ref
      Returns:
      the target reference, or this.
    • getObjectId

      @Nullable public ObjectId getObjectId()
      Cached value of this ref.
      Specified by:
      getObjectId in interface Ref
      Returns:
      the value of this ref at the last time we read it. May be null to indicate a ref that does not exist yet or a symbolic ref pointing to an unborn branch.
    • getStorage

      @NonNull public Ref.Storage getStorage()
      How was this ref obtained?

      The current storage model of a Ref may influence how the ref must be updated or deleted from the repository.

      Specified by:
      getStorage in interface Ref
      Returns:
      type of ref.
    • getPeeledObjectId

      @Nullable public ObjectId getPeeledObjectId()
      Cached value of ref^{} (the ref peeled to commit).
      Specified by:
      getPeeledObjectId in interface Ref
      Returns:
      if this ref is an annotated tag the id of the commit (or tree or blob) that the annotated tag refers to; null if this ref does not refer to an annotated tag.
    • isPeeled

      public boolean isPeeled()
      Whether the Ref represents a peeled tag.
      Specified by:
      isPeeled in interface Ref
      Returns:
      whether the Ref represents a peeled tag.
    • getUpdateIndex

      public long getUpdateIndex()
      Indicator of the relative order between updates of a specific reference name. A number that increases when a reference is updated.

      With symbolic references, the update index refers to updates of the symbolic reference itself. For example, if HEAD points to refs/heads/master, then the update index for exactRef("HEAD") will only increase when HEAD changes to point to another ref, regardless of how many times refs/heads/master is updated.

      Should not be used unless the RefDatabase that instantiated the ref supports versioning (see RefDatabase.hasVersioning())

      Specified by:
      getUpdateIndex in interface Ref
      Returns:
      the update index (i.e. version) of this reference.
      Since:
      5.3
    • toString

      public String toString()
      Overrides:
      toString in class Object