diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-22 21:23:47 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-22 21:23:47 +0200 |
commit | be97c4558992a437cde235aafc7ae2bd6df84ac8 (patch) | |
tree | 3e44a7c38e356817ca81721725709d7374f95012 /lib/git/index/fun.py | |
parent | 778234d544b3f58dd415aaf10679d15b01a5281f (diff) | |
download | gitpython-be97c4558992a437cde235aafc7ae2bd6df84ac8.tar.gz |
Initial frame for implementing read_tree using pure python. As git-read-tree can do much more than we can ( and faster assumably ), the .new method is used to create new index instances from up to 3 trees.
Implemented multi-tree traversal to facilitate building a stage list more efficiently ( although I am not sure whether it could be faster to use a dictionary together with some intensive lookup ), including test
Added performance to learn how fast certain operations are, and whether one should be preferred over another
Diffstat (limited to 'lib/git/index/fun.py')
-rw-r--r-- | lib/git/index/fun.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/lib/git/index/fun.py b/lib/git/index/fun.py index 9f877a66..962e139a 100644 --- a/lib/git/index/fun.py +++ b/lib/git/index/fun.py @@ -12,8 +12,10 @@ from git.utils import ( ) from typ import ( + BaseIndexEntry, IndexEntry, - CE_NAMEMASK + CE_NAMEMASK, + CE_STAGESHIFT ) from util import ( @@ -23,7 +25,6 @@ from util import ( from gitdb.base import IStream from gitdb.typ import str_tree_type -from binascii import a2b_hex __all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key' ) @@ -150,6 +151,7 @@ def write_tree_from_cache(entries, odb, sl, si=0): :return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of tree entries being a tuple of hexsha, mode, name""" tree_items = list() + tree_items_append = tree_items.append ci = sl.start end = sl.stop while ci < end: @@ -161,7 +163,7 @@ def write_tree_from_cache(entries, odb, sl, si=0): rbound = entry.path.find('/', si) if rbound == -1: # its not a tree - tree_items.append((entry.binsha, entry.mode, entry.path[si:])) + tree_items_append((entry.binsha, entry.mode, entry.path[si:])) else: # find common base range base = entry.path[si:rbound] @@ -178,7 +180,7 @@ def write_tree_from_cache(entries, odb, sl, si=0): # enter recursion # ci - 1 as we want to count our current item as well sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci-1, xi), rbound+1) - tree_items.append((sha, S_IFDIR, base)) + tree_items_append((sha, S_IFDIR, base)) # skip ahead ci = xi @@ -193,5 +195,24 @@ def write_tree_from_cache(entries, odb, sl, si=0): istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio)) return (istream.binsha, tree_items) +def _tree_entry_to_baseindexentry(tree_entry, stage): + return BaseIndexEntry(tree_entry[1], tree_entry[0], stage <<CE_STAGESHIFT, tree_entry[2]) +def aggressive_tree_merge(odb, tree_shas): + """ + :return: list of BaseIndexEntries representing the aggressive merge of the given + trees. All valid entries are on stage 0, whereas the conflicting ones are left + on stage 1, 2 or 3, whereas stage 1 corresponds to the common ancestor tree, + 2 to our tree and 3 to 'their' tree. + :param tree_shas: 1, 2 or 3 trees as identified by their shas""" + out = list() + out_append = out.append + if len(tree_shas) == 1: + for entry in traverse_tree_recursive(odb, tree_shas[0]): + out_append(_tree_entry_to_baseindexentry(entry, 0)) + # END for each entry + else: + raise ValueError("Cannot handle %i trees at once" % len(tree_shas)) + # END handle tree shas + return out |