2653
2655
change_reporter = delta._ChangeReporter(
2654
2656
unversioned_filter=tree.is_ignored)
2658
other_transport = None
2659
other_revision_id = None
2660
base_revision_id = None
2661
possible_transports = []
2656
2663
if branch is not None:
2658
mergeable = bundle.read_mergeable_from_url(
2660
except errors.NotABundle:
2661
pass # Continue on considering this url a Branch
2664
mergeable, other_transport = _get_bundle_helper(branch)
2663
2666
if revision is not None:
2664
2667
raise errors.BzrCommandError(
2665
2668
'Cannot use -r with merge directives or bundles')
2666
other_revision_id = mergeable.install_revisions(
2667
tree.branch.repository)
2668
revision = [RevisionSpec.from_string(
2669
'revid:' + other_revision_id)]
2671
if revision is None \
2672
or len(revision) < 1 or revision[0].needs_branch():
2673
branch = self._get_remembered_parent(tree, branch, 'Merging from')
2675
if revision is None or len(revision) < 1:
2678
other = [branch, None]
2669
mergeable.install_revisions(tree.branch.repository)
2670
base_revision_id, other_revision_id, verified =\
2671
mergeable.get_merge_request(tree.branch.repository)
2672
if base_revision_id in tree.branch.repository.get_ancestry(
2673
tree.branch.last_revision(), topo_sorted=False):
2674
base_revision_id = None
2679
possible_transports.append(other_transport)
2681
if other_revision_id is None:
2682
verified = 'inapplicable'
2683
if revision is None \
2684
or len(revision) < 1 or revision[0].needs_branch():
2685
branch = self._get_remembered_parent(tree, branch,
2688
if revision is None or len(revision) < 1:
2691
other = [branch, None]
2694
other = [branch, -1]
2695
other_branch, path = Branch.open_containing(branch,
2696
possible_transports)
2681
other = [branch, -1]
2682
other_branch, path = Branch.open_containing(branch)
2685
raise errors.BzrCommandError('Cannot use --uncommitted and'
2686
' --revision at the same time.')
2687
branch = revision[0].get_branch() or branch
2688
if len(revision) == 1:
2690
if other_revision_id is not None:
2695
other_branch, path = Branch.open_containing(branch)
2699
raise errors.BzrCommandError('Cannot use --uncommitted and'
2700
' --revision at the same time.')
2701
branch = revision[0].get_branch() or branch
2702
if len(revision) == 1:
2704
other_branch, path = Branch.open_containing(
2705
branch, possible_transports)
2696
2706
revno = revision[0].in_history(other_branch).revno
2697
2707
other = [branch, revno]
2699
assert len(revision) == 2
2700
if None in revision:
2701
raise errors.BzrCommandError(
2702
"Merge doesn't permit empty revision specifier.")
2703
base_branch, path = Branch.open_containing(branch)
2704
branch1 = revision[1].get_branch() or branch
2705
other_branch, path1 = Branch.open_containing(branch1)
2706
if revision[0].get_branch() is not None:
2707
# then path was obtained from it, and is None.
2710
base = [branch, revision[0].in_history(base_branch).revno]
2711
other = [branch1, revision[1].in_history(other_branch).revno]
2709
assert len(revision) == 2
2710
if None in revision:
2711
raise errors.BzrCommandError(
2712
"Merge doesn't permit empty revision specifier.")
2713
base_branch, path = Branch.open_containing(
2714
branch, possible_transports)
2715
branch1 = revision[1].get_branch() or branch
2716
other_branch, path1 = Branch.open_containing(
2717
branch1, possible_transports)
2718
if revision[0].get_branch() is not None:
2719
# then path was obtained from it, and is None.
2722
base = [branch, revision[0].in_history(base_branch).revno]
2724
revision[1].in_history(other_branch).revno]
2726
# Remember where we merge from
2713
2727
if ((tree.branch.get_parent() is None or remember) and
2714
2728
other_branch is not None):
2715
2729
tree.branch.set_parent(other_branch.base)
2844
2862
restore(tree.abspath(filename))
2845
2863
except errors.NotConflicted:
2847
conflicts = _mod_merge.merge_inner(
2848
tree.branch, other_tree, base_tree,
2850
interesting_ids=interesting_ids,
2851
other_rev_id=parents[1],
2852
merge_type=merge_type,
2853
show_base=show_base,
2854
reprocess=reprocess)
2865
# Disable pending merges, because the file texts we are remerging
2866
# have not had those merges performed. If we use the wrong parents
2867
# list, we imply that the working tree text has seen and rejected
2868
# all the changes from the other tree, when in fact those changes
2869
# have not yet been seen.
2870
tree.set_parent_ids(parents[:1])
2872
conflicts = _mod_merge.merge_inner(
2873
tree.branch, other_tree, base_tree,
2875
interesting_ids=interesting_ids,
2876
other_rev_id=parents[1],
2877
merge_type=merge_type,
2878
show_base=show_base,
2879
reprocess=reprocess)
2881
tree.set_parent_ids(parents)
2857
2884
if conflicts > 0:
3088
3119
class cmd_plugins(Command):
3120
"""List the installed plugins.
3122
This command displays the list of installed plugins including the
3123
path where each one is located and a short description of each.
3125
A plugin is an external component for Bazaar that extends the
3126
revision control system, by adding or replacing code in Bazaar.
3127
Plugins can do a variety of things, including overriding commands,
3128
adding new commands, providing additional network transports and
3129
customizing log output.
3131
See the Bazaar web site, http://bazaar-vcs.org, for further
3132
information on plugins including where to find them and how to
3133
install them. Instructions are also provided there on how to
3134
write new plugins using the Python programming language.
3091
3137
@display_command
3093
3139
import bzrlib.plugin
3596
3649
public_branch = stored_public_branch
3597
3650
elif stored_public_branch is None:
3598
3651
branch.set_public_branch(public_branch)
3599
if patch_type != "bundle" and public_branch is None:
3652
if not include_bundle and public_branch is None:
3600
3653
raise errors.BzrCommandError('No public branch specified or'
3655
base_revision_id = None
3602
3656
if revision is not None:
3603
if len(revision) != 1:
3657
if len(revision) > 2:
3604
3658
raise errors.BzrCommandError('bzr merge-directive takes '
3605
'exactly one revision identifier')
3607
revision_id = revision[0].in_history(branch).rev_id
3659
'at most two one revision identifiers')
3660
revision_id = revision[-1].in_history(branch).rev_id
3661
if len(revision) == 2:
3662
base_revision_id = revision[0].in_history(branch).rev_id
3663
base_revision_id = ensure_null(base_revision_id)
3609
3665
revision_id = branch.last_revision()
3610
3666
revision_id = ensure_null(revision_id)
3611
3667
if revision_id == NULL_REVISION:
3612
3668
raise errors.BzrCommandError('No revisions to bundle.')
3613
directive = merge_directive.MergeDirective.from_objects(
3669
directive = merge_directive.MergeDirective2.from_objects(
3614
3670
branch.repository, revision_id, time.time(),
3615
3671
osutils.local_time_offset(), submit_branch,
3616
public_branch=public_branch, patch_type=patch_type,
3672
public_branch=public_branch, include_patch=include_patch,
3673
include_bundle=include_bundle, message=message,
3674
base_revision_id=base_revision_id)
3618
3675
if mail_to is None:
3620
3677
self.outf.write(directive.to_signed(branch))
3626
3683
s.send_email(message)
3686
class cmd_submit(Command):
3687
"""Create a merge-directive for submiting changes.
3689
A merge directive provides many things needed for requesting merges:
3690
- A machine-readable description of the merge to perform
3691
- An optional patch that is a preview of the changes requested
3692
- An optional bundle of revision data, so that the changes can be applied
3693
directly from the merge directive, without retrieving data from a
3696
If --no-bundle is specified, then public_branch is needed (and must be
3697
up-to-date), so that the receiver can perform the merge using the
3698
public_branch. The public_branch is always included if known, so that
3699
people can check it later.
3701
The submit branch defaults to the parent, but can be overridden. Both
3702
submit branch and public branch will be remembered if supplied.
3704
If a public_branch is known for the submit_branch, that public submit
3705
branch is used in the merge instructions. This means that a local mirror
3706
can be used as your actual submit branch, once you have set public_branch
3710
encoding_type = 'exact'
3712
aliases = ['bundle', 'bundle-revisions']
3714
_see_also = ['merge']
3716
takes_args = ['submit_branch?', 'public_branch?']
3719
help='Do not include a bundle in the merge directive.'),
3720
Option('no-patch', help='Do not include a preview patch in the merge'
3723
help='Remember submit and public branch.'),
3725
help='Branch to generate the submission from, '
3726
'rather than the one containing the working directory.',
3729
Option('output', short_name='o', help='Write directive to this file.',
3734
def run(self, submit_branch=None, public_branch=None, no_bundle=False,
3735
no_patch=False, revision=None, remember=False, output=None,
3737
from bzrlib.revision import ensure_null, NULL_REVISION
3741
outfile = open(output, 'wb')
3743
from_ = kwargs.get('from', '.')
3744
branch = Branch.open_containing(from_)[0]
3745
if remember and submit_branch is None:
3746
raise errors.BzrCommandError(
3747
'--remember requires a branch to be specified.')
3748
stored_submit_branch = branch.get_submit_branch()
3749
remembered_submit_branch = False
3750
if submit_branch is None:
3751
submit_branch = stored_submit_branch
3752
remembered_submit_branch = True
3754
if stored_submit_branch is None or remember:
3755
branch.set_submit_branch(submit_branch)
3756
if submit_branch is None:
3757
submit_branch = branch.get_parent()
3758
remembered_submit_branch = True
3759
if submit_branch is None:
3760
raise errors.BzrCommandError('No submit branch known or'
3762
if remembered_submit_branch:
3763
note('Using saved location: %s', submit_branch)
3765
stored_public_branch = branch.get_public_branch()
3766
if public_branch is None:
3767
public_branch = stored_public_branch
3768
elif stored_public_branch is None or remember:
3769
branch.set_public_branch(public_branch)
3770
if no_bundle and public_branch is None:
3771
raise errors.BzrCommandError('No public branch specified or'
3773
base_revision_id = None
3774
if revision is not None:
3775
if len(revision) > 2:
3776
raise errors.BzrCommandError('bzr submit takes '
3777
'at most two one revision identifiers')
3778
revision_id = revision[-1].in_history(branch).rev_id
3779
if len(revision) == 2:
3780
base_revision_id = revision[0].in_history(branch).rev_id
3781
base_revision_id = ensure_null(base_revision_id)
3783
revision_id = branch.last_revision()
3784
revision_id = ensure_null(revision_id)
3785
if revision_id == NULL_REVISION:
3786
raise errors.BzrCommandError('No revisions to submit.')
3787
directive = merge_directive.MergeDirective2.from_objects(
3788
branch.repository, revision_id, time.time(),
3789
osutils.local_time_offset(), submit_branch,
3790
public_branch=public_branch, include_patch=not no_patch,
3791
include_bundle=not no_bundle, message=None,
3792
base_revision_id=base_revision_id)
3793
outfile.writelines(directive.to_lines())
3795
if output is not None:
3629
3798
class cmd_tag(Command):
3630
3799
"""Create a tag naming a revision.
3829
4004
cur_transport.ensure_base()
4007
def _get_bundle_helper(location):
4008
"""Get a bundle if 'location' points to one.
4010
Try try to identify a bundle and returns its mergeable form. If it's not,
4011
we return the tried transport anyway so that it can reused to access the
4014
:param location: can point to a bundle or a branch.
4016
:return: mergeable, transport
4019
url = urlutils.normalize_url(location)
4020
url, filename = urlutils.split(url, exclude_trailing_slash=False)
4021
location_transport = transport.get_transport(url)
4024
# There may be redirections but we ignore the intermediate
4025
# and final transports used
4026
read = bundle.read_mergeable_from_transport
4027
mergeable, t = read(location_transport, filename)
4028
except errors.NotABundle:
4029
# Continue on considering this url a Branch but adjust the
4030
# location_transport
4031
location_transport = location_transport.clone(filename)
4032
return mergeable, location_transport
3832
4035
# Compatibility
3833
4036
merge = _merge_helper