2888
2888
from bzrlib.tag import _merge_tags_if_possible
2889
2889
assert revision is None or len(revision) < 3
2890
2890
# find the branch locations
2891
other_loc, location = self._select_branch_location(tree, location,
2891
other_loc, user_location = self._select_branch_location(tree, location,
2893
2893
if revision is not None and len(revision) == 2:
2894
base_loc, location = self._select_branch_location(tree, location,
2894
base_loc, _unused = self._select_branch_location(tree,
2895
location, revision, 0)
2897
2897
base_loc = other_loc
2898
2898
# Open the branches
2920
2920
base_revision_id = None
2921
2921
# Remember where we merge from
2922
if ((tree.branch.get_parent() is None or remember) and
2923
other_branch is not None):
2924
tree.branch.set_parent(other_branch.base)
2922
if ((remember or tree.branch.get_submit_branch() is None) and
2923
user_location is not None):
2924
tree.branch.set_submit_branch(other_branch.base)
2925
2925
_merge_tags_if_possible(other_branch, tree.branch)
2926
2926
merger = _mod_merge.Merger.from_revision_ids(pb, tree,
2927
2927
other_revision_id, base_revision_id, other_branch, base_branch)
2932
2932
allow_pending = True
2933
2933
return merger, allow_pending
2935
def _select_branch_location(self, tree, location, revision=None,
2935
def _select_branch_location(self, tree, user_location, revision=None,
2937
2937
"""Select a branch location, according to possible inputs.
2940
2940
``revision`` and ``index`` must be supplied.)
2942
2942
Otherwise, the ``location`` parameter is used. If it is None, then the
2943
``parent`` location is used, and a note is printed.
2943
``submit`` or ``parent`` location is used, and a note is printed.
2945
2945
:param tree: The working tree to select a branch for merging into
2946
2946
:param location: The location entered by the user
2947
2947
:param revision: The revision parameter to the command
2948
2948
:param index: The index to use for the revision parameter. Negative
2949
2949
indices are permitted.
2950
:return: (selected_location, default_location). The default location
2951
will be the user-entered location, if any, or else the remembered
2950
:return: (selected_location, user_location). The default location
2951
will be the user-entered location.
2954
2953
if (revision is not None and index is not None
2955
2954
and revision[index] is not None):
2956
2955
branch = revision[index].get_branch()
2957
2956
if branch is not None:
2958
return branch, location
2959
location = self._get_remembered_parent(tree, location, 'Merging from')
2960
return location, location
2957
return branch, branch
2958
if user_location is None:
2959
location = self._get_remembered(tree, 'Merging from')
2961
location = user_location
2962
return location, user_location
2962
# TODO: move up to common parent; this isn't merge-specific anymore.
2963
def _get_remembered_parent(self, tree, supplied_location, verb_string):
2964
def _get_remembered(self, tree, verb_string):
2964
2965
"""Use tree.branch's parent if none was supplied.
2966
2967
Report if the remembered location was used.
2968
if supplied_location is not None:
2969
return supplied_location
2970
stored_location = tree.branch.get_parent()
2969
stored_location = tree.branch.get_submit_branch()
2970
if stored_location is None:
2971
stored_location = tree.branch.get_parent()
2971
2972
mutter("%s", stored_location)
2972
2973
if stored_location is None:
2973
2974
raise errors.BzrCommandError("No location specified or remembered")