Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

Use diff_tree.walk_trees for BaseObjectStore.iter_tree_contents.

Change-Id: Ia9d0f7ea83af4c3462592fb5f8ec5a5674bfaf95
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>

Changeset b76771cd338b

Parent 6c50e44d7932

committed by Jelmer Vernooij

authored by Dave Borowitz

Changes to 2 files · Browse files at b76771cd338b Showing diff from parent 6c50e44d7932 Diff from another changeset...

 
30
31
32
 
33
34
35
 
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
 
 
 
 
 
164
165
166
 
30
31
32
33
34
35
36
 
149
150
151
 
 
 
 
 
 
 
 
 
 
 
 
 
152
153
154
155
156
157
158
159
@@ -30,6 +30,7 @@
   from dulwich.diff_tree import (   tree_changes, + walk_trees,   )  from dulwich.errors import (   NotTreeError, @@ -148,19 +149,11 @@
    :param tree_id: SHA1 of the tree.   :param include_trees: If True, include tree objects in the iteration. - :return: Yields tuples of (path, mode, hexhsa) for objects in a tree. - """ - todo = [('', stat.S_IFDIR, tree_id)] - while todo: - path, mode, hexsha = todo.pop() - is_subtree = stat.S_ISDIR(mode) - if not is_subtree or include_trees: - yield path, mode, hexsha - if is_subtree: - entries = reversed(list(self[hexsha].iteritems())) - for name, entry_mode, entry_hexsha in entries: - entry_path = posixpath.join(path, name) - todo.append((entry_path, entry_mode, entry_hexsha)) + :yield: TreeEntry namedtuples for all the objects in a tree. + """ + for entry, _ in walk_trees(self, tree_id, None): + if not stat.S_ISDIR(entry.mode) or include_trees: + yield entry     def find_missing_objects(self, haves, wants, progress=None,   get_tagged=None):
 
35
36
37
 
38
39
40
 
123
124
125
126
 
127
128
129
 
144
145
146
147
148
149
150
151
152
 
 
 
 
 
 
153
154
155
 
35
36
37
38
39
40
41
 
124
125
126
 
127
128
129
130
 
145
146
147
 
 
 
 
 
 
148
149
150
151
152
153
154
155
156
@@ -35,6 +35,7 @@
  ShaFile,   Tag,   Tree, + TreeEntry,   )  from dulwich.object_store import (   DiskObjectStore, @@ -123,7 +124,7 @@
  ('c', blob_c.id, 0100644),   ]   tree_id = commit_tree(self.store, blobs) - self.assertEquals([(p, m, h) for (p, h, m) in blobs], + self.assertEquals([TreeEntry(p, m, h) for (p, h, m) in blobs],   list(self.store.iter_tree_contents(tree_id)))     def test_iter_tree_contents_include_trees(self): @@ -144,12 +145,12 @@
  tree_bd = self.store[tree_ad['bd'][1]]     expected = [ - ('', 0040000, tree_id), - ('a', 0100644, blob_a.id), - ('ad', 0040000, tree_ad.id), - ('ad/b', 0100644, blob_b.id), - ('ad/bd', 0040000, tree_bd.id), - ('ad/bd/c', 0100755, blob_c.id), + TreeEntry('', 0040000, tree_id), + TreeEntry('a', 0100644, blob_a.id), + TreeEntry('ad', 0040000, tree_ad.id), + TreeEntry('ad/b', 0100644, blob_b.id), + TreeEntry('ad/bd', 0040000, tree_bd.id), + TreeEntry('ad/bd/c', 0100755, blob_c.id),   ]   actual = self.store.iter_tree_contents(tree_id, include_trees=True)   self.assertEquals(expected, list(actual))