~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2009-06-19 09:06:56 UTC
  • mfrom: (4463 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4464.
  • Revision ID: mbp@sourcefrog.net-20090619090656-d5weqeecyscv8kqp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
946
946
            if branch_to.get_parent() is None or remember:
947
947
                branch_to.set_parent(branch_from.base)
948
948
 
949
 
        if revision is not None:
950
 
            revision_id = revision.as_revision_id(branch_from)
951
 
 
952
 
        branch_to.lock_write()
 
949
        if branch_from is not branch_to:
 
950
            branch_from.lock_read()
953
951
        try:
954
 
            if tree_to is not None:
955
 
                view_info = _get_view_info_for_change_reporter(tree_to)
956
 
                change_reporter = delta._ChangeReporter(
957
 
                    unversioned_filter=tree_to.is_ignored, view_info=view_info)
958
 
                result = tree_to.pull(branch_from, overwrite, revision_id,
959
 
                                      change_reporter,
960
 
                                      possible_transports=possible_transports,
961
 
                                      local=local)
962
 
            else:
963
 
                result = branch_to.pull(branch_from, overwrite, revision_id,
964
 
                                      local=local)
965
 
 
966
 
            result.report(self.outf)
967
 
            if verbose and result.old_revid != result.new_revid:
968
 
                log.show_branch_change(branch_to, self.outf, result.old_revno,
969
 
                                       result.old_revid)
 
952
            if revision is not None:
 
953
                revision_id = revision.as_revision_id(branch_from)
 
954
 
 
955
            branch_to.lock_write()
 
956
            try:
 
957
                if tree_to is not None:
 
958
                    view_info = _get_view_info_for_change_reporter(tree_to)
 
959
                    change_reporter = delta._ChangeReporter(
 
960
                        unversioned_filter=tree_to.is_ignored,
 
961
                        view_info=view_info)
 
962
                    result = tree_to.pull(
 
963
                        branch_from, overwrite, revision_id, change_reporter,
 
964
                        possible_transports=possible_transports, local=local)
 
965
                else:
 
966
                    result = branch_to.pull(
 
967
                        branch_from, overwrite, revision_id, local=local)
 
968
 
 
969
                result.report(self.outf)
 
970
                if verbose and result.old_revid != result.new_revid:
 
971
                    log.show_branch_change(
 
972
                        branch_to, self.outf, result.old_revno,
 
973
                        result.old_revid)
 
974
            finally:
 
975
                branch_to.unlock()
970
976
        finally:
971
 
            branch_to.unlock()
 
977
            if branch_from is not branch_to:
 
978
                branch_from.unlock()
972
979
 
973
980
 
974
981
class cmd_push(Command):
1021
1028
                'for the commit history. Only the work not present in the '
1022
1029
                'referenced branch is included in the branch created.',
1023
1030
            type=unicode),
 
1031
        Option('strict',
 
1032
               help='Refuse to push if there are uncommitted changes in'
 
1033
               ' the working tree.'),
1024
1034
        ]
1025
1035
    takes_args = ['location?']
1026
1036
    encoding_type = 'replace'
1028
1038
    def run(self, location=None, remember=False, overwrite=False,
1029
1039
        create_prefix=False, verbose=False, revision=None,
1030
1040
        use_existing_dir=False, directory=None, stacked_on=None,
1031
 
        stacked=False):
 
1041
        stacked=False, strict=None):
1032
1042
        from bzrlib.push import _show_push_branch
1033
1043
 
1034
 
        # Get the source branch and revision_id
1035
1044
        if directory is None:
1036
1045
            directory = '.'
1037
 
        br_from = Branch.open_containing(directory)[0]
 
1046
        # Get the source branch
 
1047
        tree, br_from = bzrdir.BzrDir.open_tree_or_branch(directory)
 
1048
        if strict is None:
 
1049
            strict = br_from.get_config().get_user_option('push_strict')
 
1050
            if strict is not None:
 
1051
                # FIXME: This should be better supported by config
 
1052
                # -- vila 20090611
 
1053
                bools = dict(yes=True, no=False, on=True, off=False,
 
1054
                             true=True, false=False)
 
1055
                try:
 
1056
                    strict = bools[strict.lower()]
 
1057
                except KeyError:
 
1058
                    strict = None
 
1059
        if strict:
 
1060
            changes = tree.changes_from(tree.basis_tree())
 
1061
            if changes.has_changed():
 
1062
                raise errors.UncommittedChanges(tree)
 
1063
        # Get the tip's revision_id
1038
1064
        revision = _get_one_revision('push', revision)
1039
1065
        if revision is not None:
1040
1066
            revision_id = revision.in_history(br_from).rev_id
1078
1104
 
1079
1105
 
1080
1106
class cmd_branch(Command):
1081
 
    """Create a new copy of a branch.
 
1107
    """Create a new branch that is a copy of an existing branch.
1082
1108
 
1083
1109
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
1084
1110
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
1112
1138
 
1113
1139
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1114
1140
            from_location)
 
1141
        if (accelerator_tree is not None and
 
1142
            accelerator_tree.supports_content_filtering()):
 
1143
            accelerator_tree = None
1115
1144
        revision = _get_one_revision('branch', revision)
1116
1145
        br_from.lock_read()
1117
1146
        try:
1621
1650
                branch.set_append_revisions_only(True)
1622
1651
            except errors.UpgradeRequired:
1623
1652
                raise errors.BzrCommandError('This branch format cannot be set'
1624
 
                    ' to append-revisions-only.  Try --experimental-branch6')
 
1653
                    ' to append-revisions-only.  Try --default.')
1625
1654
        if not is_quiet():
1626
1655
            from bzrlib.info import describe_layout, describe_format
1627
1656
            try:
2366
2395
 
2367
2396
        if path is None:
2368
2397
            fs_path = '.'
2369
 
            prefix = ''
2370
2398
        else:
2371
2399
            if from_root:
2372
2400
                raise errors.BzrCommandError('cannot specify both --from-root'
2373
2401
                                             ' and PATH')
2374
2402
            fs_path = path
2375
 
            prefix = path
2376
2403
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
2377
2404
            fs_path)
 
2405
 
 
2406
        # Calculate the prefix to use
 
2407
        prefix = None
2378
2408
        if from_root:
2379
 
            relpath = u''
2380
 
        elif relpath:
2381
 
            relpath += '/'
 
2409
            if relpath:
 
2410
                prefix = relpath + '/'
 
2411
        elif fs_path != '.':
 
2412
            prefix = fs_path + '/'
 
2413
 
2382
2414
        if revision is not None or tree is None:
2383
2415
            tree = _get_one_revision_tree('ls', revision, branch=branch)
2384
2416
 
2392
2424
 
2393
2425
        tree.lock_read()
2394
2426
        try:
2395
 
            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
2396
 
                if fp.startswith(relpath):
2397
 
                    rp = fp[len(relpath):]
2398
 
                    fp = osutils.pathjoin(prefix, rp)
2399
 
                    if not recursive and '/' in rp:
2400
 
                        continue
2401
 
                    if not all and not selection[fc]:
2402
 
                        continue
2403
 
                    if kind is not None and fkind != kind:
2404
 
                        continue
2405
 
                    if apply_view:
2406
 
                        try:
2407
 
                            views.check_path_in_view(tree, fp)
2408
 
                        except errors.FileOutsideView:
2409
 
                            continue
2410
 
                    kindch = entry.kind_character()
2411
 
                    outstring = fp + kindch
2412
 
                    ui.ui_factory.clear_term()
2413
 
                    if verbose:
2414
 
                        outstring = '%-8s %s' % (fc, outstring)
2415
 
                        if show_ids and fid is not None:
2416
 
                            outstring = "%-50s %s" % (outstring, fid)
2417
 
                        self.outf.write(outstring + '\n')
2418
 
                    elif null:
2419
 
                        self.outf.write(fp + '\0')
2420
 
                        if show_ids:
2421
 
                            if fid is not None:
2422
 
                                self.outf.write(fid)
2423
 
                            self.outf.write('\0')
2424
 
                        self.outf.flush()
2425
 
                    else:
 
2427
            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False,
 
2428
                from_dir=relpath, recursive=recursive):
 
2429
                # Apply additional masking
 
2430
                if not all and not selection[fc]:
 
2431
                    continue
 
2432
                if kind is not None and fkind != kind:
 
2433
                    continue
 
2434
                if apply_view:
 
2435
                    try:
 
2436
                        if relpath:
 
2437
                            fullpath = osutils.pathjoin(relpath, fp)
 
2438
                        else:
 
2439
                            fullpath = fp
 
2440
                        views.check_path_in_view(tree, fullpath)
 
2441
                    except errors.FileOutsideView:
 
2442
                        continue
 
2443
 
 
2444
                # Output the entry
 
2445
                if prefix:
 
2446
                    fp = osutils.pathjoin(prefix, fp)
 
2447
                kindch = entry.kind_character()
 
2448
                outstring = fp + kindch
 
2449
                ui.ui_factory.clear_term()
 
2450
                if verbose:
 
2451
                    outstring = '%-8s %s' % (fc, outstring)
 
2452
                    if show_ids and fid is not None:
 
2453
                        outstring = "%-50s %s" % (outstring, fid)
 
2454
                    self.outf.write(outstring + '\n')
 
2455
                elif null:
 
2456
                    self.outf.write(fp + '\0')
 
2457
                    if show_ids:
 
2458
                        if fid is not None:
 
2459
                            self.outf.write(fid)
 
2460
                        self.outf.write('\0')
 
2461
                    self.outf.flush()
 
2462
                else:
 
2463
                    if show_ids:
2426
2464
                        if fid is not None:
2427
2465
                            my_id = fid
2428
2466
                        else:
2429
2467
                            my_id = ''
2430
 
                        if show_ids:
2431
 
                            self.outf.write('%-50s %s\n' % (outstring, my_id))
2432
 
                        else:
2433
 
                            self.outf.write(outstring + '\n')
 
2468
                        self.outf.write('%-50s %s\n' % (outstring, my_id))
 
2469
                    else:
 
2470
                        self.outf.write(outstring + '\n')
2434
2471
        finally:
2435
2472
            tree.unlock()
2436
2473
 
4674
4711
        try:
4675
4712
            containing_tree.extract(sub_id)
4676
4713
        except errors.RootNotRich:
4677
 
            raise errors.UpgradeRequired(containing_tree.branch.base)
 
4714
            raise errors.RichRootUpgradeRequired(containing_tree.branch.base)
4678
4715
 
4679
4716
 
4680
4717
class cmd_merge_directive(Command):