~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/switch.py

Merge description into dont-add-conflict-helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from bzrlib.trace import note
23
23
 
24
24
 
25
 
def switch(control_dir, to_branch, force=False, quiet=False):
 
25
def switch(control_dir, to_branch, force=False, quiet=False, revision_id=None):
26
26
    """Switch the branch associated with a checkout.
27
27
 
28
28
    :param control_dir: BzrDir of the checkout to change
29
29
    :param to_branch: branch that the checkout is to reference
30
30
    :param force: skip the check for local commits in a heavy checkout
 
31
    :param revision_id: revision ID to switch to.
31
32
    """
32
33
    _check_pending_merges(control_dir, force)
33
34
    try:
36
37
        source_repository = to_branch.repository
37
38
    _set_branch_location(control_dir, to_branch, force)
38
39
    tree = control_dir.open_workingtree()
39
 
    _update(tree, source_repository, quiet)
 
40
    _update(tree, source_repository, quiet, revision_id)
40
41
 
41
42
 
42
43
def _check_pending_merges(control, force=False):
118
119
    return False
119
120
 
120
121
 
121
 
def _update(tree, source_repository, quiet=False):
 
122
def _update(tree, source_repository, quiet=False, revision_id=None):
122
123
    """Update a working tree to the latest revision of its branch.
123
124
 
124
125
    :param tree: the working tree
127
128
    tree.lock_tree_write()
128
129
    try:
129
130
        to_branch = tree.branch
130
 
        if tree.last_revision() == to_branch.last_revision():
 
131
        if revision_id is None:
 
132
            revision_id = to_branch.last_revision()
 
133
        if tree.last_revision() == revision_id:
131
134
            if not quiet:
132
135
                note("Tree is up to date at revision %d.", to_branch.revno())
133
136
            return
134
137
        base_tree = source_repository.revision_tree(tree.last_revision())
135
 
        merge.Merge3Merger(tree, tree, base_tree, to_branch.basis_tree())
 
138
        merge.Merge3Merger(tree, tree, base_tree, to_branch.repository.revision_tree(revision_id))
136
139
        tree.set_last_revision(to_branch.last_revision())
137
140
        if not quiet:
138
141
            note('Updated to revision %d.' % to_branch.revno())