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

  • Committer: Robert Collins
  • Date: 2008-04-04 00:43:07 UTC
  • mfrom: (3331 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3333.
  • Revision ID: robertc@robertcollins.net-20080404004307-0whomfhm3yal2rvw
Resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
                if rev is None:
222
222
                    raise errors.BzrCommandError('You cannot specify a NULL'
223
223
                                                 ' revision.')
224
 
                revno, rev_id = rev.in_history(b)
 
224
                rev_id = rev.as_revision_id(b)
225
225
                self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
226
226
    
227
227
 
295
295
            revs.append(RevisionSpec.from_string('-1'))
296
296
 
297
297
        for rev in revs:
298
 
            revinfo = rev.in_history(b)
299
 
            if revinfo.revno is None:
 
298
            revision_id = rev.as_revision_id(b)
 
299
            try:
 
300
                revno = '%4d' % (b.revision_id_to_revno(revision_id))
 
301
            except errors.NoSuchRevision:
300
302
                dotted_map = b.get_revision_id_to_revno_map()
301
 
                revno = '.'.join(str(i) for i in dotted_map[revinfo.rev_id])
302
 
                print '%s %s' % (revno, revinfo.rev_id)
303
 
            else:
304
 
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
 
303
                revno = '.'.join(str(i) for i in dotted_map[revision_id])
 
304
            print '%s %s' % (revno, revision_id)
305
305
 
306
306
    
307
307
class cmd_add(Command):
466
466
                    raise errors.BzrCommandError(
467
467
                        'bzr inventory --revision takes exactly one revision'
468
468
                        ' identifier')
469
 
                revision_id = revision[0].in_history(work_tree.branch).rev_id
 
469
                revision_id = revision[0].as_revision_id(work_tree.branch)
470
470
                tree = work_tree.branch.repository.revision_tree(revision_id)
471
471
 
472
472
                extra_trees = [work_tree]
534
534
        if len(names_list) < 2:
535
535
            raise errors.BzrCommandError("missing file argument")
536
536
        tree, rel_names = tree_files(names_list)
537
 
        
538
 
        if os.path.isdir(names_list[-1]):
 
537
        tree.lock_write()
 
538
        try:
 
539
            self._run(tree, names_list, rel_names, after)
 
540
        finally:
 
541
            tree.unlock()
 
542
 
 
543
    def _run(self, tree, names_list, rel_names, after):
 
544
        into_existing = osutils.isdir(names_list[-1])
 
545
        if into_existing and len(names_list) == 2:
 
546
            # special cases:
 
547
            # a. case-insensitive filesystem and change case of dir
 
548
            # b. move directory after the fact (if the source used to be
 
549
            #    a directory, but now doesn't exist in the working tree
 
550
            #    and the target is an existing directory, just rename it)
 
551
            if (not tree.case_sensitive
 
552
                and rel_names[0].lower() == rel_names[1].lower()):
 
553
                into_existing = False
 
554
            else:
 
555
                inv = tree.inventory
 
556
                from_id = tree.path2id(rel_names[0])
 
557
                if (not osutils.lexists(names_list[0]) and
 
558
                    from_id and inv.get_file_kind(from_id) == "directory"):
 
559
                    into_existing = False
 
560
        # move/rename
 
561
        if into_existing:
539
562
            # move into existing directory
540
563
            for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
541
564
                self.outf.write("%s => %s\n" % pair)
546
569
                                             ' directory')
547
570
            tree.rename_one(rel_names[0], rel_names[1], after=after)
548
571
            self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
549
 
            
550
 
    
 
572
 
 
573
 
551
574
class cmd_pull(Command):
552
575
    """Turn this branch into a mirror of another branch.
553
576
 
566
589
    that, you can omit the location to use the default.  To change the
567
590
    default, use --remember. The value will only be saved if the remote
568
591
    location can be accessed.
 
592
 
 
593
    Note: The location can be specified either in the form of a branch,
 
594
    or in the form of a path to a file containing a merge directive generated
 
595
    with bzr send.
569
596
    """
