/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/branchbuilder.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-22 18:57:57 UTC
  • mto: (3514.4.6 merge_lca_multi)
  • mto: This revision was merged to the branch mainline in revision 3590.
  • Revision ID: john@arbash-meinel.com-20080722185757-98rezzd05dgcfr3e
Clean up the build_snapshot api a bit.

Move the parent_ids to the second parameter, because it makes more sense there.
Document the function parameters and return value.
Factor out moving the branch tip, to help clean up the function.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
        finally:
61
61
            tree.unlock()
62
62
 
63
 
    def build_snapshot(self, parent_ids, revision_id, actions):
 
63
    def _move_branch_pointer(self, new_revision_id):
 
64
        """Point self._branch to a different revision id."""
 
65
        self._branch.lock_write()
 
66
        try:
 
67
            # We don't seem to have a simple set_last_revision(), so we
 
68
            # implement it here.
 
69
            cur_revno, cur_revision_id = self._branch.last_revision_info()
 
70
            g = self._branch.repository.get_graph()
 
71
            new_revno = g.find_distance_to_null(new_revision_id,
 
72
                                                [(cur_revision_id, cur_revno)])
 
73
            self._branch.set_last_revision_info(new_revno, new_revision_id)
 
74
        finally:
 
75
            self._branch.unlock()
 
76
 
 
77
    def build_snapshot(self, revision_id, parent_ids, actions):
 
78
        """Build a commit, shaped in a specific way.
 
79
 
 
80
        :param revision_id: The handle for the new commit, could be none, as it
 
81
            will be returned, though it is put in the commit message.
 
82
        :param parent_ids: A list of parent_ids to use for the commit.
 
83
            It can be None, which indicates to use the last commit.
 
84
        :param actions: A list of actions to perform. Supported actions are:
 
85
            ('add', ('path', 'file-id', 'kind', 'content' or None))
 
86
            ('modify', ('file-id', 'new-content'))
 
87
            ('unversion', 'file-id')
 
88
            # not supported yet: ('rename', ('orig-path', 'new-path'))
 
89
        ;return: The revision_id of the new commit
 
90
        """
64
91
        if parent_ids is not None:
65
 
            self._branch.lock_write()
66
 
            try:
67
 
                base_id = parent_ids[0]
68
 
                # Unfortunately, this is the only real way to get the revno
69
 
                cur_revno, cur_revision_id = self._branch.last_revision_info()
70
 
                g = self._branch.repository.get_graph()
71
 
                new_revno = g.find_distance_to_null(base_id,
72
 
                                [(cur_revision_id, cur_revno)])
73
 
                self._branch.set_last_revision_info(new_revno, base_id)
74
 
            finally:
75
 
                self._branch.unlock()
 
92
            base_id = parent_ids[0]
 
93
            if base_id != self._branch.last_revision():
 
94
                self._move_branch_pointer(base_id)
 
95
 
76
96
        tree = memorytree.MemoryTree.create_on_branch(self._branch)
77
97
        tree.lock_write()
78
98
        try: