~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/history2weaves.py

  • Committer: Martin Pool
  • Date: 2005-09-16 12:11:45 UTC
  • Revision ID: mbp@sourcefrog.net-20050916121144-7b01c532c29c3b76
- first cut at tsort to make order to bring in revisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        self.converted_revs = set()
72
72
        self.absent_revisions = set()
73
73
        self.text_count = 0
 
74
        self.revisions = {}
74
75
        self.convert()
 
76
        
75
77
 
76
78
 
77
79
 
93
95
        last_idx = None
94
96
        inv_parents = []
95
97
 
96
 
        # todo is a stack holding the revisions we still need to process;
 
98
        # to_read is a stack holding the revisions we still need to process;
97
99
        # appending to it adds new highest-priority revisions
98
 
        self.todo = rev_history[:]
99
 
        self.todo.reverse()
100
 
        self.total_revs = len(self.todo)
101
 
 
102
 
        while self.todo:
103
 
            self._convert_one_rev(self.todo.pop())
104
 
 
 
100
        importorder = []
 
101
        self.to_read = [rev_history[-1]]
 
102
        self.total_revs = len(rev_history)
 
103
        while self.to_read:
 
104
            rev_id = self.to_read.pop()
 
105
            if (rev_id not in self.revisions
 
106
                and rev_id not in self.absent_revisions):
 
107
                self._load_one_rev(rev_id)
105
108
        self.pb.clear()
 
109
 
 
110
        self._make_order()
 
111
 
 
112
        # self._convert_one_rev(self.to_read.pop())
 
113
        
106
114
        print 'upgraded to weaves:'
107
 
        print '  %6d revisions and inventories' % len(self.converted_revs)
 
115
        print '  %6d revisions and inventories' % len(self.revisions)
108
116
        print '  %6d absent revisions removed' % len(self.absent_revisions)
109
117
        print '  %6d texts' % self.text_count
110
118
 
125
133
        self.pb.clear()
126
134
 
127
135
        
 
136
    def _load_one_rev(self, rev_id):
 
137
        """Load a revision object into memory.
 
138
 
 
139
        Any parents not either loaded or abandoned get queued to be
 
140
        loaded."""
 
141
        self.pb.update('loading revision',
 
142
                       len(self.converted_revs),
 
143
                       self.total_revs)
 
144
        if rev_id not in self.branch.revision_store:
 
145
            self.pb.clear()
 
146
            note('revision {%s} not present in branch; '
 
147
                 'will not be converted',
 
148
                 rev_id)
 
149
            self.absent_revisions.add(rev_id)
 
150
        else:
 
151
            rev_xml = self.branch.revision_store[rev_id].read()
 
152
            rev = serializer_v4.read_revision_from_string(rev_xml)
 
153
            for parent_id in [x.revision_id for x in rev.parents]:
 
154
                self.total_revs += 1
 
155
                self.to_read.append(parent_id)
 
156
            self.revisions[rev_id] = rev
 
157
 
 
158
 
 
159
    def _make_order(self):
 
160
        todo = set(self.revisions.keys())
 
161
        done = self.absent_revisions.copy()
 
162
        while todo:
 
163
            # scan through looking for a revision whose parents
 
164
            # are all done
 
165
            for rev_id in list(todo):
 
166
                rev = self.revisions[rev_id]
 
167
                parent_ids = set([x.revision_id for x in rev.parents])
 
168
                if parent_ids.issubset(done):
 
169
                    # can take this one now
 
170
                    print rev_id
 
171
                    todo.remove(rev_id)
 
172
                    done.add(rev_id)
 
173
                    
 
174
                
 
175
 
 
176
    # Cannot import a revision until all its parents have been
 
177
    # imported.  in other words, we can only import revisions whose
 
178
    # parents have all been imported.  the first step must be to
 
179
    # import a revision with no parents, of which there must be at
 
180
    # least one.  (So perhaps it's useful to store forward pointers
 
181
    # from a list of parents to their children?)
 
182
    #
 
183
    # Another (equivalent?) approach is to build up the ordered
 
184
    # ancestry list for the last revision, and walk through that.  We
 
185
    # are going to need that.
 
186
    #
 
187
    # We don't want to have to recurse all the way back down the list.
 
188
    #
 
189
    # Suppose we keep a queue of the revisions able to be processed at
 
190
    # any point.  This starts out with all the revisions having no
 
191
    # parents.
 
192
    #
 
193
    # This seems like a generally useful algorithm...
 
194
 
128
195
    def _convert_one_rev(self, rev_id):
129
196
        self._bump_progress()
130
197
        b = self.branch
143
210
        rev = serializer_v4.read_revision_from_string(rev_xml)
144
211
        inv = serializer_v4.read_inventory_from_string(inv_xml)
145
212
 
146
 
        # see if parents need to be done first
147
 
        for parent_id in [x.revision_id for x in rev.parents]:
148
 
            if parent_id not in self.converted_revs:
149
 
                self.todo.append(parent_id)
150
 
 
151
213
        self.converted_revs.add(rev_id)
152
214
        
153
215
        return ##########################################
192
254
 
193
255
        revno += 1
194
256
        
195
 
    def _bump_progress(self):
196
 
        self.pb.update('converting revisions',
197
 
                       len(self.converted_revs),
198
 
                       self.total_revs)
199
257
 
200
258
 
201
259
def write_atomic_weave(weave, filename):