570
597
 
571
598
    _see_also = ['push', 'update', 'status-flags']
599
626
 
600
627
        possible_transports = []
601
628
        if location is not None:
602
 
            mergeable, location_transport = _get_mergeable_helper(location)
603
 
            possible_transports.append(location_transport)
 
629
            try:
 
630
                mergeable = bundle.read_mergeable_from_url(location,
 
631
                    possible_transports=possible_transports)
 
632
            except errors.NotABundle:
 
633
                mergeable = None
604
634
 
605
635
        stored_loc = branch_to.get_parent()
606
636
        if location is None:
613
643
                if not is_quiet():
614
644
                    self.outf.write("Using saved location: %s\n" % display_url)
615
645
                location = stored_loc
616
 
                location_transport = transport.get_transport(
617
 
                    location, possible_transports=possible_transports)
618
646
 
619
647
        if mergeable is not None:
620
648
            if revision is not None:
625
653
                mergeable.get_merge_request(branch_to.repository)
626
654
            branch_from = branch_to
627
655
        else:
628
 
            branch_from = Branch.open_from_transport(location_transport)
 
656
            branch_from = Branch.open(location,
 
657
                possible_transports=possible_transports)
629
658
 
630
659
            if branch_to.get_parent() is None or remember:
631
660
                branch_to.set_parent(branch_from.base)
632
661
 
633
662
        if revision is not None:
634
663
            if len(revision) == 1:
635
 
                revision_id = revision[0].in_history(branch_from).rev_id
 
664
                revision_id = revision[0].as_revision_id(branch_from)
636
665
            else:
637
666
                raise errors.BzrCommandError(
638
667
                    'bzr pull --revision takes one value.')
