~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2007-02-21 05:34:56 UTC
  • mfrom: (2296 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2309.
  • Revision ID: mbp@sourcefrog.net-20070221053456-vyr6o0ehqnbetrvb
merge trunk, in particular new Branch6 changes

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='.'):
599
597
 
600
598
        old_rh = branch_to.revision_history()
601
599
        if tree_to is not None:
602
 
            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))
603
602
        else:
604
603
            count = branch_to.pull(branch_from, overwrite, rev_id)
605
604
        _copy_tags_maybe(branch_from, branch_to)
650
649
            short_name='d',
651
650
            type=unicode,
652
651
            ),
653
 
            Option('use-existing-dir',
654
 
                   help='By default push will fail if the target'
655
 
                        ' directory exists, but does not already'
656
 
                        ' have a control directory. This flag will'
657
 
                        ' allow push to proceed.'),
658
 
            ]
 
652
        Option('use-existing-dir',
 
653
               help='By default push will fail if the target'
 
654
                    ' directory exists, but does not already'
 
655
                    ' have a control directory. This flag will'
 
656
                    ' allow push to proceed.'),
 
657
        ]
659
658
    takes_args = ['location?']
660
659
    encoding_type = 'replace'
661
660
 
662
661
    def run(self, location=None, remember=False, overwrite=False,
663
662
            create_prefix=False, verbose=False,
664
 
            directory=None,
665
663
            use_existing_dir=False,
666
 
            ):
 
664
            directory=None):
667
665
        # FIXME: Way too big!  Put this into a function called from the
668
666
        # command.
669
667
        if directory is None:
1225
1223
                value_switches=True,
1226
1224
                title="Branch Format",
1227
1225
                ),
 
1226
         Option('append-revisions-only',
 
1227
                help='Never change revnos or the existing log.'
 
1228
                '  Append revisions to it only.')
1228
1229
         ]
1229
 
    def run(self, location=None, format=None):
 
1230
    def run(self, location=None, format=None, append_revisions_only=False):
1230
1231
        if format is None:
1231
1232
            format = bzrdir.format_registry.make_bzrdir('default')
1232
1233
        if location is None:
1249
1250
            existing_bzrdir = bzrdir.BzrDir.open(location)
1250
1251
        except errors.NotBranchError:
1251
1252
            # really a NotBzrDir error...
1252
 
            bzrdir.BzrDir.create_branch_convenience(location, format=format)
 
1253
            branch = bzrdir.BzrDir.create_branch_convenience(location,
 
1254
                                                             format=format)
1253
1255
        else:
1254
1256
            from bzrlib.transport.local import LocalTransport
1255
1257
            if existing_bzrdir.has_branch():
1258
1260
                        raise errors.BranchExistsWithoutWorkingTree(location)
1259
1261
                raise errors.AlreadyBranchError(location)
1260
1262
            else:
1261
 
                existing_bzrdir.create_branch()
 
1263
                branch = existing_bzrdir.create_branch()
1262
1264
                existing_bzrdir.create_workingtree()
 
1265
        if append_revisions_only:
 
1266
            try:
 
1267
                branch.set_append_revisions_only(True)
 
1268
            except errors.UpgradeRequired:
 
1269
                raise errors.BzrCommandError('This branch format cannot be set'
 
1270
                    ' to append-revisions-only.  Try --experimental-branch6')
1263
1271
 
1264
1272
 
1265
1273
class cmd_init_repository(Command):
1564
1572
            dir, relpath = bzrdir.BzrDir.open_containing(location)
1565
1573
            b = dir.open_branch()
1566
1574
 
1567
 
        if revision is None:
1568
 
            rev1 = None
1569
 
            rev2 = None
1570
 
        elif len(revision) == 1:
1571
 
            rev1 = rev2 = revision[0].in_history(b).revno
1572
 
        elif len(revision) == 2:
1573
 
            if revision[1].get_branch() != revision[0].get_branch():
