~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Aaron Bentley
  • Date: 2007-02-07 03:09:58 UTC
  • mfrom: (2268 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2269.
  • Revision ID: aaron.bentley@utoronto.ca-20070207030958-fx6ykp7rg7zma6xu
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    branch,
31
31
    bundle,
32
32
    bzrdir,
 
33
    delta,
33
34
    config,
34
35
    errors,
35
36
    ignores,
37
38
    merge as _mod_merge,
38
39
    osutils,
39
40
    repository,
 
41
    symbol_versioning,
40
42
    transport,
41
43
    tree as _mod_tree,
42
44
    ui,
93
95
    return tree, new_list
94
96
 
95
97
 
 
98
@symbol_versioning.deprecated_function(symbol_versioning.zero_fifteen)
96
99
def get_format_type(typestring):
97
100
    """Parse and return a format specifier."""
98
101
    # Have to use BzrDirMetaFormat1 directly, so that
118
121
    This reports on versioned and unknown files, reporting them
119
122
    grouped by state.  Possible states are:
120
123
 
121
 
    added / A
 
124
    added
122
125
        Versioned in the working copy but not in the previous revision.
123
126
 
124
 
    removed / D
 
127
    removed
125
128
        Versioned in the previous revision but removed or deleted
126
129
        in the working copy.
127
130
 
128
 
    renamed / R
 
131
    renamed
129
132
        Path of this file changed from the previous revision;
130
133
        the text may also have changed.  This includes files whose
131
134
        parent directory was renamed.
132
135
 
133
 
    modified / M
 
136
    modified
134
137
        Text has changed since the previous revision.
135
138
 
136
 
    unknown / ?
 
139
    kind changed
 
140
        File kind has been changed (e.g. from file to directory).
 
141
 
 
142
    unknown
137
143
        Not versioned and not matching an ignore pattern.
138
144
 
139
145
    To see ignored files use 'bzr ignored'.  For details in the
140
146
    changes to file texts, use 'bzr diff'.
141
147
    
142
 
    --short gives a one character status flag for each item, similar
143
 
    to the SVN's status command.
 
148
    --short gives a status flags for each item, similar to the SVN's status
 
149
    command.
 
150
 
 
151
    Column 1: versioning / renames
 
152
      + File versioned
 
153
      - File unversioned
 
154
      R File renamed
 
155
      ? File unknown
 
156
      C File has conflicts
 
157
      P Entry for a pending merge (not a file)
 
158
 
 
159
    Column 2: Contents
 
160
      N File created
 
161
      D File deleted
 
162
      K File kind changed
 
163
      M File modified
 
164
 
 
165
    Column 3: Execute
 
166
      * The execute bit was changed
144
167
 
145
168
    If no arguments are specified, the status of the entire working
146
169
    directory is shown.  Otherwise, only the status of the specified
450
473
 
451
474
    If the last argument is a versioned directory, all the other names
452
475
    are moved into it.  Otherwise, there must be exactly two arguments
453
 
    and the file is changed to a new name, which must not already exist.
 
476
    and the file is changed to a new name.
 
477
 
 
478
    If OLDNAME does not exist on the filesystem but is versioned and
 
479
    NEWNAME does exist on the filesystem but is not versioned, mv
 
480
    assumes that the file has been manually moved and only updates
 
481
    its internal inventory to reflect that change.
 
482
    The same is valid when moving many SOURCE files to a DESTINATION.
454
483
 
455
484
    Files cannot be moved between branches.
456
485
    """
457
486
 
458
487
    takes_args = ['names*']
 
488
    takes_options = [Option("after", help="move only the bzr identifier"
 
489
        " of the file (file has already been moved). Use this flag if"
 
490
        " bzr is not able to detect this itself.")]
459
491
    aliases = ['move', 'rename']
460
492
    encoding_type = 'replace'
461
493
 
462
 
    def run(self, names_list):
 
494
    def run(self, names_list, after=False):
463
495
        if names_list is None:
464
496
            names_list = []
465
497
 
469
501
        
470
502
        if os.path.isdir(names_list[-1]):
471
503
            # move into existing directory
472
 
            for pair in tree.move(rel_names[:-1], rel_names[-1]):
 
504
            for pair in tree.move(rel_names[:-1], rel_names[-1], after=after):
473
505
                self.outf.write("%s => %s\n" % pair)
474
506
        else:
475
507
            if len(names_list) != 2:
476
 
                raise errors.BzrCommandError('to mv multiple files the destination '
477
 
                                             'must be a versioned directory')
478
 
            tree.rename_one(rel_names[0], rel_names[1])
 
508
                raise errors.BzrCommandError('to mv multiple files the'
 
509
                                             ' destination must be a versioned'
 
510
                                             ' directory')
 
511
            tree.rename_one(rel_names[0], rel_names[1], after=after)
479
512
            self.outf.write("%s => %s\n" % (rel_names[0], rel_names[1]))
480
513
            
481
514
    
650
683
            dir_to = br_from.bzrdir.clone(location_url,
651
684
                revision_id=br_from.last_revision())
652
685
            br_to = dir_to.open_branch()
653
 
            count = len(br_to.revision_history())
 
686
            count = br_to.last_revision_info()[0]
654
687
            # We successfully created the target, remember it
655
688
            if br_from.get_push_location() is None or remember:
656
689
                br_from.set_push_location(br_to.base)
666
699
                except errors.NotLocalUrl:
667
700
                    warning('This transport does not update the working '
668
701
                            'tree of: %s' % (br_to.base,))
669
 
                    count = br_to.pull(br_from, overwrite)
 
702
                    count = br_from.push(br_to, overwrite)
670
703
                except errors.NoWorkingTree:
671
 
                    count = br_to.pull(br_from, overwrite)
 
704
                    count = br_from.push(br_to, overwrite)
672
705
                else:
673
 
                    count = tree_to.pull(br_from, overwrite)
 
706
                    tree_to.lock_write()
 
707
                    try:
 
708
                        count = br_from.push(tree_to.branch, overwrite)
 
709
                        tree_to.update()
 
710
                    finally:
 
711
                        tree_to.unlock()
674
712
            except errors.DivergedBranches:
675
713
                raise errors.BzrCommandError('These branches have diverged.'
676
714
                                        '  Try using "merge" and then "push".')
1084
1122
                                 ' formats are: default, knit, metaweave and'
1085
1123
                                 ' weave. Default is knit; metaweave and'
1086
1124
                                 ' weave are deprecated',
 
1125
                            converter=bzrdir.format_registry.make_bzrdir,
1087
1126
                            registry=bzrdir.format_registry,
1088
 
                            converter=get_format_type,
1089
1127
                            value_switches=True),
1090
1128
                     ]
1091
1129
    def run(self, location=None, format=None):
1092
1130
        if format is None:
1093
 
            format = get_format_type('default')
 
1131
            format = bzrdir.format_registry.make_bzrdir('default')
1094
1132
        if location is None:
1095
1133
            location = u'.'
1096
1134
 
1145
1183
                                 ' metaweave and weave. Default is knit;'
1146
1184
                                 ' metaweave and weave are deprecated',
1147
1185
                            registry=bzrdir.format_registry,
1148
 
                            converter=get_format_type,
 
1186
                            converter=bzrdir.format_registry.make_bzrdir,
1149
1187
                            value_switches=True),
1150
1188
                     Option('trees',
1151
1189
                             help='Allows branches in repository to have'
1153
1191
    aliases = ["init-repo"]
1154
1192
    def run(self, location, format=None, trees=False):
1155
1193
        if format is None:
1156
 
            format = get_format_type('default')
 
1194
            format = bzrdir.format_registry.make_bzrdir('default')
1157
1195
 
1158
1196
        if location is None:
1159
1197
            location = '.'
1541
1579
                                             ' and PATH')
1542
1580
            fs_path = path
1543
1581
            prefix = path
1544
 
        tree, relpath = WorkingTree.open_containing(fs_path)
 
1582
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
 
1583
            fs_path)
1545
1584
        if from_root:
1546
1585
            relpath = u''
1547
1586
        elif relpath:
1548
1587
            relpath += '/'
1549
1588
        if revision is not None:
1550
 
            tree = tree.branch.repository.revision_tree(
1551
 
                revision[0].in_history(tree.branch).rev_id)
 
1589
            tree = branch.repository.revision_tree(
 
1590
                revision[0].in_history(branch).rev_id)
 
1591
        elif tree is None:
 
1592
            tree = branch.basis_tree()
1552
1593
 
1553
1594
        for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
1554
1595
            if fp.startswith(relpath):
1966
2007
                             ' Default is knit; metaweave and weave are'
1967
2008
                             ' deprecated',
1968
2009
                        registry=bzrdir.format_registry,
1969
 
                        converter=get_format_type,
 
2010
                        converter=bzrdir.format_registry.make_bzrdir,
1970
2011
                        value_switches=True),
1971
2012
                    ]
1972
2013
 
1974
2015
    def run(self, url='.', format=None):
1975
2016
        from bzrlib.upgrade import upgrade
1976
2017
        if format is None:
1977
 
            format = get_format_type('default')
 
2018
            format = bzrdir.format_registry.make_bzrdir('default')
1978
2019
        upgrade(url, format)
1979
2020
 
1980
2021
 
2202
2243
        branch1 = Branch.open_containing(branch)[0]
2203
2244
        branch2 = Branch.open_containing(other)[0]
2204
2245
 
2205
 
        history_1 = branch1.revision_history()
2206
 
        history_2 = branch2.revision_history()
2207
 
 
2208
2246
        last1 = branch1.last_revision()
2209
2247
        last2 = branch2.last_revision()
2210
2248
 
2517
2555
        try:
2518
2556
            tree.revert(file_list, 
2519
2557
                        tree.branch.repository.revision_tree(rev_id),
2520
 
                        not no_backup, pb)
 
2558
                        not no_backup, pb, report_changes=True)
2521
2559
        finally:
2522
2560
            pb.finished()
2523
2561
 
2607
2645
            other_branch = parent
2608
2646
            if other_branch is None:
2609
2647
                raise errors.BzrCommandError("No peer location known or specified.")
2610
 
            print "Using last location: " + local_branch.get_parent()
 
2648
            display_url = urlutils.unescape_for_display(parent,
 
2649
                                                        self.outf.encoding)
 
2650
            print "Using last location: " + display_url
 
2651
 
2611
2652
        remote_branch = Branch.open(other_branch)
2612
2653
        if remote_branch.base == local_branch.base:
2613
2654
            remote_branch = local_branch