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

Add functions for determining the delta between the index and a revision tree.

Changeset 00ea704bc564

Parent c5e791853ac7

by Jelmer Vernooij

Changes to 3 files · Browse files at 00ea704bc564 Showing diff from parent c5e791853ac7 Diff from another changeset...

Change 1 of 1 Show Entire File NEWS Stacked
 
1
 
 
 
 
 
 
2
3
4
 
1
2
3
4
5
6
7
8
9
10
@@ -1,4 +1,10 @@
 0.4.1 UNRELEASED + + FEATURES + + * Add ObjectStore.iter_tree_contents() + + * Add Index.changes_from_tree()    0.4.0 2009-10-07  
Change 1 of 2 Show Entire File dulwich/​index.py Stacked
 
212
213
214
 
 
 
 
215
216
217
 
233
234
235
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
237
238
 
212
213
214
215
216
217
218
219
220
221
 
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
@@ -212,6 +212,10 @@
  """Return the (git object) SHA1 for the object at a path."""   return self[path][-2]   + def get_mode(self, path): + """Return the POSIX file mode for the object at a path.""" + return self[path][-6] +   def iterblobs(self):   """Iterate over path, sha, mode tuples for use with commit_tree."""   for path, entry in self: @@ -233,6 +237,28 @@
  def update(self, entries):   for name, value in entries.iteritems():   self[name] = value + + def changes_from_tree(self, object_store, tree, want_unchanged=False): + """Find the differences between the contents of this index and a tree. + + :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) + """ + mine = set(self._byname.keys()) + for (name, mode, sha) in object_store.iter_tree_contents(tree): + if name in mine: + if (want_unchanged or self.get_sha1(name) != sha or + self.get_mode(name) != mode): + yield ((name, name), (mode, self.get_mode(name)), (sha, self.get_sha1(name))) + mine.remove(name) + else: + # Was removed + yield ((name, None), (mode, None), (sha, None)) + # Mention added files + for name in mine: + yield ((None, name), (None, self.get_mode(name)), (None, self.get_sha1(name)))      def commit_tree(object_store, blobs):
 
99
100
101
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
103
104
 
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@@ -99,6 +99,25 @@
  """   raise NotImplementedError(self.add_objects)   + def iter_tree_contents(self, tree): + """Yield (path, mode, hexsha) tuples for all non-Tree objects in a tree. + + :param tree: SHA1 of the root of the tree + """ + todo = set([(tree, "")]) + while todo: + (tid, tpath) = todo.pop() + tree = self[tid] + for name, mode, hexsha in tree.iteritems(): + if tpath == "": + path = name + else: + path = "%s/%s" % (tpath, name) + if stat.S_ISDIR(mode): + todo.add((hexsha, path)) + else: + yield path, mode, hexsha +   def find_missing_objects(self, haves, wants, progress=None):   """Find the missing objects required for a set of revisions.