682
711
    """
683
712
 
684
713
    _see_also = ['pull', 'update', 'working-trees']
685
 
    takes_options = ['remember', 'overwrite', 'verbose',
 
714
    takes_options = ['remember', 'overwrite', 'verbose', 'revision',
686
715
        Option('create-prefix',
687
716
               help='Create the path leading up to the branch '
688
717
                    'if it does not already exist.'),
702
731
    encoding_type = 'replace'
703
732
 
704
733
    def run(self, location=None, remember=False, overwrite=False,
705
 
            create_prefix=False, verbose=False,
 
734
            create_prefix=False, verbose=False, revision=None,
706
735
            use_existing_dir=False,
707
736
            directory=None):
708
737
        # FIXME: Way too big!  Put this into a function called from the
741
770
            else:
742
771
                # Found a branch, so we must have found a repository
743
772
                repository_to = br_to.repository
 
773
 
 
774
        if revision is not None:
 
775
            if len(revision) == 1:
 
776
                revision_id = revision[0].in_history(br_from).rev_id
 
777
            else:
 
778
                raise errors.BzrCommandError(
 
779
                    'bzr push --revision takes one value.')
 
780
        else:
 
781
            revision_id = br_from.last_revision()
 
782
 
744
783
        push_result = None
745
784
        if verbose:
746
785
            old_rh = []
781
820
            # directory. So we need to create it, along with any work to create
782
821
            # all of the dependent branches, etc.
783
822
            dir_to = br_from.bzrdir.clone_on_transport(to_transport,
784
 
                revision_id=br_from.last_revision())
 
823
                                                       revision_id=revision_id)
785
824
            br_to = dir_to.open_branch()
786
825
            # TODO: Some more useful message about what was copied
787
826
            note('Created new branch.')
799
838
        elif br_to is None:
800
839
            # We have a repository but no branch, copy the revisions, and then
801
840
            # create a branch.
802
 
            last_revision_id = br_from.last_revision()
803
 
            repository_to.fetch(br_from.repository,
804
 
                                revision_id=last_revision_id)
805
 
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
 
841
            repository_to.fetch(br_from.repository, revision_id=revision_id)
 
842
            br_to = br_from.clone(dir_to, revision_id=revision_id)
806
843
            note('Created new branch.')
807
844
            if br_from.get_push_location() is None or remember:
808
845
                br_from.set_push_location(br_to.base)
820
857
                    warning("This transport does not update the working " 
821
858
                            "tree of: %s. See 'bzr help working-trees' for "
822
859
                            "more information." % br_to.base)
823
 
                    push_result = br_from.push(br_to, overwrite)
 
860
                    push_result = br_from.push(br_to, overwrite,
 
861
                                               stop_revision=revision_id)
824
862
                except errors.NoWorkingTree:
825
 
                    push_result = br_from.push(br_to, overwrite)
 
863
                    push_result = br_from.push(br_to, overwrite,
 
864
                                               stop_revision=revision_id)
826
865
                else:
827
866
                    tree_to.lock_write()
828
867
                    try:
829
 
                        push_result = br_from.push(tree_to.branch, overwrite)
 
868
                        push_result = br_from.push(tree_to.branch, overwrite,
 
869
                                                   stop_revision=revision_id)
830
870
                        tree_to.update()
831
871
                    finally:
832
872
                        tree_to.unlock()
882
922
        br_from.lock_read()
883
923
        try:
884
924
            if len(revision) == 1 and revision[0] is not None:
885
 
                revision_id = revision[0].in_history(br_from)[1]
 
925
                revision_id = revision[0].as_revision_id(br_from)
886
926
            else:
887
927
                # FIXME - wt.last_revision, fallback to branch, fall back to
888
928
                # None or perhaps NULL_REVISION to mean copy nothing
976
1016
        if files_from is not None:
977
1017
            accelerator_tree = WorkingTree.open(files_from)
978
1018
        if len(revision) == 1 and revision[0] is not None:
979
 
            revision_id = _mod_revision.ensure_null(
980
 
                revision[0].in_history(source)[1])
 
1019
            revision_id = revision[0].as_revision_id(source)
981
1020
        else:
982
1021
            revision_id = None
983
1022
        if to_location is None:
1837
1876
            relpath += '/'
1838
1877
        if revision is not None:
1839
1878
            tree = branch.repository.revision_tree(
1840
 
                revision[0].in_history(branch).rev_id)
 
1879
                revision[0].as_revision_id(branch))
1841
1880
        elif tree is None:
1842
1881
            tree = branch.basis_tree()
1843
1882
 
1935
1974
        Ignore .o files under the lib directory::
1936
1975
 
1937
1976
            bzr ignore "RE:lib/.*\.o"
 
1977
 
 
1978
        Ignore everything but the "debian" toplevel directory::
 
1979
 
 
1980
            bzr ignore "RE:(?!debian/).*"
1938
1981
    """
1939
1982
 
1940
1983
    _see_also = ['status', 'ignored']
2098
2141
        else:
2099
2142
            if len(revision) != 1:
2100
2143
                raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
2101
 
            rev_id = revision[0].in_history(b).rev_id
 
2144
            rev_id = revision[0].as_revision_id(b)
2102
2145
        t = b.repository.revision_tree(rev_id)
2103
2146
        try:
2104
2147
            export(t, dest, format, root)
2143
2186
        if revision is None:
2144
2187
            revision_id = b.last_revision()
2145
2188
        else:
2146
 
            revision_id = revision[0].in_history(b).rev_id
 
2189
            revision_id = revision[0].as_revision_id(b)
2147
2190
 
2148
2191
        cur_file_id = tree.path2id(relpath)
2149
2192
        rev_tree = b.repository.revision_tree(revision_id)
2404
2447
                try:
2405
2448
                    repo_basis = tree.branch.repository.revision_tree(
2406
2449
                        tree.last_revision())
2407
 
                    if len(list(repo_basis._iter_changes(tree_basis))):
 
2450
                    if len(list(repo_basis.iter_changes(tree_basis))):
