/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-07 11:02:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6250.
  • Revision ID: jelmer@samba.org-20111107110219-ywbvifd666p1j9u5
Factor out the updating of branches into a separate helper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
363
363
        self._check_bound_branch(operation, possible_master_transports)
364
364
 
365
365
        # Check that the working tree is up to date
366
 
        old_revno, new_revno = self._check_out_of_date_tree()
 
366
        old_revno, old_revid, new_revno = self._check_out_of_date_tree()
367
367
 
368
368
        # Complete configuration setup
369
369
        if reporter is not None:
411
411
            self.builder.abort()
412
412
            raise errors.ExcludesUnsupported(self.branch.repository)
413
413
 
 
414
        if self.builder.updates_branch and self.bound_branch:
 
415
            self.builder.abort()
 
416
            raise AssertionError(
 
417
                "bound branches not supported for commit builders "
 
418
                "that update the branch")
 
419
 
414
420
        try:
415
421
            self.builder.will_record_deletes()
416
422
            # find the location being committed to
436
442
            message = message_callback(self)
437
443
            self.message = message
438
444
 
439
 
            if self.builder.updates_branch:
440
 
                # Remember the current last revision, in case
441
 
                # the pre_commit hook raises an exception
442
 
                # and the branch has to be reverted.
443
 
                old_rev_info = self.branch.last_revision_info()
444
 
                if self.bound_branch:
445
 
                    raise AssertionError(
446
 
                        "bound branches not supported for commit builders "
447
 
                        "that update the branch")
448
 
 
449
445
            # Add revision data to the local branch
450
446
            self.rev_id = self.builder.commit(self.message)
451
447
 
455
451
            self.builder.abort()
456
452
            raise
457
453
 
 
454
        self._update_branches(old_revno, old_revid, new_revno)
 
455
 
 
456
        # Make the working tree be up to date with the branch. This
 
457
        # includes automatic changes scheduled to be made to the tree, such
 
458
        # as updating its basis and unversioning paths that were missing.
 
459
        self.work_tree.unversion(self.deleted_ids)
 
460
        self._set_progress_stage("Updating the working tree")
 
461
        self.work_tree.update_basis_by_delta(self.rev_id,
 
462
             self.builder.get_basis_delta())
 
463
        self.reporter.completed(new_revno, self.rev_id)
 
464
        self._process_post_hooks(old_revno, new_revno)
 
465
        return self.rev_id
 
466
 
 
467
    def _update_branches(self, old_revno, old_revid, new_revno):
 
468
        """Update the master and local branch to the new revision.
 
469
 
 
470
        This will try to make sure that the master branch is updated
 
471
        before the local branch.
 
472
 
 
473
        :param old_revno: Revision number of master branch before the
 
474
            commit
 
475
        :param old_revid: Tip of master branch before the commit
 
476
        :param new_revno: Revision number of the new commit
 
477
        """
458
478
        if not self.builder.updates_branch:
459
479
            self._process_pre_hooks(old_revno, new_revno)
460
480
 
465
485
                # 'commit' to the master first so a timeout here causes the
466
486
                # local branch to be out of date
467
487
                (new_revno, self.rev_id) = self.master_branch.import_last_revision_info_and_tags(
468
 
                    self.branch, new_revno, self.rev_id, lossy=lossy)
469
 
                if lossy:
 
488
                    self.branch, new_revno, self.rev_id, lossy=self._lossy)
 
489
                if self._lossy:
470
490
                    self.branch.fetch(self.master_branch, self.rev_id)
471
491
 
472
492
            # and now do the commit locally.
477
497
            except:
478
498
                # The commit builder will already have updated the branch,
479
499
                # revert it.
480
 
                self.branch.set_last_revision_info(
481
 
                    old_rev_info[0], old_rev_info[1])
 
500
                self.branch.set_last_revision_info(old_revno, old_revid)
482
501
                raise
483
502
 
484
503
        # Merge local tags to remote
491
510
                note( gettext("Conflicting tags in bound branch:\n{0}".format(
492
511
                    "\n".join(warning_lines))) )
493
512
 
494
 
        # Make the working tree be up to date with the branch. This
495
 
        # includes automatic changes scheduled to be made to the tree, such
496
 
        # as updating its basis and unversioning paths that were missing.
497
 
        self.work_tree.unversion(self.deleted_ids)
498
 
        self._set_progress_stage("Updating the working tree")
499
 
        self.work_tree.update_basis_by_delta(self.rev_id,
500
 
             self.builder.get_basis_delta())
501
 
        self.reporter.completed(new_revno, self.rev_id)
502
 
        self._process_post_hooks(old_revno, new_revno)
503
 
        return self.rev_id
504
 
 
505
513
    def _select_reporter(self):
506
514
        """Select the CommitReporter to use."""
507
515
        if is_quiet():
564
572
    def _check_out_of_date_tree(self):
565
573
        """Check that the working tree is up to date.
566
574
 
567
 
        :return: old_revision_number,new_revision_number tuple
 
575
        :return: old_revision_number, old_revision_id, new_revision_number
 
576
            tuple
568
577
        """
569
578
        try:
570
579
            first_tree_parent = self.work_tree.get_parent_ids()[0]
583
592
        else:
584
593
            # ghost parents never appear in revision history.
585
594
            new_revno = 1
586
 
        return old_revno,new_revno
 
595
        return old_revno, master_last, new_revno
587
596
 
588
597
    def _process_pre_hooks(self, old_revno, new_revno):
589
598
        """Process any registered pre commit hooks."""