localrepo: Add tree modification helpers
There are times when we want to modify an existing tree (especially when replacing some existing operations RPCs with git plumbing implementations eg: #4575 (closed)), but since trees in Git are immutable, we need to write a new tree with the modifications. There are three cases of this
- modifying an existing entry in the tree
- adding an entry into the tree
- deleting an entry from the tree.
To avoid having to write trees each time we need to modify a tree however, the following interface has been created. (thanks for the suggestion @pks-gitlab)
-
Add()
,Modify()
,Delete()
all operate on aTreeEntry
data structure. Any number of operations can be made on aTreeEntry
before we write it to the git object database. - Once all modifications are made,
Write()
is called to write theTreeEntry
data structure to the git object database.
This way, we only write new trees to the Git object database once for multiple edits to a git tree.
Edited by John Cai