2408
2451
                        raise errors.BzrCheckError(
2409
2452
                            "Mismatched basis inventory content.")
2410
2453
                    tree._validate()
2628
2671
            print '   %s (%s python%s)' % (
2629
2672
                    bzrlib.__path__[0],
2630
2673
                    bzrlib.version_string,
2631
 
                    '.'.join(map(str, sys.version_info)),
 
2674
                    bzrlib._format_version_tuple(sys.version_info),
2632
2675
                    )
2633
2676
        print
2634
2677
        if testspecs_list is not None:
2723
2766
class cmd_merge(Command):
2724
2767
    """Perform a three-way merge.
2725
2768
    
2726
 
    The branch is the branch you will merge from.  By default, it will merge
2727
 
    the latest revision.  If you specify a revision, that revision will be
2728
 
    merged.  If you specify two revisions, the first will be used as a BASE,
2729
 
    and the second one as OTHER.  Revision numbers are always relative to the
2730
 
    specified branch.
 
2769
    The source of the merge can be specified either in the form of a branch,
 
2770
    or in the form of a path to a file containing a merge directive generated
 
2771
    with bzr send. If neither is specified, the default is the upstream branch
 
2772
    or the branch most recently merged using --remember.
 
2773
 
 
2774
    When merging a branch, by default the tip will be merged. To pick a different
 
2775
    revision, pass --revision. If you specify two values, the first will be used as
 
2776
    BASE and the second one as OTHER. Merging individual revisions, or a subset of
 
2777
    available revisions, like this is commonly referred to as "cherrypicking".
 
2778
 
 
2779
    Revision numbers are always relative to the branch being merged.
2731
2780
 
2732
2781
    By default, bzr will try to merge in all new work from the other
2733
2782
    branch, automatically determining an appropriate base.  If this
2764
2813
        To merge the changes introduced by 82, without previous changes::
2765
2814
 
2766
2815
            bzr merge -r 81..82 ../bzr.dev
 
2816
 
 
2817
        To apply a merge directive contained in in /tmp/merge:
 
2818
 
 
2819
            bzr merge /tmp/merge
2767
2820
    """
2768
2821
 
2769
2822
    encoding_type = 'exact'
2770
2823
    _see_also = ['update', 'remerge', 'status-flags']
2771
 
    takes_args = ['branch?']
 
2824
    takes_args = ['location?']
2772
2825
    takes_options = [
2773
2826
        'change',
2774
2827
        'revision',
2794
2847
        Option('preview', help='Instead of merging, show a diff of the merge.')
2795
2848
    ]
2796
2849
 
2797
 
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2798
 
            show_base=False, reprocess=False, remember=False,
 
2850
    def run(self, location=None, revision=None, force=False,
 
2851
            merge_type=None, show_base=False, reprocess=False, remember=False,
2799
2852
            uncommitted=False, pull=False,
2800
2853
            directory=None,
2801
2854
            preview=False,
2802
2855
            ):
2803
 
        # This is actually a branch (or merge-directive) *location*.
2804
 
        location = branch
2805
 
        del branch
2806
 
 
2807
2856
        if merge_type is None:
2808
2857
            merge_type = _mod_merge.Merge3Merger
2809
2858
 
2822
2871
            tree.lock_write()
2823
2872
            cleanups.append(tree.unlock)
2824
2873
            if location is not None:
2825
 
                mergeable, other_transport = _get_mergeable_helper(location)
2826
 
                if mergeable:
 
2874
                try:
 
2875
                    mergeable = bundle.read_mergeable_from_url(location,
 
2876
                        possible_transports=possible_transports)
 
2877
                except errors.NotABundle:
 
2878
                    mergeable = None
 
2879
                else:
2827
2880
                    if uncommitted:
2828
2881
                        raise errors.BzrCommandError('Cannot use --uncommitted'
2829
2882
                            ' with bundles or merge directives.')
