org.eclipse.jgit.lib
Class Tree

java.lang.Object
  extended by org.eclipse.jgit.lib.TreeEntry
      extended by org.eclipse.jgit.lib.Tree
All Implemented Interfaces:
java.lang.Comparable, Treeish

public class Tree
extends TreeEntry
implements Treeish

A representation of a Git tree entry. A Tree is a directory in Git.


Field Summary
 
Fields inherited from class org.eclipse.jgit.lib.TreeEntry
CONCURRENT_MODIFICATION, LOADED_ONLY, MODIFIED_ONLY
 
Constructor Summary
Tree(Repository repo)
          Constructor for a new Tree
Tree(Repository repo, ObjectId myId, byte[] raw)
          Construct a Tree object with known content and hash value
Tree(Tree parent, byte[] nameUTF8)
          Construct a new Tree under another Tree
Tree(Tree parent, ObjectId id, byte[] nameUTF8)
          Construct a Tree with a known SHA-1 under another tree.
 
Method Summary
 void accept(TreeVisitor tv, int flags)
          Visit the members of this TreeEntry.
 void addEntry(TreeEntry e)
          Add the specified tree entry to this tree.
 FileTreeEntry addFile(byte[] s, int offset)
          Adds a new or existing file with the specified name to this tree.
 FileTreeEntry addFile(java.lang.String name)
          Adds a new or existing file with the specified name to this tree.
 Tree addTree(byte[] s, int offset)
          Adds a new or existing Tree with the specified name to this tree.
 Tree addTree(java.lang.String name)
          Adds a new or existing Tree with the specified name to this tree.
static int compareNames(byte[] a, byte[] b, int lasta, int lastb)
          Compare two names represented as bytes.
 boolean existsBlob(java.lang.String path)
           
 boolean existsTree(java.lang.String path)
           
 TreeEntry findBlobMember(java.lang.String s)
           
 TreeEntry findTreeMember(java.lang.String s)
           
 FileMode getMode()
           
 Repository getRepository()
           
 Tree getTree()
           
 ObjectId getTreeId()
           
 boolean isLoaded()
           
 boolean isRoot()
           
 int memberCount()
           
 TreeEntry[] members()
          Return all members of the tree sorted in Git order.
 java.lang.String toString()
           
 void unload()
          Forget the in-memory data for this tree.
 
Methods inherited from class org.eclipse.jgit.lib.TreeEntry
accept, compareTo, delete, detachParent, getFullName, getFullNameUTF8, getId, getName, getNameUTF8, getParent, isModified, lastChar, lastChar, rename, rename, setId, setModified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tree

public Tree(Repository repo)
Constructor for a new Tree

Parameters:
repo - The repository that owns the Tree.

Tree

public Tree(Repository repo,
            ObjectId myId,
            byte[] raw)
     throws java.io.IOException
Construct a Tree object with known content and hash value

Parameters:
repo -
myId -
raw -
Throws:
java.io.IOException

Tree

public Tree(Tree parent,
            byte[] nameUTF8)
Construct a new Tree under another Tree

Parameters:
parent -
nameUTF8 -

Tree

public Tree(Tree parent,
            ObjectId id,
            byte[] nameUTF8)
Construct a Tree with a known SHA-1 under another tree. Data is not yet specified and will have to be loaded on demand.

Parameters:
parent -
id -
nameUTF8 -
Method Detail

compareNames

public static final int compareNames(byte[] a,
                                     byte[] b,
                                     int lasta,
                                     int lastb)
Compare two names represented as bytes. Since git treats names of trees and blobs differently we have one parameter that represents a '/' for trees. For other objects the value should be NUL. The names are compare by their positive byte value (0..255). A blob and a tree with the same name will not compare equal.

Parameters:
a - name
b - name
lasta - '/' if a is a tree, else NUL
lastb - '/' if b is a tree, else NUL
Returns:
< 0 if a is sorted before b, 0 if they are the same, else b

getMode

public FileMode getMode()
Specified by:
getMode in class TreeEntry
Returns:
mode (type of object)

isRoot

public boolean isRoot()
Returns:
true if this Tree is the top level Tree.

getRepository

public Repository getRepository()
Overrides:
getRepository in class TreeEntry
Returns:
the repository owning this entry.

getTreeId

public final ObjectId getTreeId()
Specified by:
getTreeId in interface Treeish
Returns:
the id of this tree

getTree

public final Tree getTree()
Specified by:
getTree in interface Treeish
Returns:
the tree of this tree-ish object

isLoaded

public boolean isLoaded()
Returns:
true of the data of this Tree is loaded

unload

public void unload()
Forget the in-memory data for this tree.


addFile

public FileTreeEntry addFile(java.lang.String name)
                      throws java.io.IOException
Adds a new or existing file with the specified name to this tree. Trees are added if necessary as the name may contain '/':s.

Parameters:
name - Name
Returns:
a FileTreeEntry for the added file.
Throws:
java.io.IOException

addFile

public FileTreeEntry addFile(byte[] s,
                             int offset)
                      throws java.io.IOException
Adds a new or existing file with the specified name to this tree. Trees are added if necessary as the name may contain '/':s.

Parameters:
s - an array containing the name
offset - when the name starts in the tree.
Returns:
a FileTreeEntry for the added file.
Throws:
java.io.IOException

addTree

public Tree addTree(java.lang.String name)
             throws java.io.IOException
Adds a new or existing Tree with the specified name to this tree. Trees are added if necessary as the name may contain '/':s.

Parameters:
name - Name
Returns:
a FileTreeEntry for the added tree.
Throws:
java.io.IOException

addTree

public Tree addTree(byte[] s,
                    int offset)
             throws java.io.IOException
Adds a new or existing Tree with the specified name to this tree. Trees are added if necessary as the name may contain '/':s.

Parameters:
s - an array containing the name
offset - when the name starts in the tree.
Returns:
a FileTreeEntry for the added tree.
Throws:
java.io.IOException

addEntry

public void addEntry(TreeEntry e)
              throws java.io.IOException
Add the specified tree entry to this tree.

Parameters:
e -
Throws:
java.io.IOException

memberCount

public int memberCount()
                throws java.io.IOException
Returns:
number of members in this tree
Throws:
java.io.IOException

members

public TreeEntry[] members()
                    throws java.io.IOException
Return all members of the tree sorted in Git order. Entries are sorted by the numerical unsigned byte values with (sub)trees having an implicit '/'. An example of a tree with three entries. a:b is an actual file name here.

100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a.b 040000 tree 4277b6e69d25e5efa77c455340557b384a4c018a a 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a:b

Returns:
all entries in this Tree, sorted.
Throws:
java.io.IOException

existsTree

public boolean existsTree(java.lang.String path)
                   throws java.io.IOException
Parameters:
path - to the tree.
Returns:
true if a tree with the specified path can be found under this tree.
Throws:
java.io.IOException

existsBlob

public boolean existsBlob(java.lang.String path)
                   throws java.io.IOException
Parameters:
path - of the non-tree entry.
Returns:
true if a blob, symlink, or gitlink with the specified name can be found under this tree.
Throws:
java.io.IOException

findBlobMember

public TreeEntry findBlobMember(java.lang.String s)
                         throws java.io.IOException
Parameters:
s - blob name
Returns:
a TreeEntry representing an object with the specified relative path.
Throws:
java.io.IOException

findTreeMember

public TreeEntry findTreeMember(java.lang.String s)
                         throws java.io.IOException
Parameters:
s - Tree Name
Returns:
a Tree with the name s or null
Throws:
java.io.IOException

accept

public void accept(TreeVisitor tv,
                   int flags)
            throws java.io.IOException
Description copied from class: TreeEntry
Visit the members of this TreeEntry.

Specified by:
accept in class TreeEntry
Parameters:
tv - A visitor object doing the work
flags - Specification for what members to visit. See TreeEntry.MODIFIED_ONLY, TreeEntry.LOADED_ONLY, TreeEntry.CONCURRENT_MODIFICATION.
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object