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 Changes Only NEWS Stacked
1
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
114
115
116
117
118
119
120
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
114
115
116
117
118
119
120
121
122
123
124
125
126
 0.4.1 UNRELEASED + + FEATURES + + * Add ObjectStore.iter_tree_contents() + + * Add Index.changes_from_tree()    0.4.0 2009-10-07     DOCUMENTATION     * Added tutorial.     API CHANGES     * dulwich.object_store.tree_lookup_path will now return the mode and   sha of the object found rather than the object itself.     BUG FIXES     * Use binascii.hexlify / binascii.unhexlify for better performance.     * Cope with extra unknown data in index files by ignoring it (for now).     * Add proper error message when server unexpectedly hangs up. (#415843)     * Correctly write opcode for equal in create_delta.    0.3.3 2009-07-23     FEATURES     * Implement ShaFile.__hash__().     * Implement Tree.__len__()     BUG FIXES     * Check for 'objects' and 'refs' directories   when looking for a Git repository. (#380818)    0.3.2 2009-05-20     BUG FIXES     * Support the encoding field in Commits.     * Some Windows compatibility fixes.     * Fixed several issues in commit support.     FEATURES     * Basic support for handling submodules.    0.3.1 2009-05-13     FEATURES     * Implemented Repo.__getitem__, Repo.__setitem__ and Repo.__delitem__ to   access content.     API CHANGES     * Removed Repo.set_ref, Repo.remove_ref, Repo.tags, Repo.get_refs and   Repo.heads in favor of Repo.refs, a dictionary-like object for accessing   refs.     BUG FIXES     * Removed import of 'sha' module in objects.py, which was causing   deprecation warnings on Python 2.6.    0.3.0 2009-05-10     FEATURES     * A new function `commit_tree' has been added that can commit a tree   based on an index.     BUG FIXES     * The memory usage when generating indexes has been significantly reduced.     * A memory leak in the C implementation of parse_tree has been fixed.     * The send-pack smart server command now works. (Thanks Scott Chacon)     * The handling of short timestamps (less than 10 digits) has been fixed.     * The handling of timezones has been fixed.    0.2.1 2009-04-30     BUG FIXES     * Fix compatibility with Python2.4.    0.2.0 2009-04-30     FEATURES     * Support for activity reporting in smart protocol client.     * Optional C extensions for better performance in a couple of   places that are performance-critical.    0.1.1 2009-03-13     BUG FIXES     * Fixed regression in Repo.find_missing_objects()     * Don't fetch ^{} objects from remote hosts, as requesting them   causes a hangup.     * Always write pack to disk completely before calculating checksum.     FEATURES     * Allow disabling thin packs when talking to remote hosts.    0.1.0 2009-01-24     * Initial release.
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.