2833
2886
                            'Cannot use -r with merge directives or bundles')
2834
2887
                    merger, verified = _mod_merge.Merger.from_mergeable(tree,
2835
2888
                       mergeable, pb)
2836
 
                possible_transports.append(other_transport)
2837
2889
 
2838
2890
            if merger is None and uncommitted:
2839
2891
                if revision is not None and len(revision) > 0:
2939
2991
            other_revision_id = _mod_revision.ensure_null(
2940
2992
                other_branch.last_revision())
2941
2993
        else:
2942
 
            other_revision_id = \
2943
 
                _mod_revision.ensure_null(
2944
 
                    revision[-1].in_history(other_branch).rev_id)
 
2994
            other_revision_id = revision[-1].as_revision_id(other_branch)
2945
2995
        if (revision is not None and len(revision) == 2
2946
2996
            and revision[0] is not None):
2947
 
            base_revision_id = \
2948
 
                _mod_revision.ensure_null(
2949
 
                    revision[0].in_history(base_branch).rev_id)
 
2997
            base_revision_id = revision[0].as_revision_id(base_branch)
2950
2998
        else:
2951
2999
            base_revision_id = None
2952
3000
        # Remember where we merge from
3003
3051
        mutter("%s", stored_location)
3004
3052
        if stored_location is None:
3005
3053
            raise errors.BzrCommandError("No location specified or remembered")
3006
 
        display_url = urlutils.unescape_for_display(stored_location,
3007
 
            self.outf.encoding)
3008
 
        self.outf.write("%s remembered location %s\n" % (verb_string,
3009
 
            display_url))
 
3054
        display_url = urlutils.unescape_for_display(stored_location, 'utf-8')
 
3055
        note(u"%s remembered location %s", verb_string, display_url)
3010
3056
        return stored_location
3011
3057
 
3012
3058
 
3167
3213
        elif len(revision) != 1:
3168
3214
            raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
3169
3215
        else:
3170
 
            rev_id = revision[0].in_history(tree.branch).rev_id
 
3216
            rev_id = revision[0].as_revision_id(tree.branch)
3171
3217
        pb = ui.ui_factory.nested_progress_bar()
3172
3218
        try:
3173
3219
            tree.revert(file_list,
3418
3464
            if revision is None:
3419
3465
                rev_id = b.last_revision()
3420
3466
            else:
3421
 
                rev_id = revision[0].in_history(b).rev_id
 
3467
                rev_id = revision[0].as_revision_id(b)
3422
3468
            t = testament_class.from_revision(b.repository, rev_id)
3423
3469
            if long:
3424
3470
                sys.stdout.writelines(t.as_text_lines())
3465
3511
            elif len(revision) != 1:
3466
3512
                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3467
3513
            else:
3468
 
                revision_id = revision[0].in_history(branch).rev_id
 
3514
                revision_id = revision[0].as_revision_id(branch)
3469
3515
            tree = branch.repository.revision_tree(revision_id)
3470
3516
            if wt is not None:
3471
3517
                file_id = wt.path2id(relpath)
3621
3667
    _see_also = ['commit']
3622
3668
    takes_options = ['verbose', 'revision',
3623
3669
                    Option('dry-run', help='Don\'t actually make changes.'),
3624
 
                    Option('force', help='Say yes to all questions.')]
 
3670
                    Option('force', help='Say yes to all questions.'),
 
3671
                    Option('local',
 
3672
                           help="Only remove the commits from the local branch"
 
3673
                                " when in a checkout."
 
3674
                           ),
 
3675
                    ]
3625
3676
    takes_args = ['location?']
3626
3677
    aliases = []
3627
3678
    encoding_type = 'replace'
3628
3679
 
3629
3680
    def run(self, location=None,
3630
3681
            dry_run=False, verbose=False,
3631
 
            revision=None, force=False):
 
3682
            revision=None, force=False, local=False):
3632
3683
        if location is None:
3633
3684
            location = u'.'
3634
3685
        control, relpath = bzrdir.BzrDir.open_containing(location)
3644
3695
        else:
3645
3696
            b.lock_write()
3646
3697
        try:
3647
 
            return self._run(b, tree, dry_run, verbose, revision, force)
 
3698
            return self._run(b, tree, dry_run, verbose, revision, force,
 
3699
                             local=local)
3648
3700
        finally:
3649
3701
            if tree is not None:
3650
3702
                tree.unlock()
3651
3703
            else:
3652
3704
                b.unlock()
3653
3705
 
3654
 
    def _run(self, b, tree, dry_run, verbose, revision, force):
 
3706
    def _run(self, b, tree, dry_run, verbose, revision, force, local=False):
3655
3707
        from bzrlib.log import log_formatter, show_log
3656
3708
        from bzrlib.uncommit import uncommit
3657
3709
 
3699
3751
                    return 0
3700
3752
 
3701
3753
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
3702
 
                 revno=revno)
 
3754
                 revno=revno, local=local)
3703
3755
 
3704
3756
 
3705
3757
class cmd_break_lock(Command):
3960
4012
            if len(revision) > 2:
3961
4013
                raise errors.BzrCommandError('bzr merge-directive takes '
3962
4014
                    'at most two one revision identifiers')
3963
 
            revision_id = revision[-1].in_history(branch).rev_id
 
4015
            revision_id = revision[-1].as_revision_id(branch)
3964
4016
            if len(revision) == 2:
3965
 
                base_revision_id = revision[0].in_history(branch).rev_id
3966
 
                base_revision_id = ensure_null(base_revision_id)
 
4017
                base_revision_id = revision[0].as_revision_id(branch)
3967
4018
        else:
3968
4019
            revision_id = branch.last_revision()
3969
4020
        revision_id = ensure_null(revision_id)
4022
4073
    generic options are "default", "editor", "mapi", and "xdg-email".
4023
4074
 
4024
4075
    If mail is being sent, a to address is required.  This can be supplied
4025
 
    either on the commandline, or by setting the submit_to configuration
4026
 
    option.
 
4076
    either on the commandline, by setting the submit_to configuration
 
4077
    option in the branch itself or the child_submit_to configuration option 
 
4078
    in the submit branch.
4027
4079
 
4028
4080
    Two formats are currently supported: "4" uses revision bundle format 4 and
4029
4081
    merge directive format 2.  It is significantly faster and smaller than
4030
4082
    older formats.  It is compatible with Bazaar 0.19 and later.  It is the
4031
4083
    default.  "0.9" uses revision bundle format 0.9 and merge directive
4032
4084
    format 1.  It is compatible with Bazaar 0.12 - 0.18.
 
4085
    
 
4086
    Merge directives are applied using the merge command or the pull command.
