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

Add ObjectStore.tree_changes().

Changeset 8256b06fe983

Parent 00ea704bc564

by Jelmer Vernooij

Changes to 2 files · Browse files at 8256b06fe983 Showing diff from parent 00ea704bc564 Diff from another changeset...

Change 1 of 1 Show Entire File NEWS Stacked
 
5
6
7
 
 
8
9
10
 
5
6
7
8
9
10
11
12
@@ -5,6 +5,8 @@
  * Add ObjectStore.iter_tree_contents()     * Add Index.changes_from_tree() + + * Add ObjectStore.tree_changes()    0.4.0 2009-10-07  
 
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
124
125
126
127
128
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
@@ -99,6 +99,65 @@
  """   raise NotImplementedError(self.add_objects)   + def tree_changes(self, source, target, want_unchanged=False): + """Find the differences between the contents of two trees + + :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(): + if path == "": + oldchildpath = name + else: + oldchildpath = "%s/%s" % (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(): + if path == "": + childpath = name + else: + childpath = "%s/%s" % (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)) +   def iter_tree_contents(self, tree):   """Yield (path, mode, hexsha) tuples for all non-Tree objects in a tree.