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

public Interface Ref

Known Direct Subinterfaces
org.eclipse.jgit.internal.storage.file.RefDirectory.LooseRef
Known Direct Implementers
org.eclipse.jgit.lib.SymbolicRef, org.eclipse.jgit.lib.ObjectIdRef
Imports
org.eclipse.jgit.annotations.NonNull, .Nullable

Pairing of a name and the org.eclipse.jgit.lib.ObjectId it currently has.

A ref in Git is (more or less) a variable that holds a single object identifier. The object identifier can be any valid Git object (blob, tree, commit, annotated tag, ...).

The ref name has the attributes of the ref that was asked for as well as the ref it was resolved to for symbolic refs plus the object id it points to and (for tags) the peeled target object id, i.e. the tag resolved recursively until a non-tag object is referenced.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Ref.Storage

Location where a Ref is stored.

Field Summary

Modifier and TypeField and Description
public static final long
UNDEFINED_UPDATE_INDEX

Update index value when a reference doesn't have one

Method Summary

Modifier and TypeMethod and Description
public Ref

Returns:

the reference that actually stores the ObjectId value.
getLeaf
()

Traverse target references until isSymbolic() is false.

public String

Returns:

name of this ref.
getName
()

What this ref is called within the repository.

public ObjectId

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.
getObjectId
()

Cached value of this ref.

public ObjectId

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.
getPeeledObjectId
()

Cached value of ref^{} (the ref peeled to commit).

public Ref.Storage

Returns:

type of ref.
getStorage
()

How was this ref obtained?

public Ref

Returns:

the target reference, or this.
getTarget
()

Get the reference this reference points to, or this.

public default long

Returns:

the update index (i.e. version) of this reference.
getUpdateIndex
()

Indicator of the relative order between updates of a specific reference name.

public boolean

Returns:

whether the Ref represents a peeled tag.
isPeeled
()

Whether the Ref represents a peeled tag.

public boolean

Returns:

true if this is a symbolic reference; false if this reference contains its own ObjectId.
isSymbolic
()

Test if this reference is a symbolic reference.

Field Detail

UNDEFINED_UPDATE_INDEXback to summary
public static final long UNDEFINED_UPDATE_INDEX

Update index value when a reference doesn't have one

Since
5.4

Method Detail

getLeafback to summary
public Ref getLeaf()

Traverse target references until isSymbolic() is false.

If isSymbolic() is false, returns this.

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

This method is effectively

return isSymbolic() ? getTarget().getLeaf() : this;
Returns:Ref

the reference that actually stores the ObjectId value.

Annotations
@NonNull
getNameback to summary
public String getName()

What this ref is called within the repository.

Returns:String

name of this ref.

Annotations
@NonNull
getObjectIdback to summary
public ObjectId getObjectId()

Cached value of this ref.

Returns:ObjectId

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.

Annotations
@Nullable
getPeeledObjectIdback to summary
public ObjectId getPeeledObjectId()

Cached value of ref^{} (the ref peeled to commit).

Returns:ObjectId

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.

Annotations
@Nullable
getStorageback to summary
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.

Returns:Ref.Storage

type of ref.

Annotations
@NonNull
getTargetback to summary
public Ref getTarget()

Get the reference this reference points to, or this.

If 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.

Returns:Ref

the target reference, or this.

Annotations
@NonNull
getUpdateIndexback to summary
public default 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())

Returns:long

the update index (i.e. version) of this reference.

Exceptions
UnsupportedOperationException:
if the creator of the instance (e.g. RefDatabase) doesn't support versioning and doesn't override this method
Since
5.3
isPeeledback to summary
public boolean isPeeled()

Whether the Ref represents a peeled tag.

Returns:boolean

whether the Ref represents a peeled tag.

isSymbolicback to summary
public boolean isSymbolic()

Test if this reference is a symbolic reference.

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

Returns:boolean

true if this is a symbolic reference; false if this reference contains its own ObjectId.

org.eclipse.jgit.lib back to summary

public final Enum Ref.Storage

extends Enum<Ref.Storage>
Class Inheritance

Location where a Ref is stored.

Field Summary

Modifier and TypeField and Description
public static final Ref.Storage
LOOSE

The ref is stored in a file by itself.

private final boolean
public static final Ref.Storage
LOOSE_PACKED

The ref is both LOOSE and PACKED.

public static final Ref.Storage
NETWORK

The ref came from a network advertisement and storage is unknown.

public static final Ref.Storage
NEW

The ref does not exist yet, updating it may create it.

public static final Ref.Storage
PACKED

The ref is stored in the packed-refs file, with others.

private final boolean

Constructor Summary

AccessConstructor and Description
private
Storage(boolean l, boolean p)

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this storage has a loose file.
isLoose
()

Whether this storage has a loose file

public boolean

Returns:

true if this storage is inside the packed file.
isPacked
()

Whether this storage is inside the packed file

public static Ref.Storage
public static Ref.Storage[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LOOSEback to summary
public static final Ref.Storage LOOSE

The ref is stored in a file by itself.

Updating this ref affects only this ref.

looseback to summary
private final boolean loose
LOOSE_PACKEDback to summary
public static final Ref.Storage LOOSE_PACKED

The ref is both LOOSE and PACKED.

Updating this ref requires only updating the loose file, but deletion requires updating both the loose file and the packed refs file.

NETWORKback to summary
public static final Ref.Storage NETWORK

The ref came from a network advertisement and storage is unknown.

This ref cannot be updated without Git-aware support on the remote side, as Git-aware code consolidate the remote refs and reported them to this process.

NEWback to summary
public static final Ref.Storage NEW

The ref does not exist yet, updating it may create it.

Creation is likely to choose LOOSE storage.

PACKEDback to summary
public static final Ref.Storage PACKED

The ref is stored in the packed-refs file, with others.

Updating this ref requires rewriting the file, with perhaps many other refs being included at the same time.

packedback to summary
private final boolean packed

Constructor Detail

Storageback to summary
private Storage(boolean l, boolean p)

Method Detail

isLooseback to summary
public boolean isLoose()

Whether this storage has a loose file

Returns:boolean

true if this storage has a loose file.

isPackedback to summary
public boolean isPacked()

Whether this storage is inside the packed file

Returns:boolean

true if this storage is inside the packed file.

valueOfback to summary
public static Ref.Storage valueOf(String name)
valuesback to summary
public static Ref.Storage[] values()