4033
4087
    """
4034
4088
 
4035
4089
    encoding_type = 'exact'
4036
4090
 
4037
 
    _see_also = ['merge']
 
4091
    _see_also = ['merge', 'pull']
4038
4092
 
4039
4093
    takes_args = ['submit_branch?', 'public_branch?']
4040
4094
 
4108
4162
            if remembered_submit_branch:
4109
4163
                note('Using saved location: %s', submit_branch)
4110
4164
 
 
4165
            if mail_to is None:
 
4166
                submit_config = Branch.open(submit_branch).get_config()
 
4167
                mail_to = submit_config.get_user_option("child_submit_to")
 
4168
 
4111
4169
            stored_public_branch = branch.get_public_branch()
4112
4170
            if public_branch is None:
4113
4171
                public_branch = stored_public_branch
4122
4180
                if len(revision) > 2:
4123
4181
                    raise errors.BzrCommandError('bzr send takes '
4124
4182
                        'at most two one revision identifiers')
4125
 
                revision_id = revision[-1].in_history(branch).rev_id
 
4183
                revision_id = revision[-1].as_revision_id(branch)
4126
4184
                if len(revision) == 2:
4127
 
                    base_revision_id = revision[0].in_history(branch).rev_id
 
4185
                    base_revision_id = revision[0].as_revision_id(branch)
4128
4186
            if revision_id is None:
4129
4187
                revision_id = branch.last_revision()
4130
4188
            if revision_id == NULL_REVISION:
4162
4220
                else:
4163
4221
                    revision = branch.repository.get_revision(revision_id)
4164
4222
                    subject += revision.get_summary()
 
4223
                basename = directive.get_disk_name(branch)
4165
4224
                mail_client.compose_merge_request(mail_to, subject,
4166
 
                                                  outfile.getvalue())
 
4225
                                                  outfile.getvalue(), basename)
4167
4226
        finally:
4168
4227
            if output != '-':
4169
4228
                outfile.close()
4289
4348
                        raise errors.BzrCommandError(
4290
4349
                            "Tags can only be placed on a single revision, "
4291
4350
                            "not on a range")
4292
 
                    revision_id = revision[0].in_history(branch).rev_id
 
4351
                    revision_id = revision[0].as_revision_id(branch)
4293
4352
                else:
4294
4353
                    revision_id = branch.last_revision()
4295
4354
                if (not force) and branch.tags.has_tag(tag_name):
4437
4496
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
4438
4497
 
4439
4498
 
 
4499
class cmd_hooks(Command):
 
4500
    """Show a branch's currently registered hooks.
 
4501
    """
 
4502
 
 
4503
    hidden = True
 
4504
    takes_args = ['path?']
 
4505
 
 
4506
    def run(self, path=None):
 
4507
        if path is None:
 
4508
            path = '.'
 
4509
        branch_hooks = Branch.open(path).hooks
 
4510
        for hook_type in branch_hooks:
 
4511
            hooks = branch_hooks[hook_type]
 
4512
            self.outf.write("%s:\n" % (hook_type,))
 
4513
            if hooks:
 
4514
                for hook in hooks:
 
4515
                    self.outf.write("  %s\n" %
 
4516
                                    (branch_hooks.get_hook_name(hook),))
 
4517
            else:
 
4518
                self.outf.write("  <no hooks installed>\n")
 
4519
 
 
4520
 
4440
4521
def _create_prefix(cur_transport):
4441
4522
    needed = [cur_transport]
4442
4523
    # Recurse upwards until we can create a directory successfully
4459
4540
        cur_transport.ensure_base()
4460
4541
 
4461
4542
 
4462
 
def _get_mergeable_helper(location):
4463
 
    """Get a merge directive or bundle if 'location' points to one.
4464
 
 
4465
 
    Try try to identify a bundle and returns its mergeable form. If it's not,
4466
 
    we return the tried transport anyway so that it can reused to access the
4467
 
    branch
4468
 
 
4469
 
    :param location: can point to a bundle or a branch.
4470
 
 
4471
 
    :return: mergeable, transport
4472
 
    """
4473
 
    mergeable = None
4474
 
    url = urlutils.normalize_url(location)
4475
 
    url, filename = urlutils.split(url, exclude_trailing_slash=False)
4476
 
    location_transport = transport.get_transport(url)
4477
 
    if filename:
4478
 
        try:
4479
 
            # There may be redirections but we ignore the intermediate
4480
 
            # and final transports used
4481
 
            read = bundle.read_mergeable_from_transport
4482
 
            mergeable, t = read(location_transport, filename)
4483
 
        except errors.NotABundle:
4484
 
            # Continue on considering this url a Branch but adjust the
4485
 
            # location_transport
4486
 
            location_transport = location_transport.clone(filename)
4487
 
    return mergeable, location_transport
4488
 
 
4489
 
 
4490
4543
# these get imported and then picked up by the scan for cmd_*
4491
4544
# TODO: Some more consistent way to split command definitions across files;
4492
4545
# we do need to load at least some information about them to know of