~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from bzrlib.workingtree import WorkingTree
39
39
 
40
40
 
41
 
def tree_files(file_list, default_branch='.'):
 
41
def tree_files(file_list, default_branch=u'.'):
42
42
    try:
43
43
        return internal_tree_files(file_list, default_branch)
44
44
    except FileInWrongBranch, e:
45
45
        raise BzrCommandError("%s is not in the same branch as %s" %
46
46
                             (e.path, file_list[0]))
47
47
 
48
 
def internal_tree_files(file_list, default_branch='.'):
 
48
def internal_tree_files(file_list, default_branch=u'.'):
49
49
    """\
50
50
    Return a branch and list of branch-relative paths.
51
51
    If supplied file_list is empty or None, the branch default will be used,
58
58
    for filename in file_list:
59
59
        try:
60
60
            new_list.append(tree.relpath(filename))
61
 
        except NotBranchError:
 
61
        except errors.PathNotChild:
62
62
            raise FileInWrongBranch(tree.branch, filename)
63
63
    return tree, new_list
64
64
 
142
142
            raise BzrCommandError('You can only supply one of revision_id or --revision')
143
143
        if revision_id is None and revision is None:
144
144
            raise BzrCommandError('You must supply either --revision or a revision_id')
145
 
        b = WorkingTree.open_containing('.')[0].branch
 
145
        b = WorkingTree.open_containing(u'.')[0].branch
146
146
        if revision_id is not None:
147
147
            sys.stdout.write(b.storage.get_revision_xml(revision_id))
148
148
        elif revision is not None:
157
157
    """Show current revision number.
158
158
 
