~bzr/bzr-bisect/trunk

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: James Westby
  • Date: 2009-04-02 16:01:01 UTC
  • Revision ID: james.westby@canonical.com-20090402160101-ccr19bx1mduq46hq
Fix the problem with bisecting in to merge revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
        self._high_revid = high_revid
193
193
        self._low_revid = low_revid
194
194
 
195
 
    def _switch_wc_to_revno(self, revno):
 
195
    def _switch_wc_to_revno(self, revno, outf):
196
196
        "Move the working tree to the given revno."
197
197
        self._current.switch(revno)
198
 
        self._current.show_rev_log()
 
198
        self._current.show_rev_log(out=outf)
199
199
 
200
200
    def _set_status(self, revid, status):
201
201
        "Set the bisect status for the given revid."
238
238
        "Set the current revision to the given bisection status."
239
239
        self._set_status(self._current.get_current_revid(), status)
240
240
 
241
 
    def bisect(self):
 
241
    def is_merge_point(self, revid):
 
242
        return len(self.get_parent_revids(revid)) > 1
 
243
 
 
244
    def get_parent_revids(self, revid):
 
245
        repo = self._bzrbranch.repository
 
246
        repo.lock_read()
 
247
        try:
 
248
            retval = repo.get_parent_map([revid]).get(revid, None)
 
249
        finally:
 
250
            repo.unlock()
 
251
        return retval
 
252
 
 
253
    def bisect(self, outf):
242
254
        "Using the current revision's status, do a bisection."
243
255
        self._find_range_and_middle()
244
 
        self._switch_wc_to_revno(self._middle_revid)
245
 
 
246
256
        # If we've found the "final" revision, check for a
247
257
        # merge point.
248
 
 
 
258
        while ((self._middle_revid == self._high_revid
 
259
                or self._middle_revid == self._low_revid)
 
260
                and self.is_merge_point(self._middle_revid)):
 
261
            for parent in self.get_parent_revids(self._middle_revid):
 
262
                if parent == self._low_revid:
 
263
                    continue
 
264
                else:
 
265
                    self._find_range_and_middle(parent)
 
266
                    break
 
267
        self._switch_wc_to_revno(self._middle_revid, outf)
249
268
        if self._middle_revid == self._high_revid or \
250
269
           self._middle_revid == self._low_revid:
251
 
            if self._current.is_merge_point():
252
 
                for parent in self._current.get_parent_revids():
253
 
                    if parent == self._low_revid:
254
 
                        continue
255
 
                    else:
256
 
                        self._find_range_and_middle(parent)
257
 
                        self._switch_wc_to_revno(self._middle_revid)
258
 
                        break
259
 
            else:
260
 
                self.set_current("done")
 
270
            self.set_current("done")
261
271
 
262
272
 
263
273
class cmd_bisect(Command):
330
340
            bisect_log.set_status_from_revspec(revspec, state)
331
341
        else:
332
342
            bisect_log.set_current(state)
333
 
        bisect_log.bisect()
 
343
        bisect_log.bisect(self.outf)
334
344
        bisect_log.save()
335
345
        return False
336
346
 
420
430
        bisect_log.change_file_name(bisect_info_path)
421
431
        bisect_log.save()
422
432
 
423
 
        bisect_log.bisect()
 
433
        bisect_log.bisect(self.outf)
424
434
 
425
435
    def run_bisect(self, script):
426
436
        import subprocess