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

Use diff_tree.tree_changes for BaseObjectStore.tree_changes.

Added tests.

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

Changeset 6c50e44d7932

Parent 2004e1021756

committed by Jelmer Vernooij

authored by Dave Borowitz

Changes to 3 files · Browse files at 6c50e44d7932 Showing diff from parent 2004e1021756 Diff from another changeset...

 
28
29
30
 
 
 
31
32
33
 
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 
 
 
 
 
 
 
 
178
179
180
 
28
29
30
31
32
33
34
35
36
 
132
133
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
136
137
138
139
140
141
142
143
144
145
@@ -28,6 +28,9 @@
 import tempfile  import urllib2   +from dulwich.diff_tree import ( + tree_changes, + )  from dulwich.errors import (   NotTreeError,   ) @@ -129,52 +132,14 @@
  :param object_store: Object store to use for retrieving tree contents   :param tree: SHA1 of the root tree   :param want_unchanged: Whether unchanged files should be reported - :return: Iterator over tuples with (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) - """ - todo = set([(source, target, "")]) - while todo: - (sid, tid, path) = todo.pop() - if sid is not None: - stree = self[sid] - else: - stree = {} - if tid is not None: - ttree = self[tid] - else: - ttree = {} - for name, oldmode, oldhexsha in stree.iteritems(): - oldchildpath = posixpath.join(path, name) - try: - (newmode, newhexsha) = ttree[name] - newchildpath = oldchildpath - except KeyError: - newmode = None - newhexsha = None - newchildpath = None - if (want_unchanged or oldmode != newmode or - oldhexsha != newhexsha): - if stat.S_ISDIR(oldmode): - if newmode is None or stat.S_ISDIR(newmode): - todo.add((oldhexsha, newhexsha, oldchildpath)) - else: - # entry became a file - todo.add((oldhexsha, None, oldchildpath)) - yield ((None, newchildpath), (None, newmode), (None, newhexsha)) - else: - if newmode is not None and stat.S_ISDIR(newmode): - # entry became a dir - yield ((oldchildpath, None), (oldmode, None), (oldhexsha, None)) - todo.add((None, newhexsha, newchildpath)) - else: - yield ((oldchildpath, newchildpath), (oldmode, newmode), (oldhexsha, newhexsha)) - - for name, newmode, newhexsha in ttree.iteritems(): - childpath = posixpath.join(path, name) - if not name in stree: - if not stat.S_ISDIR(newmode): - yield ((None, childpath), (None, newmode), (None, newhexsha)) - else: - todo.add((None, newhexsha, childpath)) + :return: Iterator over tuples with + (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) + """ + for change in tree_changes(self, source, target, + want_unchanged=want_unchanged): + yield ((change.old.path, change.new.path), + (change.old.mode, change.new.mode), + (change.old.sha, change.new.sha))     def iter_tree_contents(self, tree_id, include_trees=False):   """Iterate the contents of a tree and all subtrees.
 
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
93
94
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@@ -89,6 +89,25 @@
  r = self.store[testobject.id]   self.assertEquals(r, testobject)   + def test_tree_changes(self): + blob_a1 = make_object(Blob, data='a1') + blob_a2 = make_object(Blob, data='a2') + blob_b = make_object(Blob, data='b') + for blob in [blob_a1, blob_a2, blob_b]: + self.store.add_object(blob) + + blobs_1 = [('a', blob_a1.id, 0100644), ('b', blob_b.id, 0100644)] + tree1_id = commit_tree(self.store, blobs_1) + blobs_2 = [('a', blob_a2.id, 0100644), ('b', blob_b.id, 0100644)] + tree2_id = commit_tree(self.store, blobs_2) + change_a = (('a', 'a'), (0100644, 0100644), (blob_a1.id, blob_a2.id)) + self.assertEquals([change_a], + list(self.store.tree_changes(tree1_id, tree2_id))) + self.assertEquals( + [change_a, (('b', 'b'), (0100644, 0100644), (blob_b.id, blob_b.id))], + list(self.store.tree_changes(tree1_id, tree2_id, + want_unchanged=True))) +   def test_iter_tree_contents(self):   blob_a = make_object(Blob, data='a')   blob_b = make_object(Blob, data='b')
 
267
268
269
 
 
 
 
 
 
 
270
271
272
 
282
283
284
285
286
287
288
289
290
291
292
 
 
267
268
269
270
271
272
273
274
275
276
277
278
279
 
289
290
291
 
 
 
 
 
 
 
 
292
@@ -267,6 +267,13 @@
  tree1, tree2, added, removed, changed1, changed2, unchanged]])   write_tree_diff(f, store, tree1.id, tree2.id)   self.assertEquals([ + 'diff --git /dev/null b/added.txt', + 'new mode 644', + 'index e69de29..76d4bb8 644', + '--- /dev/null', + '+++ b/added.txt', + '@@ -1,0 +1,1 @@', + '+add',   'diff --git a/changed.txt b/changed.txt',   'index bf84e48..1be2436 644',   '--- a/changed.txt', @@ -282,11 +289,4 @@
  '+++ /dev/null',   '@@ -1,1 +1,0 @@',   '-removed', - 'diff --git /dev/null b/added.txt', - 'new mode 644', - 'index e69de29..76d4bb8 644', - '--- /dev/null', - '+++ b/added.txt', - '@@ -1,0 +1,1 @@', - '+add' - ], f.getvalue().splitlines()) + ], f.getvalue().splitlines())