Class RefTree
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.reftree.RefTree
-
public class RefTree extends java.lang.ObjectTree of references in the reference graph.The root corresponds to the
"refs/"subdirectory, for example the default reference"refs/heads/master"is stored at path"heads/master"in aRefTree.Normal references are stored as
FileMode.GITLINKtree entries. The ObjectId in the tree entry is the ObjectId the reference refers to.Symbolic references are stored as
FileMode.SYMLINKentries, with the blob storing the name of the target reference.Annotated tags also store the peeled object using a
GITLINKentry with the suffix" ^"(space carrot), for example"tags/v1.0"stores the annotated tag object, while"tags/v1.0 ^"stores the commit the tag annotates.HEADis a special case and stored as"..HEAD".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classRefTree.LockFailureException
-
Field Summary
Fields Modifier and Type Field Description private DirCachecontentsstatic java.lang.StringPEELED_SUFFIXSuffix applied to GITLINK to indicate its the peeled value of a tag.private java.util.Map<ObjectId,java.lang.String>pendingBlobs(package private) static java.lang.StringROOT_DOTDOT
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanapply(java.util.Collection<Command> cmdList)Attempt a batch of commands against this RefTree.private voidapply(DirCacheEditor ed, Command cmd)private static voidcheckRef(DirCacheEntry ent, Command cmd)private static voidcleanupPeeledRef(DirCacheEditor ed, Ref ref)RefTreecopy()Create a deep copy of this RefTree.RefexactRef(ObjectReader reader, java.lang.String name)Read one reference.private static booleanisValidRef(Command cmd)static RefTreenewEmptyTree()Create an empty reference tree.private static java.lang.StringpeeledPath(java.lang.String name)static RefTreeread(ObjectReader reader, RevTree tree)Load a reference tree.private RefreadRef(ObjectReader reader, java.lang.String name)static java.lang.StringrefName(java.lang.String path)Convert a path name in a RefTree to the reference name known by Git.(package private) static java.lang.StringrefPath(java.lang.String name)private Refresolve(ObjectReader reader, Ref ref, int depth)private ReftoRef(ObjectReader reader, DirCacheEntry e, java.lang.String name)ObjectIdwriteTree(ObjectInserter inserter)Write this reference tree.
-
-
-
Field Detail
-
PEELED_SUFFIX
public static final java.lang.String PEELED_SUFFIX
Suffix applied to GITLINK to indicate its the peeled value of a tag.- See Also:
- Constant Field Values
-
ROOT_DOTDOT
static final java.lang.String ROOT_DOTDOT
- See Also:
- Constant Field Values
-
contents
private DirCache contents
-
pendingBlobs
private java.util.Map<ObjectId,java.lang.String> pendingBlobs
-
-
Constructor Detail
-
RefTree
private RefTree(DirCache dc)
-
-
Method Detail
-
newEmptyTree
public static RefTree newEmptyTree()
Create an empty reference tree.- Returns:
- a new empty reference tree.
-
read
public static RefTree read(ObjectReader reader, RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, java.io.IOException
Load a reference tree.- Parameters:
reader- reader to scan the reference tree with.tree- the tree to read.- Returns:
- the ref tree read from the commit.
- Throws:
java.io.IOException- the repository cannot be accessed through the reader.CorruptObjectException- a tree object is corrupt and cannot be read.IncorrectObjectTypeException- a tree object wasn't actually a tree.MissingObjectException- a reference tree object doesn't exist.
-
exactRef
@Nullable public Ref exactRef(ObjectReader reader, java.lang.String name) throws java.io.IOException
Read one reference.References are always returned peeled (
Ref.isPeeled()is true). If the reference points to an annotated tag, the returned reference will be peeled and containRef.getPeeledObjectId().If the reference is a symbolic reference and the chain depth is less than
RefDatabase.MAX_SYMBOLIC_REF_DEPTHthe returned reference is resolved. If the chain depth is longer, the symbolic reference is returned without resolving.- Parameters:
reader- to access objects necessary to read the requested reference.name- name of the reference to read.- Returns:
- the reference; null if it does not exist.
- Throws:
java.io.IOException- cannot read a symbolic reference target.
-
readRef
private Ref readRef(ObjectReader reader, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
toRef
private Ref toRef(ObjectReader reader, DirCacheEntry e, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
resolve
private Ref resolve(ObjectReader reader, Ref ref, int depth) throws java.io.IOException
- Throws:
java.io.IOException
-
apply
public boolean apply(java.util.Collection<Command> cmdList)
Attempt a batch of commands against this RefTree.The batch is applied atomically, either all commands apply at once, or they all reject and the RefTree is left unmodified.
On success (when this method returns
true) the command results are left as-is (probablyNOT_ATTEMPTED). Result fields are set only when this method returnsfalseto indicate failure.- Parameters:
cmdList- to apply. All commands should still have result NOT_ATTEMPTED.- Returns:
- true if the commands applied; false if they were rejected.
-
isValidRef
private static boolean isValidRef(Command cmd)
-
apply
private void apply(DirCacheEditor ed, Command cmd)
-
checkRef
private static void checkRef(@Nullable DirCacheEntry ent, Command cmd)
-
cleanupPeeledRef
private static void cleanupPeeledRef(DirCacheEditor ed, Ref ref)
-
refName
public static java.lang.String refName(java.lang.String path)
Convert a path name in a RefTree to the reference name known by Git.- Parameters:
path- name read from the RefTree structure, for example"heads/master".- Returns:
- reference name for the path,
"refs/heads/master".
-
refPath
static java.lang.String refPath(java.lang.String name)
-
peeledPath
private static java.lang.String peeledPath(java.lang.String name)
-
writeTree
public ObjectId writeTree(ObjectInserter inserter) throws java.io.IOException
Write this reference tree.- Parameters:
inserter- inserter to use when writing trees to the object database. Caller is responsible for flushing the inserter before trying to read the objects, or exposing them through a reference.- Returns:
- the top level tree.
- Throws:
java.io.IOException- a tree could not be written.
-
copy
public RefTree copy()
Create a deep copy of this RefTree.- Returns:
- a deep copy of this RefTree.
-
-