1574
 
                # b is taken from revision[0].get_branch(), and
1575
 
                # show_log will use its revision_history. Having
1576
 
                # different branches will lead to weird behaviors.
 
1575
        b.lock_read()
 
1576
        try:
 
1577
            if revision is None:
 
1578
                rev1 = None
 
1579
                rev2 = None
 
1580
            elif len(revision) == 1:
 
1581
                rev1 = rev2 = revision[0].in_history(b).revno
 
1582
            elif len(revision) == 2:
 
1583
                if revision[1].get_branch() != revision[0].get_branch():
 
1584
                    # b is taken from revision[0].get_branch(), and
 
1585
                    # show_log will use its revision_history. Having
 
1586
                    # different branches will lead to weird behaviors.
 
1587
                    raise errors.BzrCommandError(
 
1588
                        "Log doesn't accept two revisions in different"
 
1589
                        " branches.")
 
1590
                if revision[0].spec is None:
 
1591
                    # missing begin-range means first revision
 
1592
                    rev1 = 1
 
1593
                else:
 
1594
                    rev1 = revision[0].in_history(b).revno
 
1595
 
 
1596
                if revision[1].spec is None:
 
1597
                    # missing end-range means last known revision
 
1598
                    rev2 = b.revno()
 
1599
                else:
 
1600
                    rev2 = revision[1].in_history(b).revno
 
1601
            else:
1577
1602
                raise errors.BzrCommandError(
1578
 
                    "Log doesn't accept two revisions in different branches.")
1579
 
            if revision[0].spec is None:
1580
 
                # missing begin-range means first revision
1581
 
                rev1 = 1
1582
 
            else:
1583
 
                rev1 = revision[0].in_history(b).revno
1584
 
 
1585
 
            if revision[1].spec is None:
1586
 
                # missing end-range means last known revision
1587
 
                rev2 = b.revno()
1588
 
            else:
1589
 
                rev2 = revision[1].in_history(b).revno
1590
 
        else:
1591
 
            raise errors.BzrCommandError('bzr log --revision takes one or two values.')
1592
 
 
1593
 
        # By this point, the revision numbers are converted to the +ve
1594
 
        # form if they were supplied in the -ve form, so we can do
1595
 
        # this comparison in relative safety
1596
 
        if rev1 > rev2:
1597
 
            (rev2, rev1) = (rev1, rev2)
1598
 
 
1599
 
        if log_format is None:
1600
 
            log_format = log.log_formatter_registry.get_default(b)
1601
 
 
1602
 
        lf = log_format(show_ids=show_ids, to_file=self.outf,
1603
 
                        show_timezone=timezone)
1604
 
 
1605
 
        show_log(b,
1606
 
                 lf,
1607
 
                 file_id,
1608
 
                 verbose=verbose,
1609
 
                 direction=direction,
1610
 
                 start_revision=rev1,
1611
 
                 end_revision=rev2,
1612
 
                 search=message)
 
1603
                    'bzr log --revision takes one or two values.')
 
1604
 
 
1605
            # By this point, the revision numbers are converted to the +ve
 
1606
            # form if they were supplied in the -ve form, so we can do
 
1607
            # this comparison in relative safety
 
1608
            if rev1 > rev2:
 
1609
                (rev2, rev1) = (rev1, rev2)
 
1610
 
 
1611
            if log_format is None:
 
1612
                log_format = log.log_formatter_registry.get_default(b)
 
1613
 
 
1614
            lf = log_format(show_ids=show_ids, to_file=self.outf,
 
1615
                            show_timezone=timezone)
 
1616
 
 
1617
            show_log(b,
 
1618
                     lf,
 
1619
                     file_id,
 
1620
                     verbose=verbose,
 
1621
                     direction=direction,
 
1622
                     start_revision=rev1,
 
1623
                     end_revision=rev2,
 
1624
                     search=message)
 
