Skip to content

localrepo: Add tree modification helpers

John Cai requested to merge jc/add-tree-modification-helpers into master

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

  1. modifying an existing entry in the tree
  2. adding an entry into the tree
  3. 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)

  1. Add(), Modify(), Delete() all operate on a TreeEntry data structure. Any number of operations can be made on a TreeEntry before we write it to the git object database.
  2. Once all modifications are made, Write() is called to write the TreeEntry 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

Merge request reports

Loading