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