Module gall.tree
Tree object interface
Functions
create (repo, flat_tree) | Create a tree instance representing the given flat tree |
flatten (t) | Flatten a tree into a single table. |
new (repo, obj) | Create a new tree instance representing the given raw object |
realise (t) | Realise a tree object
Tree objects are unrealised by default and realise themselves when you first access their fields. |
Class tree
tree:diff_to (other) | Generate the delta between two trees |
Functions
- create (repo, flat_tree)
-
Create a tree instance representing the given flat tree
Parameters:
- repo repository The repository in which to create the tree(s)
- flat_tree table A flat tree (of the kind returned by flatten)
Returns:
-
tree
The tree instance representing the top level of the tree
Or
- nil Nil on error
- string The error message
- flatten (t)
-
Flatten a tree into a single table.
Normally a tree consists of leaf -> data mappings. To flatten a tree we walk the tree finding tree objects inside it and add those to the outer tree with their names separated by ‘/’ which is how git does things.
Use this on a top-level tree to get a table mapping all entries in that tree and any trees beneath it.
Parameters:
- t tree The tree to flatten
Returns:
-
table
The flattened tree
- new (repo, obj)
-
Create a new tree instance representing the given raw object Trees are unrealised by default, use realise to cause their data to
be loaded into Lua if you want to iterate the tree.
Parameters:
- repo repository The repository in which the tree can be found
- obj object The raw object representing the tree
Returns:
-
tree
The tree instance for the given raw object
- realise (t)
-
Realise a tree object
Tree objects are unrealised by default and realise themselves when you first access their fields. You can call this function up-front if you want to force a tree to be realised first.
Parameters:
- t tree The tree to realise
Class tree
Representation of a tree in a Git repository.Apart from the diff_to method which will mask an entry called diff_to, all the fields of a tree instance are the entries in the Git tree.
The values of those fields are tables with permissions
, name
, type,
and obj
entries.
- tree:diff_to (other)
-
Generate the delta between two trees Treedelta entries are tables containing:
- Start mode and end mode
- Start kind and end kin
- Start sha and end sha
- An indication of the action
- An optional score of the action
- The filename in question
- If a copy or rename, src_name and dst_name too
The treedelta table is both an array of those entries and a map keyed on the filename.
Parameters:
- other tree Another tree instance
Returns:
-
table
The tree delta
Or
- nil Nil on error
- string The error message