159
159
    This is equal to the number of revisions on this branch."""
 
160
    takes_args = ['location?']
160
161
    @display_command
161
 
    def run(self):
162
 
        print Branch.open_containing('.')[0].revno()
 
162
    def run(self, location=u'.'):
 
163
        print Branch.open_containing(location)[0].revno()
163
164
 
164
165
 
165
166
class cmd_revision_info(Command):
180
181
        if len(revs) == 0:
181
182
            raise BzrCommandError('You must supply a revision identifier')
182
183
 
183
 
        b = WorkingTree.open_containing('.')[0].branch
 
184
        b = WorkingTree.open_containing(u'.')[0].branch
184
185
 
185
186
        for rev in revs:
186
187
            revinfo = rev.in_history(b)
263
264
    def run(self, revision=None, show_ids=False, kind=None):
264
265
        if kind and kind not in ['file', 'directory', 'symlink']:
265
266
            raise BzrCommandError('invalid kind specified')
266
 
        tree = WorkingTree.open_containing('.')[0]
 
267
        tree = WorkingTree.open_containing(u'.')[0]
267
268
        if revision is None:
268
269
            inv = tree.read_working_inventory()
269
270
        else:
375
376
        from shutil import rmtree
376
377
        import errno
377
378
        # FIXME: too much stuff is in the command class        
378
 
        tree_to = WorkingTree.open_containing('.')[0]
 
379
        tree_to = WorkingTree.open_containing(u'.')[0]
379
380
        stored_loc = tree_to.branch.get_parent()
380
381
        if location is None:
381
382
            if stored_loc is None:
395
396
                                  "  Try merge.")
396
397
        if br_to.get_parent() is None or remember:
397
398
            br_to.set_parent(location)
398
 
        note('%d revision(s) pulled.', count)
 
399
        note('%d revision(s) pulled.' % (count,))
 
400
 
399
401
        if verbose:
400
402
            new_rh = tree_to.branch.revision_history()
401
403
            if old_rh != new_rh:
441
443
        from shutil import rmtree
442
444
        from bzrlib.transport import get_transport
443
445
        
444
 
        tree_from = WorkingTree.open_containing('.')[0]
 
446
        tree_from = WorkingTree.open_containing(u'.')[0]
445
447
        br_from = tree_from.branch
446
448
        stored_loc = tree_from.branch.get_push_location()
447
449
        if location is None:
477
479
                            raise BzrCommandError("Could not creeate "
478
480
                                                  "path prefix.")
479
481
            br_to = Branch.initialize(location)
 
482
        old_rh = br_to.revision_history()
480
483
        try:
481
 
            old_rh = br_to.revision_history()
482
 
            count = br_to.pull(br_from, overwrite)
 
484
            try:
 
485
                tree_to = br_to.working_tree()
 
486
            except NoWorkingTree:
 
487
                # TODO: This should be updated for branches which don't have a
 
488
                # working tree, as opposed to ones where we just couldn't 
 
489
                # update the tree.
 
490
                warning('Unable to update the working tree of: %s' % (br_to.base,))
 
491
                count = br_to.pull(br_from, overwrite)
 
492
            else:
 
493
                count = tree_to.pull(br_from, overwrite)
483
494
        except DivergedBranches:
484
495
            raise BzrCommandError("These branches have diverged."
485
496
                                  "  Try a merge then push with overwrite.")
486
497
        if br_from.get_push_location() is None or remember:
487
498
            br_from.set_push_location(location)
488
499
        note('%d revision(s) pushed.' % (count,))
 
500
 
489
501
        if verbose:
490
502
            new_rh = br_to.revision_history()
491
503
            if old_rh != new_rh:
581
593
    takes_args = ['dir?']
582
594
 
583
595
    @display_command
584
 
    def run(self, dir='.'):
 
596
    def run(self, dir=u'.'):
585
597
        tree = WorkingTree.open_containing(dir)[0]
586
598
        old_inv = tree.branch.basis_tree().inventory
587
599
        new_inv = tree.read_working_inventory()
660
672
    hidden = True
661
673
    @display_command
662
674
    def run(self):
663
 
        branch = WorkingTree.open_containing('.')[0].branch
 
675
        branch = WorkingTree.open_containing(u'.')[0].branch
664
676
        for patchid in branch.revision_history():
665
677
            print patchid
666
678
 
670
682
    hidden = True
671
683
    @display_command
672
684
    def run(self):
673
 
        tree = WorkingTree.open_containing('.')[0]
 
685
        tree = WorkingTree.open_containing(u'.')[0]
674
686
        b = tree.branch
675
687
        # FIXME. should be tree.last_revision
676
688
        for revision_id in b.get_ancestry(b.last_revision()):
694
706
    def run(self, location=None):
695
707
        from bzrlib.branch import Branch
696
708
        if location is None:
697
 
            location = '.'
 
709
            location = u'.'
698
710
        else:
699
711
            # The path has to exist to initialize a
700
712
            # branch inside of it.
784
796
    # if the directories are very large...)
785
797
    @display_command
786
798
    def run(self, show_ids=False):
787
 
        tree = WorkingTree.open_containing('.')[0]
 
799
        tree = WorkingTree.open_containing(u'.')[0]
788
800
        old = tree.branch.basis_tree()
789
801
        for path, ie in old.inventory.iter_entries():
790
802
            if not tree.has_id(ie.file_id):
801
813
    def run(self):
802
814
        from bzrlib.delta import compare_trees
803
815
 
804
 
        tree = WorkingTree.open_containing('.')[0]
 
816
        tree = WorkingTree.open_containing(u'.')[0]
805
817
        td = compare_trees(tree.branch.basis_tree(), tree)
806
818
 
807
819
        for path, id, kind, text_modified, meta_modified in td.modified:
814
826
    hidden = True
815
827
    @display_command
816
828
    def run(self):
817
 
        wt = WorkingTree.open_containing('.')[0]
 
829
        wt = WorkingTree.open_containing(u'.')[0]
818
830
        basis_inv = wt.branch.basis_tree().inventory
819
831
        inv = wt.inventory
820
832
        for file_id in inv:
897
909
            else:
898
910
                file_id = None  # points to branch root
899
911
        else:
900
 
            tree, relpath = WorkingTree.open_containing('.')
 
912
            tree, relpath = WorkingTree.open_containing(u'.')
901
913
            b = tree.branch
902
914
            file_id = None
903
915
 
989
1001
 
990
1002
        selection = {'I':ignored, '?':unknown, 'V':versioned}
991
1003
 
992
 
        tree, relpath = WorkingTree.open_containing('.')
 
1004
        tree, relpath = WorkingTree.open_containing(u'.')
993
1005
        if from_root:
994
 
            relpath = ''
 
1006
            relpath = u''
995
1007
        elif relpath:
996
1008
            relpath += '/'
997
1009
        if revision is not None:
1020
1032
    @display_command
1021
1033
    def run(self):
1022
1034
        from bzrlib.osutils import quotefn
1023
 
        for f in WorkingTree.open_containing('.')[0].unknowns():
 
1035
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
1024
1036
            print quotefn(f)
1025
1037
 
1026
1038
 
1049
1061
        from bzrlib.atomicfile import AtomicFile
1050
1062
        import os.path
1051
1063
 
1052
 
        tree, relpath = WorkingTree.open_containing('.')
 
1064
        tree, relpath = WorkingTree.open_containing(u'.')
1053
1065
        ifn = tree.abspath('.bzrignore')
1054
1066
 
1055
1067
        if os.path.exists(ifn):
1089
1101
    See also: bzr ignore"""
