~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/history2weaves.py

  • Committer: Martin Pool
  • Date: 2005-09-19 08:18:38 UTC
  • Revision ID: mbp@sourcefrog.net-20050919081837-a46ca712bab7f104
- import file inventories in correct order

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
# sort of all revisions.  (Or do we, can we just before doing a revision
40
40
# see that all its parents have either been converted or abandoned?)
41
41
 
 
42
 
 
43
# Cannot import a revision until all its parents have been
 
44
# imported.  in other words, we can only import revisions whose
 
45
# parents have all been imported.  the first step must be to
 
46
# import a revision with no parents, of which there must be at
 
47
# least one.  (So perhaps it's useful to store forward pointers
 
48
# from a list of parents to their children?)
 
49
#
 
50
# Another (equivalent?) approach is to build up the ordered
 
51
# ancestry list for the last revision, and walk through that.  We
 
52
# are going to need that.
 
53
#
 
54
# We don't want to have to recurse all the way back down the list.
 
55
#
 
56
# Suppose we keep a queue of the revisions able to be processed at
 
57
# any point.  This starts out with all the revisions having no
 
58
# parents.
 
59
#
 
60
# This seems like a generally useful algorithm...
 
61
#
 
62
# The current algorithm is dumb (O(n**2)?) but will do the job, and
 
63
# takes less than a second on the bzr.dev branch.
 
64
 
42
65
if False:
43
66
    try:
44
67
        import psyco
107
130
                self._load_one_rev(rev_id)
108
131
        self.pb.clear()
109
132
        to_import = self._make_order()
110
 
        for rev_id in to_import:
 
133
        for i, rev_id in enumerate(to_import):
 
134
            self.pb.update('converting revision', i, len(to_import))
111
135
            self._import_one_rev(rev_id)
112
136
 
113
 
        # self._convert_one_rev(self.to_read.pop())
114
 
        
115
 
        print 'upgraded to weaves:'
 
137
        print '(not really) upgraded to weaves:'
116
138
        print '  %6d revisions and inventories' % len(self.revisions)
117
139
        print '  %6d absent revisions removed' % len(self.absent_revisions)
118
140
        print '  %6d texts' % self.text_count
122
144
 
123
145
    def _write_all_weaves(self):
124
146
        i = 0
125
 
        return ############################################
126
 
        # TODO: commit them all atomically at the end, not one by one
127
147
        write_atomic_weave(self.inv_weave, 'weaves/inventory.weave')
 
148
        return #######################
128
149
        write_atomic_weave(self.anc_weave, 'weaves/ancestry.weave')
129
150
        for file_id, file_weave in text_weaves.items():
130
151
            self.pb.update('writing weave', i, len(text_weaves))
140
161
        Any parents not either loaded or abandoned get queued to be
141
162
        loaded."""
142
163
        self.pb.update('loading revision',
143
 
                       len(self.converted_revs),
 
164
                       len(self.revisions),
144
165
                       self.total_revs)
145
166
        if rev_id not in self.branch.revision_store:
146
167
            self.pb.clear()
159
180
 
160
181
    def _import_one_rev(self, rev_id):
161
182
        """Convert rev_id and all referenced file texts to new format."""
162
 
        
 
183
        inv_xml = self.branch.inventory_store[rev_id].read()
 
184
        inv = serializer_v4.read_inventory_from_string(inv_xml)
 
185
        inv_parents = [x for x in self.revisions[rev_id].parent_ids
 
186
                       if x not in self.absent_revisions]
 
187
        self.inv_weave.add(rev_id, inv_parents,
 
188
                           inv_xml.splitlines(True))
163
189
 
164
190
 
165
191
    def _make_order(self):
182
208
                    o.append(rev_id)
183
209
                    todo.remove(rev_id)
184
210
                    done.add(rev_id)
185
 
                    
 
211
        return o
186
212
                
187
213
 
188
 
    # Cannot import a revision until all its parents have been
189
 
    # imported.  in other words, we can only import revisions whose
190
 
    # parents have all been imported.  the first step must be to
191
 
    # import a revision with no parents, of which there must be at
192
 
    # least one.  (So perhaps it's useful to store forward pointers
193
 
    # from a list of parents to their children?)
194
 
    #
195
 
    # Another (equivalent?) approach is to build up the ordered
196
 
    # ancestry list for the last revision, and walk through that.  We
197
 
    # are going to need that.
198
 
    #
199
 
    # We don't want to have to recurse all the way back down the list.
200
 
    #
201
 
    # Suppose we keep a queue of the revisions able to be processed at
202
 
    # any point.  This starts out with all the revisions having no
203
 
    # parents.
204
 
    #
205
 
    # This seems like a generally useful algorithm...
206
 
 
207
214
    def _convert_one_rev(self, rev_id):
208
215
        self._bump_progress()
209
216
        b = self.branch
226
233
        
227
234
        return ##########################################
228
235
 
229
 
        new_idx = self.inv_weave.add(rev_id, inv_parents, inv_xml)
230
 
        inv_parents = [new_idx]
231
 
 
232
236
        tree = b.revision_tree(rev_id)
233
237
        inv = tree.inventory
234
238