1625
        finally:
 
1626
            b.unlock()
1613
1627
 
1614
1628
 
1615
1629
def get_log_format(long=False, short=False, line=False, default='long'):
2419
2433
                ' source rather than merging. When this happens,'
2420
2434
                ' you do not need to commit the result.'),
2421
2435
        Option('directory',
2422
 
            help='branch to push from, '
 
2436
            help='Branch to merge into, '
2423
2437
                 'rather than the one containing the working directory',
2424
2438
            short_name='d',
2425
2439
            type=unicode,
2427
2441
    ]
2428
2442
 
2429
2443
    def run(self, branch=None, revision=None, force=False, merge_type=None,
2430
 
            show_base=False, reprocess=False, remember=False, 
 
2444
            show_base=False, reprocess=False, remember=False,
2431
2445
            uncommitted=False, pull=False,
2432
2446
            directory=None,
2433
2447
            ):
2434
2448
        if merge_type is None:
2435
2449
            merge_type = _mod_merge.Merge3Merger
 
2450
 
2436
2451
        if directory is None: directory = u'.'
2437
2452
        tree = WorkingTree.open_containing(directory)[0]
 
2453
        change_reporter = delta.ChangeReporter(tree.inventory)
2438
2454
 
2439
2455
        if branch is not None:
2440
2456
            try:
2443
2459
                pass # Continue on considering this url a Branch
2444
2460
            else:
2445
2461
                conflicts = merge_bundle(reader, tree, not force, merge_type,
2446
 
                                            reprocess, show_base)
 
2462
                                         reprocess, show_base, change_reporter)
2447
2463
                if conflicts == 0:
2448
2464
                    return 0
2449
2465
                else:
2507
2523
                    show_base=show_base,
2508
2524
                    pull=pull,
2509
2525
                    this_dir=directory,
2510
 
                    pb=pb, file_list=interesting_files)
 
2526
                    pb=pb, file_list=interesting_files,
 
2527
                    change_reporter=change_reporter)
2511
2528
            finally:
2512
2529
                pb.finished()
2513
2530
            if conflict_count != 0:
2961
2978
    See "help checkouts" for more information on checkouts.
2962
2979
    """
2963
2980
 
2964
 
    takes_args = ['location']
 
2981
    takes_args = ['location?']
2965
2982
    takes_options = []
2966
2983
 
2967
2984
    def run(self, location=None):
2968
2985
        b, relpath = Branch.open_containing(u'.')
 
2986
        if location is None:
 
2987
            try:
 
2988
                location = b.get_old_bound_location()
 
2989
            except errors.UpgradeRequired:
 
2990
                raise errors.BzrCommandError('No location supplied.  '
 
2991
                    'This format does not remember old locations.')
 
2992
            else:
 
2993
                if location is None:
 
2994
                    raise errors.BzrCommandError('No location supplied and no '
 
2995
                        'previous location known')
2969
2996
        b_other = Branch.open(location)
2970
2997
        try:
2971
2998
            b.bind(b_other)
3233
3260
                  merge_type=None,
3234
3261
                  file_list=None, show_base=False, reprocess=False,
3235
3262
                  pull=False,
3236
 
                  pb=DummyProgress()):
 
3263
                  pb=DummyProgress(),
 
3264
                  change_reporter=None):
3237
3265
    """Merge changes into a tree.
3238
3266
 
3239
3267
    base_revision
3277
3305
        raise errors.BzrCommandError("Cannot do conflict reduction and show base.")
3278
3306
    try:
3279
3307
        merger = _mod_merge.Merger(this_tree.branch, this_tree=this_tree,
3280
 
                                   pb=pb)
 
3308
                                   pb=pb, change_reporter=change_reporter)
3281
3309
        merger.pp = ProgressPhase("Merge phase", 5, pb)
3282
3310
        merger.pp.next_phase()
3283
3311
        merger.check_basis(check_clean)