~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Fix WorkingTree4._iter_changes with pending merges and deleted files

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
    unknown
149
149
        Not versioned and not matching an ignore pattern.
150
150
 
151
 
    To see ignored files use 'bzr ignored'.  For details on the
 
151
    To see ignored files use 'bzr ignored'.  For details in the
152
152
    changes to file texts, use 'bzr diff'.
153
153
    
154
154
    --short gives a status flags for each item, similar to the SVN's status
183
183
    # TODO: --no-recurse, --recurse options
184
184
    
185
185
    takes_args = ['file*']
186
 
    takes_options = ['show-ids', 'revision',
187
 
                     Option('short', help='Give short SVN-style status lines'),
188
 
                     Option('versioned', help='Only show versioned files')]
 
186
    takes_options = ['show-ids', 'revision', 'short']
189
187
    aliases = ['st', 'stat']
190
188
 
191
189
    encoding_type = 'replace'
192
190
    
193
191
    @display_command
194
 
    def run(self, show_ids=False, file_list=None, revision=None, short=False,
195
 
            versioned=False):
 
192
    def run(self, show_ids=False, file_list=None, revision=None, short=False):
196
193
        from bzrlib.status import show_tree_status
197
194
 
198
195
        tree, file_list = tree_files(file_list)
199
196
            
200
197
        show_tree_status(tree, show_ids=show_ids,
201
198
                         specific_files=file_list, revision=revision,
202
 
                         to_file=self.outf, short=short, versioned=versioned)
 
199
                         to_file=self.outf,
 
200
                         short=short)
203
201
 
204
202
 
205
203
class cmd_cat_revision(Command):
569
567
            directory=None):
570
568
        from bzrlib.tag import _merge_tags_if_possible
571
569
        # FIXME: too much stuff is in the command class
572
 
        revision_id = None
573
 
        mergeable = None
574
570
        if directory is None:
575
571
            directory = u'.'
576
572
        try:
583
579
        reader = None
584
580
        if location is not None:
585
581
            try:
586
 
                mergeable = bundle.read_mergeable_from_url(
587
 
                    location)
 
582
                reader = bundle.read_bundle_from_url(location)
588
583
            except errors.NotABundle:
589
584
                pass # Continue on considering this url a Branch
590
585
 
599
594
                self.outf.write("Using saved location: %s\n" % display_url)
600
595
                location = stored_loc
601
596
 
602
 
        if mergeable is not None:
603
 
            if revision is not None:
604
 
                raise errors.BzrCommandError(
605
 
                    'Cannot use -r with merge directives or bundles')
606
 
            revision_id = mergeable.install_revisions(branch_to.repository)
 
597
        if reader is not None:
 
598
            install_bundle(branch_to.repository, reader)
607
599
            branch_from = branch_to
608
600
        else:
609
601
            branch_from = Branch.open(location)
611
603
            if branch_to.get_parent() is None or remember:
612
604
                branch_to.set_parent(branch_from.base)
613
605
 
614
 
        if revision is not None:
615
 
            if len(revision) == 1:
616
 
                revision_id = revision[0].in_history(branch_from).rev_id
617
 
            else:
618
 
                raise errors.BzrCommandError(
619
 
                    'bzr pull --revision takes one value.')
 
606
        rev_id = None
 
607
        if revision is None:
 
608
            if reader is not None:
 
609
                rev_id = reader.target
 
610
        elif len(revision) == 1:
 
611
            rev_id = revision[0].in_history(branch_from).rev_id
 
612
        else:
 
613
            raise errors.BzrCommandError('bzr pull --revision takes one value.')
620
614
 
621
615
        old_rh = branch_to.revision_history()
622
616
        if tree_to is not None:
623
 
            result = tree_to.pull(branch_from, overwrite, revision_id,
 
617
            result = tree_to.pull(branch_from, overwrite, rev_id,
624
618
                delta._ChangeReporter(unversioned_filter=tree_to.is_ignored))
625
619
        else:
626
 
            result = branch_to.pull(branch_from, overwrite, revision_id)
 
620
            result = branch_to.pull(branch_from, overwrite, rev_id)
627
621
 
628
622
        result.report(self.outf)
629
623
        if verbose:
630
624
            from bzrlib.log import show_changed_revisions
631
625
            new_rh = branch_to.revision_history()
632
 
            show_changed_revisions(branch_to, old_rh, new_rh,
633
 
                                   to_file=self.outf)
 
626
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
634
627
 
635
628
 
636
629
class cmd_push(Command):
840
833
 
841
834
    To retrieve the branch as of a particular revision, supply the --revision
842
835
    parameter, as in "branch foo/bar -r 5".
 
836
 
 
837
    --basis is to speed up branching from remote branches.  When specified, it
 
838
    copies all the file-contents, inventory and revision data from the basis
 
839
    branch before copying anything from the remote branch.
843
840
    """
844
841
    takes_args = ['from_location', 'to_location?']
845
 
    takes_options = ['revision']
 
842
    takes_options = ['revision', 'basis']
846
843
    aliases = ['get', 'clone']
847
844
 
848
 
    def run(self, from_location, to_location=None, revision=None):
 
845
    def run(self, from_location, to_location=None, revision=None, basis=None):
849
846
        from bzrlib.tag import _merge_tags_if_possible
850
847
        if revision is None:
851
848
            revision = [None]
856
853
        br_from = Branch.open(from_location)
857
854
        br_from.lock_read()
858
855
        try:
 
856
            if basis is not None:
 
857
                basis_dir = bzrdir.BzrDir.open_containing(basis)[0]
 
858
            else:
 
859
                basis_dir = None
859
860
            if len(revision) == 1 and revision[0] is not None:
860
861
                revision_id = revision[0].in_history(br_from)[1]
861
862
            else:
880
881
                                             % to_location)
881
882
            try:
882
883
                # preserve whatever source format we have.
883
 
                dir = br_from.bzrdir.sprout(to_transport.base, revision_id)
 
884
                dir = br_from.bzrdir.sprout(to_transport.base,
 
885
                        revision_id, basis_dir)
884
886
                branch = dir.open_branch()
885
887
            except errors.NoSuchRevision:
886
888
                to_transport.delete_tree('.')
887
889
                msg = "The branch %s has no revision %s." % (from_location, revision[0])
888
890
                raise errors.BzrCommandError(msg)
 
891
            except errors.UnlistableBranch:
 
892
                osutils.rmtree(to_location)
 
893
                msg = "The branch %s cannot be used as a --basis" % (basis,)
 
894
                raise errors.BzrCommandError(msg)
889
895
            if name:
890
896
                branch.control_files.put_utf8('branch-name', name)
891
897
            _merge_tags_if_possible(br_from, branch)
910
916
    out of date [so you cannot commit] but it may be useful (i.e. to examine old
911
917
    code.)
912
918
 
 
919
    --basis is to speed up checking out from remote branches.  When specified, it
 
920
    uses the inventory and file contents from the basis branch in preference to the
 
921
    branch being checked out.
 
922
 
913
923
    See "help checkouts" for more information on checkouts.
914
924
    """
915
925
    takes_args = ['branch_location?', 'to_location?']
916
 
    takes_options = ['revision',
 
926
    takes_options = ['revision', # , 'basis']
917
927
                     Option('lightweight',
918
928
                            help="perform a lightweight checkout. Lightweight "
919
929
                                 "checkouts depend on access to the branch for "
924
934
                     ]
925
935
    aliases = ['co']
926
936
 
927
 
    def run(self, branch_location=None, to_location=None, revision=None,
 
937
    def run(self, branch_location=None, to_location=None, revision=None, basis=None,
928
938
            lightweight=False):
929
939
        if revision is None:
930
940
            revision = [None]
1202
1212
 
1203
1213
    If there is a repository in a parent directory of the location, then 
1204
1214
    the history of the branch will be stored in the repository.  Otherwise
1205
 
    init creates a standalone branch which carries its own history
1206
 
    in the .bzr directory.
 
1215
    init creates a standalone branch which carries its own history in 
 
1216
    .bzr.
1207
1217
 
1208
1218
    If there is already a branch at the location but it has no working tree,
1209
1219
    the tree can be populated with 'bzr checkout'.
1276
1286
    """Create a shared repository to hold branches.
1277
1287
 
1278
1288
    New branches created under the repository directory will store their revisions
1279
 
    in the repository, not in the branch directory.
 
1289
    in the repository, not in the branch directory, if the branch format supports
 
1290
    shared storage.
1280
1291
 
1281
1292
    example:
1282
 
        bzr init-repo --no-trees repo
 
1293
        bzr init-repo repo
1283
1294
        bzr init repo/trunk
1284
1295
        bzr checkout --lightweight repo/trunk trunk-checkout
1285
1296
        cd trunk-checkout
1286
1297
        (add files here)
1287
1298
    """
1288
 
 
1289
1299
    takes_args = ["location"]
1290
1300
    takes_options = [RegistryOption('format',
1291
1301
                            help='Specify a format for this repository. See'
1293
1303
                            registry=bzrdir.format_registry,
1294
1304
                            converter=bzrdir.format_registry.make_bzrdir,
1295
1305
                            value_switches=True, title='Repository format'),
1296
 
                     Option('no-trees',
1297
 
                             help='Branches in the repository will default to'
1298
 
                                  ' not having a working tree'),
1299
 
                    ]
 
1306
                     Option('trees',
 
1307
                             help='Allows branches in repository to have'
 
1308
                             ' a working tree')]
1300
1309
    aliases = ["init-repo"]
1301
 
 
1302
 
    def run(self, location, format=None, no_trees=False):
 
1310
    def run(self, location, format=None, trees=False):
1303
1311
        if format is None:
1304
1312
            format = bzrdir.format_registry.make_bzrdir('default')
1305
1313
 
1314
1322
 
1315
1323
        newdir = format.initialize_on_transport(to_transport)
1316
1324
        repo = newdir.create_repository(shared=True)
1317
 
        repo.set_make_working_trees(not no_trees)
 
1325
        repo.set_make_working_trees(trees)
1318
1326
 
1319
1327
 
1320
1328
class cmd_diff(Command):
1906
1914
 
1907
1915
 
1908
1916
class cmd_export(Command):
1909
 
    """Export current or past revision to a destination directory or archive.
 
1917
    """Export past revision to destination directory.
1910
1918
 
1911
1919
    If no revision is specified this exports the last committed revision.
1912
1920
 
1917
1925
    Root may be the top directory for tar, tgz and tbz2 formats. If none
1918
1926
    is given, the top directory will be the root name of the file.
1919
1927
 
1920
 
    If branch is omitted then the branch containing the current working
1921
 
    directory will be used.
 
1928
    If branch is omitted then the branch containing the CWD will be used.
1922
1929
 
1923
1930
    Note: export of tree with non-ascii filenames to zip is not supported.
1924
1931
 
1956
1963
 
1957
1964
 
1958
1965
class cmd_cat(Command):
1959
 
    """Write the contents of a file as of a given revision to standard output.
1960
 
 
1961
 
    If no revision is nominated, the last revision is used.
1962
 
 
1963
 
    Note: Take care to redirect standard output when using this command on a
1964
 
    binary file. 
1965
 
    """
 
1966
    """Write a file's text from a previous revision."""
1966
1967
 
1967
1968
    takes_options = ['revision', 'name-from-revision']
1968
1969
    takes_args = ['filename']
2235
2236
 
2236
2237
    @display_command
2237
2238
    def printme(self, branch):
2238
 
        print branch.nick
 
2239
        print branch.nick 
2239
2240
 
2240
2241
 
2241
2242
class cmd_selftest(Command):
2295
2296
    takes_args = ['testspecs*']
2296
2297
    takes_options = ['verbose',
2297
2298
                     Option('one', help='stop when one test fails'),
2298
 
                     Option('keep-output',
 
2299
                     Option('keep-output', 
2299
2300
                            help='keep output directories when tests fail'),
2300
 
                     Option('transport',
 
2301
                     Option('transport', 
2301
2302
                            help='Use a different transport by default '
2302
2303
                                 'throughout the test suite.',
2303
2304
                            type=get_transport_type),
2304
 
                     Option('benchmark', help='run the bzr benchmarks.'),
 
2305
                     Option('benchmark', help='run the bzr bencharks.'),
2305
2306
                     Option('lsprof-timed',
2306
2307
                            help='generate lsprof output for benchmarked'
2307
2308
                                 ' sections of code.'),
2312
2313
                            help='clean temporary tests directories'
2313
2314
                                 ' without running tests'),
2314
2315
                     Option('first',
2315
 
                            help='run all tests, but run specified tests first'
 
2316
                            help='run all tests, but run specified tests first',
2316
2317
                            ),
2317
2318
                     Option('numbered-dirs',
2318
2319
                            help='use numbered dirs for TestCaseInTempDir'),
2464
2465
    
2465
2466
    merge refuses to run if there are any uncommitted changes, unless
2466
2467
    --force is given.
 
2468
 
 
2469
    The following merge types are available:
2467
2470
    """
2468
2471
    takes_args = ['branch?']
2469
2472
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2489
2492
            directory=None,
2490
2493
            ):
2491
2494
        from bzrlib.tag import _merge_tags_if_possible
2492
 
        other_revision_id = None
2493
2495
        if merge_type is None:
2494
2496
            merge_type = _mod_merge.Merge3Merger
2495
2497
 
2507
2509
 
2508
2510
        if branch is not None:
2509
2511
            try:
2510
 
                mergeable = bundle.read_mergeable_from_url(
2511
 
                    branch)
 
2512
                reader = bundle.read_bundle_from_url(branch)
2512
2513
            except errors.NotABundle:
2513
2514
                pass # Continue on considering this url a Branch
2514
2515
            else:
2515
 
                if revision is not None:
2516
 
                    raise errors.BzrCommandError(
2517
 
                        'Cannot use -r with merge directives or bundles')
2518
 
                other_revision_id = mergeable.install_revisions(
2519
 
                    tree.branch.repository)
2520
 
                revision = [RevisionSpec.from_string(
2521
 
                    'revid:' + other_revision_id)]
 
2516
                conflicts = merge_bundle(reader, tree, not force, merge_type,
 
2517
                                         reprocess, show_base, change_reporter)
 
2518
                if conflicts == 0:
 
2519
                    return 0
 
2520
                else:
 
2521
                    return 1
2522
2522
 
2523
2523
        if revision is None \
2524
2524
                or len(revision) < 1 or revision[0].needs_branch():
2539
2539
            branch = revision[0].get_branch() or branch
2540
2540
            if len(revision) == 1:
2541
2541
                base = [None, None]
2542
 
                if other_revision_id is not None:
2543
 
                    other_branch = None
2544
 
                    path = ""
2545
 
                    other = None
2546
 
                else:
2547
 
                    other_branch, path = Branch.open_containing(branch)
2548
 
                    revno = revision[0].in_history(other_branch).revno
2549
 
                    other = [branch, revno]
 
2542
                other_branch, path = Branch.open_containing(branch)
 
2543
                revno = revision[0].in_history(other_branch).revno
 
2544
                other = [branch, revno]
2550
2545
            else:
2551
2546
                assert len(revision) == 2
2552
2547
                if None in revision:
2562
2557
                base = [branch, revision[0].in_history(base_branch).revno]
2563
2558
                other = [branch1, revision[1].in_history(other_branch).revno]
2564
2559
 
2565
 
        if ((tree.branch.get_parent() is None or remember) and
2566
 
            other_branch is not None):
 
2560
        if tree.branch.get_parent() is None or remember:
2567
2561
            tree.branch.set_parent(other_branch.base)
2568
2562
 
2569
2563
        # pull tags now... it's a bit inconsistent to do it ahead of copying
2570
2564
        # the history but that's done inside the merge code
2571
 
        if other_branch is not None:
2572
 
            _merge_tags_if_possible(other_branch, tree.branch)
 
2565
        _merge_tags_if_possible(other_branch, tree.branch)
2573
2566
 
2574
2567
        if path != "":
2575
2568
            interesting_files = [path]
2579
2572
        try:
2580
2573
            try:
2581
2574
                conflict_count = _merge_helper(
2582
 
                    other, base, other_rev_id=other_revision_id,
2583
 
                    check_clean=(not force),
 
2575
                    other, base, check_clean=(not force),
2584
2576
                    merge_type=merge_type,
2585
2577
                    reprocess=reprocess,
2586
2578
                    show_base=show_base,
2639
2631
    $ bzr remerge --merge-type weave --reprocess foobar
2640
2632
        Re-do the merge of "foobar", using the weave merge algorithm, with
2641
2633
        additional processing to reduce the size of conflict regions.
2642
 
    """
 
2634
    
 
2635
    The following merge types are available:"""
2643
2636
    takes_args = ['file*']
2644
2637
    takes_options = ['merge-type', 'reprocess',
2645
2638
                     Option('show-base', help="Show base revision text in "
2731
2724
    """
2732
2725
    takes_options = ['revision', 'no-backup']
2733
2726
    takes_args = ['file*']
 
2727
    aliases = ['merge-revert']
2734
2728
 
2735
2729
    def run(self, revision=None, no_backup=False, file_list=None):
2736
2730
        if file_list is not None:
3252
3246
class cmd_join(Command):
3253
3247
    """Combine a subtree into its containing tree.
3254
3248
    
3255
 
    This command is for experimental use only.  It requires the target tree
3256
 
    to be in dirstate-with-subtree format, which cannot be converted into
3257
 
    earlier formats.
3258
 
 
3259
 
    The TREE argument should be an independent tree, inside another tree, but
3260
 
    not part of it.  (Such trees can be produced by "bzr split", but also by
3261
 
    running "bzr branch" with the target inside a tree.)
3262
 
 
3263
 
    The result is a combined tree, with the subtree no longer an independant
3264
 
    part.  This is marked as a merge of the subtree into the containing tree,
3265
 
    and all history is preserved.
3266
 
 
3267
 
    If --reference is specified, the subtree retains its independence.  It can
3268
 
    be branched by itself, and can be part of multiple projects at the same
3269
 
    time.  But operations performed in the containing tree, such as commit
3270
 
    and merge, will recurse into the subtree.
 
3249
    This is marked as a merge of the subtree into the containing tree, and all
 
3250
    history is preserved.
3271
3251
    """
3272
3252
 
3273
3253
    takes_args = ['tree']
3274
3254
    takes_options = [Option('reference', 'join by reference')]
3275
 
    hidden = True
3276
3255
 
3277
3256
    def run(self, tree, reference=False):
3278
3257
        sub_tree = WorkingTree.open(tree)
3302
3281
 
3303
3282
class cmd_split(Command):
3304
3283
    """Split a tree into two trees.
3305
 
 
3306
 
    This command is for experimental use only.  It requires the target tree
3307
 
    to be in dirstate-with-subtree format, which cannot be converted into
3308
 
    earlier formats.
3309
 
 
3310
 
    The TREE argument should be a subdirectory of a working tree.  That
3311
 
    subdirectory will be converted into an independent tree, with its own
3312
 
    branch.  Commits in the top-level tree will not apply to the new subtree.
3313
 
    If you want that behavior, do "bzr join --reference TREE".
3314
 
 
3315
 
    To undo this operation, do "bzr join TREE".
3316
3284
    """
3317
3285
 
3318
3286
    takes_args = ['tree']
3319
3287
 
3320
 
    hidden = True
3321
 
 
3322
3288
    def run(self, tree):
3323
3289
        containing_tree, subdir = WorkingTree.open_containing(tree)
3324
3290
        sub_id = containing_tree.path2id(subdir)
3412
3378
            server = branch.get_config().get_user_option('smtp_server')
3413
3379
            if not server:
3414
3380
                server = 'localhost'
3415
 
            s.connect(server)
 
3381
            s.connect()
3416
3382
            s.sendmail(message['From'], message['To'], message.as_string())
3417
3383
 
3418
3384
 
3506
3472
                  file_list=None, show_base=False, reprocess=False,
3507
3473
                  pull=False,
3508
3474
                  pb=DummyProgress(),
3509
 
                  change_reporter=None,
3510
 
                  other_rev_id=None):
 
3475
                  change_reporter=None):
3511
3476
    """Merge changes into a tree.
3512
3477
 
3513
3478
    base_revision
3563
3528
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3564
3529
        merger.pp.next_phase()
3565
3530
        merger.check_basis(check_clean)
3566
 
        if other_rev_id is not None:
3567
 
            merger.set_other_revision(other_rev_id, this_tree.branch)
3568
 
        else:
3569
 
            merger.set_other(other_revision)
 
3531
        merger.set_other(other_revision)
3570
3532
        merger.pp.next_phase()
3571
3533
        merger.set_base(base_revision)
3572
3534
        if merger.base_rev_id == merger.other_rev_id: