~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: John Arbash Meinel
  • Date: 2007-02-17 01:42:57 UTC
  • mfrom: (2293 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070217014257-3chgn02femptf4co
[merge] bzr.dev 2293 and resolve conflicts, but still broken

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
    this will refuse to run against one.
238
238
    """
239
239
 
240
 
    hidden = True
241
 
 
242
240
    takes_args = ['location?']
243
241
 
244
242
    def run(self, location='.'):
537
535
    location can be accessed.
538
536
    """
539
537
 
540
 
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
 
538
    takes_options = ['remember', 'overwrite', 'revision', 'verbose',
 
539
        Option('directory',
 
540
            help='branch to pull into, '
 
541
                 'rather than the one containing the working directory',
 
542
            short_name='d',
 
543
            type=unicode,
 
544
            ),
 
545
        ]
541
546
    takes_args = ['location?']
542
547
    encoding_type = 'replace'
543
548
 
544
 
    def run(self, location=None, remember=False, overwrite=False, revision=None, verbose=False):
 
549
    def run(self, location=None, remember=False, overwrite=False,
 
550
            revision=None, verbose=False,
 
551
            directory=None):
545
552
        # FIXME: too much stuff is in the command class
 
553
        if directory is None:
 
554
            directory = u'.'
546
555
        try:
547
 
            tree_to = WorkingTree.open_containing(u'.')[0]
 
556
            tree_to = WorkingTree.open_containing(directory)[0]
548
557
            branch_to = tree_to.branch
549
558
        except errors.NoWorkingTree:
550
559
            tree_to = None
551
 
            branch_to = Branch.open_containing(u'.')[0]
 
560
            branch_to = Branch.open_containing(directory)[0]
552
561
 
553
562
        reader = None
554
563
        if location is not None:
568
577
                self.outf.write("Using saved location: %s\n" % display_url)
569
578
                location = stored_loc
570
579
 
571
 
 
572
580
        if reader is not None:
573
581
            install_bundle(branch_to.repository, reader)
574
582
            branch_from = branch_to
589
597
 
590
598
        old_rh = branch_to.revision_history()
591
599
        if tree_to is not None:
592
 
            count = tree_to.pull(branch_from, overwrite, rev_id)
 
600
            count = tree_to.pull(branch_from, overwrite, rev_id,
 
601
                delta.ChangeReporter(tree_to.inventory))
593
602
        else:
594
603
            count = branch_to.pull(branch_from, overwrite, rev_id)
595
604
        note('%d revision(s) pulled.' % (count,))
630
639
    """
631
640
 
632
641
    takes_options = ['remember', 'overwrite', 'verbose',
633
 
                     Option('create-prefix',
634
 
                            help='Create the path leading up to the branch '
635
 
                                 'if it does not already exist'),
636
 
                     Option('use-existing-dir',
637
 
                            help='By default push will fail if the target'
638
 
                                 ' directory exists, but does not already'
639
 
                                 ' have a control directory. This flag will'
640
 
                                 ' allow push to proceed.'),
641
 
                     ]
 
642
        Option('create-prefix',
 
643
               help='Create the path leading up to the branch '
 
644
                    'if it does not already exist'),
 
645
        Option('directory',
 
646
            help='branch to push from, '
 
647
                 'rather than the one containing the working directory',
 
648
            short_name='d',
 
649
            type=unicode,
 
650
            ),
 
651
        Option('use-existing-dir',
 
652
               help='By default push will fail if the target'
 
653
                    ' directory exists, but does not already'
 
654
                    ' have a control directory. This flag will'
 
655
                    ' allow push to proceed.'),
 
656
        ]
642
657
    takes_args = ['location?']
643
658
    encoding_type = 'replace'
644
659
 
645
660
    def run(self, location=None, remember=False, overwrite=False,
646
 
            create_prefix=False, verbose=False, use_existing_dir=False):
 
661
            create_prefix=False, verbose=False,
 
662
            use_existing_dir=False,
 
663
            directory=None):
647
664
        # FIXME: Way too big!  Put this into a function called from the
648
665
        # command.
649
 
        
650
 
        br_from = Branch.open_containing('.')[0]
 
666
        if directory is None:
 
667
            directory = '.'
 
668
        br_from = Branch.open_containing(directory)[0]
651
669
        stored_loc = br_from.get_push_location()
652
670
        if location is None:
653
671
            if stored_loc is None:
813
831
        elif len(revision) > 1:
814
832
            raise errors.BzrCommandError(
815
833
                'bzr branch --revision takes exactly 1 revision value')
816
 
        try:
817
 
            br_from = Branch.open(from_location)
818
 
        except OSError, e:
819
 
            if e.errno == errno.ENOENT:
820
 
                raise errors.BzrCommandError('Source location "%s" does not'
821
 
                                             ' exist.' % to_location)
822
 
            else:
823
 
                raise
 
834
 
 
835
        br_from = Branch.open(from_location)
824
836
        br_from.lock_read()
825
837
        try:
826
838
            if basis is not None:
1194
1206
                value_switches=True,
1195
1207
                title="Branch Format",
1196
1208
                ),
 
1209
         Option('append-revisions-only',
 
1210
                help='Never change revnos or the existing log.'
 
1211
                '  Append revisions to it only.')
1197
1212
         ]
1198
 
    def run(self, location=None, format=None):
 
1213
    def run(self, location=None, format=None, append_revisions_only=False):
1199
1214
        if format is None:
1200
1215
            format = bzrdir.format_registry.make_bzrdir('default')
1201
1216
        if location is None:
1218
1233
            existing_bzrdir = bzrdir.BzrDir.open(location)
1219
1234
        except errors.NotBranchError:
1220
1235
            # really a NotBzrDir error...
1221
 
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
1236
            branch = bzrdir.BzrDir.create_branch_convenience(location,
 
1237
                                                             format=format)
1222
1238
        else:
1223
1239
            from bzrlib.transport.local import LocalTransport
1224
1240
            if existing_bzrdir.has_branch():
1227
1243
                        raise errors.BranchExistsWithoutWorkingTree(location)
1228
1244
                raise errors.AlreadyBranchError(location)
1229
1245
            else:
1230
 
                existing_bzrdir.create_branch()
 
1246
                branch = existing_bzrdir.create_branch()
1231
1247
                existing_bzrdir.create_workingtree()
 
1248
        if append_revisions_only:
 
1249
            try:
 
1250
                branch.set_append_revisions_only(True)
 
1251
            except errors.UpgradeRequired:
 
1252
                raise errors.BzrCommandError('This branch format cannot be set'
 
1253
                    ' to append-revisions-only.  Try --experimental-branch6')
1232
1254
 
1233
1255
 
1234
1256
class cmd_init_repository(Command):
1533
1555
            dir, relpath = bzrdir.BzrDir.open_containing(location)
1534
1556
            b = dir.open_branch()
1535
1557
 
1536
 
        if revision is None:
1537
 
            rev1 = None
1538
 
            rev2 = None
1539
 
        elif len(revision) == 1:
1540
 
            rev1 = rev2 = revision[0].in_history(b).revno
1541
 
        elif len(revision) == 2:
1542
 
            if revision[1].get_branch() != revision[0].get_branch():
1543
 
                # b is taken from revision[0].get_branch(), and
1544
 
                # show_log will use its revision_history. Having
1545
 
                # different branches will lead to weird behaviors.
 
1558
        b.lock_read()
 
1559
        try:
 
1560
            if revision is None:
 
1561
                rev1 = None
 
1562
                rev2 = None
 
1563
            elif len(revision) == 1:
 
1564
                rev1 = rev2 = revision[0].in_history(b).revno
 
1565
            elif len(revision) == 2:
 
1566
                if revision[1].get_branch() != revision[0].get_branch():
 
1567
                    # b is taken from revision[0].get_branch(), and
 
1568
                    # show_log will use its revision_history. Having
 
1569
                    # different branches will lead to weird behaviors.
 
1570
                    raise errors.BzrCommandError(
 
1571
                        "Log doesn't accept two revisions in different"
 
1572
                        " branches.")
 
1573
                if revision[0].spec is None:
 
1574
                    # missing begin-range means first revision
 
1575
                    rev1 = 1
 
1576
                else:
 
1577
                    rev1 = revision[0].in_history(b).revno
 
1578
 
 
1579
                if revision[1].spec is None:
 
1580
                    # missing end-range means last known revision
 
1581
                    rev2 = b.revno()
 
1582
                else:
 
1583
                    rev2 = revision[1].in_history(b).revno
 
1584
            else:
1546
1585
                raise errors.BzrCommandError(
1547
 
                    "Log doesn't accept two revisions in different branches.")
1548
 
            if revision[0].spec is None:
1549
 
                # missing begin-range means first revision
1550
 
                rev1 = 1
1551
 
            else:
1552
 
                rev1 = revision[0].in_history(b).revno
1553
 
 
1554
 
            if revision[1].spec is None:
1555
 
                # missing end-range means last known revision
1556
 
                rev2 = b.revno()
1557
 
            else:
1558
 
                rev2 = revision[1].in_history(b).revno
1559
 
        else:
1560
 
            raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1561
 
 
1562
 
        # By this point, the revision numbers are converted to the +ve
1563
 
        # form if they were supplied in the -ve form, so we can do
1564
 
        # this comparison in relative safety
1565
 
        if rev1 > rev2:
1566
 
            (rev2, rev1) = (rev1, rev2)
1567
 
 
1568
 
        if log_format is None:
1569
 
            log_format = log.log_formatter_registry.get_default(b)
1570
 
 
1571
 
        lf = log_format(show_ids=show_ids, to_file=self.outf,
1572
 
                        show_timezone=timezone)
1573
 
 
1574
 
        show_log(b,
1575
 
                 lf,
1576
 
                 file_id,
1577
 
                 verbose=verbose,
1578
 
                 direction=direction,
1579
 
                 start_revision=rev1,
1580
 
                 end_revision=rev2,
1581
 
                 search=message)
 
1586
                    'bzr log --revision takes one or two values.')
 
1587
 
 
1588
            # By this point, the revision numbers are converted to the +ve
 
1589
            # form if they were supplied in the -ve form, so we can do
 
1590
            # this comparison in relative safety
 
1591
            if rev1 > rev2:
 
1592
                (rev2, rev1) = (rev1, rev2)
 
1593
 
 
1594
            if log_format is None:
 
1595
                log_format = log.log_formatter_registry.get_default(b)
 
1596
 
 
1597
            lf = log_format(show_ids=show_ids, to_file=self.outf,
 
1598
                            show_timezone=timezone)
 
1599
 
 
1600
            show_log(b,
 
1601
                     lf,
 
1602
                     file_id,
 
1603
                     verbose=verbose,
 
1604
                     direction=direction,
 
1605
                     start_revision=rev1,
 
1606
                     end_revision=rev2,
 
1607
                     search=message)
 
1608
        finally:
 
1609
            b.unlock()
1582
1610
 
1583
1611
 
1584
1612
def get_log_format(long=False, short=False, line=False, default='long'):
2357
2385
    default, use --remember. The value will only be saved if the remote
2358
2386
    location can be accessed.
2359
2387
 
 
2388
    The results of the merge are placed into the destination working
 
2389
    directory, where they can be reviewed (with bzr diff), tested, and then
 
2390
    committed to record the result of the merge.
 
2391
 
2360
2392
    Examples:
2361
2393
 
2362
2394
    To merge the latest revision from bzr.dev
2375
2407
    """
2376
2408
    takes_args = ['branch?']
2377
2409
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
2378
 
                     Option('show-base', help="Show base revision text in "
2379
 
                            "conflicts"),
2380
 
                     Option('uncommitted', help='Apply uncommitted changes'
2381
 
                            ' from a working copy, instead of branch changes'),
2382
 
                     Option('pull', help='If the destination is already'
2383
 
                             ' completely merged into the source, pull from the'
2384
 
                             ' source rather than merging. When this happens,'
2385
 
                             ' you do not need to commit the result.'),
2386
 
                     ]
 
2410
        Option('show-base', help="Show base revision text in "
 
2411
               "conflicts"),
 
2412
        Option('uncommitted', help='Apply uncommitted changes'
 
2413
               ' from a working copy, instead of branch changes'),
 
2414
        Option('pull', help='If the destination is already'
 
2415
                ' completely merged into the source, pull from the'
 
2416
                ' source rather than merging. When this happens,'
 
2417
                ' you do not need to commit the result.'),
 
2418
        Option('directory',
 
2419
            help='branch to merge into, '
 
2420
                 'rather than the one containing the working directory',
 
2421
            short_name='d',
 
2422
            type=unicode,
 
2423
            ),
 
2424
    ]
2387
2425
 
2388
2426
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2389
 
            show_base=False, reprocess=False, remember=False, 
2390
 
            uncommitted=False, pull=False):
 
2427
            show_base=False, reprocess=False, remember=False,
 
2428
            uncommitted=False, pull=False,
 
2429
            directory=None,
 
2430
            ):
2391
2431
        if merge_type is None:
2392
2432
            merge_type = _mod_merge.Merge3Merger
2393
2433
 
2394
 
        tree = WorkingTree.open_containing(u'.')[0]
 
2434
        if directory is None: directory = u'.'
 
2435
        tree = WorkingTree.open_containing(directory)[0]
 
2436
        change_reporter = delta.ChangeReporter(tree.inventory)
2395
2437
 
2396
2438
        if branch is not None:
2397
2439
            try:
2400
2442
                pass # Continue on considering this url a Branch
2401
2443
            else:
2402
2444
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2403
 
                                            reprocess, show_base)
 
2445
                                         reprocess, show_base, change_reporter)
2404
2446
                if conflicts == 0:
2405
2447
                    return 0
2406
2448
                else:
2459
2501
                    reprocess=reprocess,
2460
2502
                    show_base=show_base,
2461
2503
                    pull=pull,
2462
 
                    pb=pb, file_list=interesting_files)
 
2504
                    this_dir=directory,
 
2505
                    pb=pb, file_list=interesting_files,
 
2506
                    change_reporter=change_reporter)
2463
2507
            finally:
2464
2508
                pb.finished()
2465
2509
            if conflict_count != 0:
2913
2957
    See "help checkouts" for more information on checkouts.
2914
2958
    """
2915
2959
 
2916
 
    takes_args = ['location']
 
2960
    takes_args = ['location?']
2917
2961
    takes_options = []
2918
2962
 
2919
2963
    def run(self, location=None):
2920
2964
        b, relpath = Branch.open_containing(u'.')
 
2965
        if location is None:
 
2966
            try:
 
2967
                location = b.get_old_bound_location()
 
2968
            except errors.UpgradeRequired:
 
2969
                raise errors.BzrCommandError('No location supplied.  '
 
2970
                    'This format does not remember old locations.')
 
2971
            else:
 
2972
                if location is None:
 
2973
                    raise errors.BzrCommandError('No location supplied and no '
 
2974
                        'previous location known')
2921
2975
        b_other = Branch.open(location)
2922
2976
        try:
2923
2977
            b.bind(b_other)
3117
3171
                  merge_type=None,
3118
3172
                  file_list=None, show_base=False, reprocess=False,
3119
3173
                  pull=False,
3120
 
                  pb=DummyProgress()):
 
3174
                  pb=DummyProgress(),
 
3175
                  change_reporter=None):
3121
3176
    """Merge changes into a tree.
3122
3177
 
3123
3178
    base_revision
3161
3216
        raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3162
3217
    try:
3163
3218
        merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3164
 
                                   pb=pb)
 
3219
                                   pb=pb, change_reporter=change_reporter)
3165
3220
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3166
3221
        merger.pp.next_phase()
3167
3222
        merger.check_basis(check_clean)