1090
1102
    @display_command
1091
1103
    def run(self):
1092
 
        tree = WorkingTree.open_containing('.')[0]
 
1104
        tree = WorkingTree.open_containing(u'.')[0]
1093
1105
        for path, file_class, kind, file_id, entry in tree.list_files():
1094
1106
            if file_class != 'I':
1095
1107
                continue
1114
1126
        except ValueError:
1115
1127
            raise BzrCommandError("not a valid revision-number: %r" % revno)
1116
1128
 
1117
 
        print WorkingTree.open_containing('.')[0].branch.get_rev_id(revno)
 
1129
        print WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
1118
1130
 
1119
1131
 
1120
1132
class cmd_export(Command):
1144
1156
    def run(self, dest, revision=None, format=None, root=None):
1145
1157
        import os.path
1146
1158
        from bzrlib.export import export
1147
 
        tree = WorkingTree.open_containing('.')[0]
 
1159
        tree = WorkingTree.open_containing(u'.')[0]
1148
1160
        b = tree.branch
1149
1161
        if revision is None:
1150
1162
            # should be tree.last_revision  FIXME
1168
1180
 
1169
1181
    @display_command
1170
1182
    def run(self, filename, revision=None):
1171
 
        if revision is None:
1172
 
            raise BzrCommandError("bzr cat requires a revision number")
1173
 
        elif len(revision) != 1:
 
1183
        if revision is not None and len(revision) != 1:
1174
1184
            raise BzrCommandError("bzr cat --revision takes exactly one number")
1175
1185
        tree = None
1176
1186
        try:
1178
1188
            b = tree.branch
1179
1189
        except NotBranchError:
1180
1190
            pass
 
1191
 
1181
1192
        if tree is None:
1182
1193
            b, relpath = Branch.open_containing(filename)
1183
 
        b.print_file(relpath, revision[0].in_history(b).revno)
 
1194
        if revision is None:
 
1195
            revision_id = b.last_revision()
 
1196
        else:
 
1197
            revision_id = revision[0].in_history(b).rev_id
 
1198
        b.print_file(relpath, revision_id)
1184
1199
 
1185
1200
 
1186
1201
class cmd_local_time_offset(Command):
1231
1246
            unchanged=False, strict=False):
1232
1247
        from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1233
1248
                StrictCommitFailed)
1234
 
        from bzrlib.msgeditor import edit_commit_message
 
1249
        from bzrlib.msgeditor import edit_commit_message, \
 
1250
                make_commit_message_template
1235
1251
        from bzrlib.status import show_status
1236
 
        from cStringIO import StringIO
1237
 
 
 
1252
        from tempfile import TemporaryFile
 
1253
        import codecs
 
1254
 
 
1255
        # TODO: Need a blackbox test for invoking the external editor; may be
 
1256
        # slightly problematic to run this cross-platform.
 
1257
 
 
1258
        # TODO: do more checks that the commit will succeed before 
 
1259
        # spending the user's valuable time typing a commit message.
 
1260
        #
 
1261
        # TODO: if the commit *does* happen to fail, then save the commit 
 
1262
        # message to a temporary file where it can be recovered
1238
1263
        tree, selected_list = tree_files(selected_list)
1239
1264
        if message is None and not file:
1240
 
            catcher = StringIO()
1241
 
            show_status(tree.branch, specific_files=selected_list,
1242
 
                        to_file=catcher)
1243
 
            message = edit_commit_message(catcher.getvalue())
1244
 
 
 
1265
            template = make_commit_message_template(tree, selected_list)
 
1266
            message = edit_commit_message(template)
1245
1267
            if message is None:
1246
1268
                raise BzrCommandError("please specify a commit message"
1247
1269
                                      " with either --message or --file")
1270
1292
            raise BzrCommandError("Commit refused because there are unknown "
1271
1293
                                  "files in the working tree.")
1272
1294
        note('Committed revision %d.' % (tree.branch.revno(),))
1273
 
        
 
1295
 
1274
1296
 
1275
1297
class cmd_check(Command):
1276
1298
    """Validate consistency of branch history.
1296
1318
    def run(self):
1297
1319
        from bzrlib.hashcache import HashCache
1298
1320
 
1299
 
        c = HashCache('.')
 
1321
        c = HashCache(u'.')
1300
1322
        c.read()
1301
1323
        c.scan()
1302
1324
            
1322
1344
    """
1323
1345
    takes_args = ['dir?']
1324
1346
 
1325
 
    def run(self, dir='.'):
 
1347
    def run(self, dir=u'.'):
1326
1348
        from bzrlib.upgrade import upgrade
1327
1349
        upgrade(dir)
1328
1350
 
1334
1356
    @display_command
1335
1357
    def run(self, email=False):
1336
1358
        try:
1337
 
            b = WorkingTree.open_containing('.')[0].branch
 
1359
            b = WorkingTree.open_containing(u'.')[0].branch
1338
1360
            config = bzrlib.config.BranchConfig(b)
1339
1361
        except NotBranchError:
1340
1362
            config = bzrlib.config.GlobalConfig()
1352
1374
    """
1353
1375
    takes_args = ['nickname?']
1354
1376
    def run(self, nickname=None):
1355
 
        branch = Branch.open_containing('.')[0]
 
1377
        branch = Branch.open_containing(u'.')[0]
1356
1378
        if nickname is None:
1357
1379
            self.printme(branch)
1358
1380
        else:
1517
1539
        if merge_type is None:
1518
1540
            merge_type = ApplyMerge3
1519
1541
        if branch is None:
1520
 
            branch = WorkingTree.open_containing('.')[0].branch.get_parent()
 
1542
            branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1521
1543
            if branch is None:
1522
1544
                raise BzrCommandError("No merge location known or specified.")
1523
1545
            else:
1641
1663
            file_list = []
1642
1664
        if revision is None:
1643
1665
            revno = -1
1644
 
            tree = WorkingTree.open_containing('.')[0]
 
1666
            tree = WorkingTree.open_containing(u'.')[0]
1645
1667
            # FIXME should be tree.last_revision
1646
1668
            rev_id = tree.branch.last_revision()
1647
1669
        elif len(revision) != 1:
1730
1752
        if verbose and is_quiet():
1731
1753
            raise BzrCommandError('Cannot pass both quiet and verbose')
1732
1754
 
1733
 
        tree = WorkingTree.open_containing('.')[0]
 
1755
        tree = WorkingTree.open_containing(u'.')[0]
1734
1756
        parent = tree.branch.get_parent()
1735
1757
        if remote is None:
1736
1758
            if parent is None:
1755
1777
    def run(self):
1756
1778
        import bzrlib.plugin
1757
1779
        from inspect import getdoc
1758
 
        for plugin in bzrlib.plugin.all_plugins:
 
1780
        for name, plugin in bzrlib.plugin.all_plugins().items():
1759
1781
            if hasattr(plugin, '__path__'):
1760
1782
                print plugin.__path__[0]
1761
1783
            elif hasattr(plugin, '__file__'):
1773
1795
    takes_options = ['revision', 'long']
1774
1796
    takes_args = ['branch?']
1775
1797
    @display_command
1776
 
    def run(self, branch='.', revision=None, long=False):
 
1798
    def run(self, branch=u'.', revision=None, long=False):
1777
1799
        from bzrlib.testament import Testament
1778
1800
        b = WorkingTree.open_containing(branch)[0].branch
1779
1801
        b.lock_read()
1840
1862
            raise BzrCommandError('You can only supply one of revision_id or --revision')
1841
1863
        if revision_id is None and revision is None:
1842
1864
            raise BzrCommandError('You must supply either --revision or a revision_id')
1843
 
        b = WorkingTree.open_containing('.')[0].branch
 
1865
        b = WorkingTree.open_containing(u'.')[0].branch
1844
1866
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1845
1867
        if revision_id is not None:
1846
1868
            b.storage.sign_revision(revision_id, gpg_strategy)
1893
1915
        from bzrlib.uncommit import uncommit
1894
1916
 
1895
1917
        if location is None:
1896
 
            location = '.'
 
1918
            location = u'.'
1897
1919
        b, relpath = Branch.open_containing(location)
1898
1920
 
1899
1921
        if revision is None: