~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

Merge from mbp.

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,
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.get_revision_xml(revision_id))
148
148
        elif revision is not None:
159
159
    This is equal to the number of revisions on this branch."""
160
160
    @display_command
161
161
    def run(self):
162
 
        print Branch.open_containing('.')[0].revno()
 
162
        print Branch.open_containing(u'.')[0].revno()
163
163
 
164
164
 
165
165
class cmd_revision_info(Command):
180
180
        if len(revs) == 0:
181
181
            raise BzrCommandError('You must supply a revision identifier')
182
182
 
183
 
        b = WorkingTree.open_containing('.')[0].branch
 
183
        b = WorkingTree.open_containing(u'.')[0].branch
184
184
 
185
185
        for rev in revs:
186
186
            revinfo = rev.in_history(b)
263
263
    def run(self, revision=None, show_ids=False, kind=None):
264
264
        if kind and kind not in ['file', 'directory', 'symlink']:
265
265
            raise BzrCommandError('invalid kind specified')
266
 
        tree = WorkingTree.open_containing('.')[0]
 
266
        tree = WorkingTree.open_containing(u'.')[0]
267
267
        if revision is None:
268
268
            inv = tree.read_working_inventory()
269
269
        else:
375
375
        from shutil import rmtree
376
376
        import errno
377
377
        # FIXME: too much stuff is in the command class        
378
 
        tree_to = WorkingTree.open_containing('.')[0]
 
378
        tree_to = WorkingTree.open_containing(u'.')[0]
379
379
        stored_loc = tree_to.branch.get_parent()
380
380
        if location is None:
381
381
            if stored_loc is None:
395
395
                                  "  Try merge.")
396
396
        if br_to.get_parent() is None or remember:
397
397
            br_to.set_parent(location)
398
 
        note('%d revision(s) pulled.', count)
 
398
        note('%d revision(s) pulled.' % (count,))
 
399
 
399
400
        if verbose:
400
401
            new_rh = tree_to.branch.revision_history()
401
402
            if old_rh != new_rh:
441
442
        from shutil import rmtree
442
443
        from bzrlib.transport import get_transport
443
444
        
444
 
        tree_from = WorkingTree.open_containing('.')[0]
 
445
        tree_from = WorkingTree.open_containing(u'.')[0]
445
446
        br_from = tree_from.branch
446
447
        stored_loc = tree_from.branch.get_push_location()
447
448
        if location is None:
486
487
        if br_from.get_push_location() is None or remember:
487
488
            br_from.set_push_location(location)
488
489
        note('%d revision(s) pushed.' % (count,))
 
490
 
489
491
        if verbose:
490
492
            new_rh = br_to.revision_history()
491
493
            if old_rh != new_rh:
582
584
    takes_args = ['dir?']
583
585
 
584
586
    @display_command
585
 
    def run(self, dir='.'):
 
587
    def run(self, dir=u'.'):
586
588
        tree = WorkingTree.open_containing(dir)[0]
587
589
        old_inv = tree.branch.basis_tree().inventory
588
590
        new_inv = tree.read_working_inventory()
661
663
    hidden = True
662
664
    @display_command
663
665
    def run(self):
664
 
        branch = WorkingTree.open_containing('.')[0].branch
 
666
        branch = WorkingTree.open_containing(u'.')[0].branch
665
667
        for patchid in branch.revision_history():
666
668
            print patchid
667
669
 
671
673
    hidden = True
672
674
    @display_command
673
675
    def run(self):
674
 
        tree = WorkingTree.open_containing('.')[0]
 
676
        tree = WorkingTree.open_containing(u'.')[0]
675
677
        b = tree.branch
676
678
        # FIXME. should be tree.last_revision
677
679
        for revision_id in b.get_ancestry(b.last_revision()):
695
697
    def run(self, location=None):
696
698
        from bzrlib.branch import Branch
697
699
        if location is None:
698
 
            location = '.'
 
700
            location = u'.'
699
701
        else:
700
702
            # The path has to exist to initialize a
701
703
            # branch inside of it.
785
787
    # if the directories are very large...)
786
788
    @display_command
787
789
    def run(self, show_ids=False):
788
 
        tree = WorkingTree.open_containing('.')[0]
 
790
        tree = WorkingTree.open_containing(u'.')[0]
789
791
        old = tree.branch.basis_tree()
790
792
        for path, ie in old.inventory.iter_entries():
791
793
            if not tree.has_id(ie.file_id):
802
804
    def run(self):
803
805
        from bzrlib.delta import compare_trees
804
806
 
805
 
        tree = WorkingTree.open_containing('.')[0]
 
807
        tree = WorkingTree.open_containing(u'.')[0]
806
808
        td = compare_trees(tree.branch.basis_tree(), tree)
807
809
 
808
810
        for path, id, kind, text_modified, meta_modified in td.modified:
815
817
    hidden = True
816
818
    @display_command
817
819
    def run(self):
818
 
        wt = WorkingTree.open_containing('.')[0]
 
820
        wt = WorkingTree.open_containing(u'.')[0]
819
821
        basis_inv = wt.branch.basis_tree().inventory
820
822
        inv = wt.inventory
821
823
        for file_id in inv:
898
900
            else:
899
901
                file_id = None  # points to branch root
900
902
        else:
901
 
            tree, relpath = WorkingTree.open_containing('.')
 
903
            tree, relpath = WorkingTree.open_containing(u'.')
902
904
            b = tree.branch
903
905
            file_id = None
904
906
 
990
992
 
991
993
        selection = {'I':ignored, '?':unknown, 'V':versioned}
992
994
 
993
 
        tree, relpath = WorkingTree.open_containing('.')
 
995
        tree, relpath = WorkingTree.open_containing(u'.')
994
996
        if from_root:
995
 
            relpath = ''
 
997
            relpath = u''
996
998
        elif relpath:
997
999
            relpath += '/'
998
1000
        if revision is not None:
1021
1023
    @display_command
1022
1024
    def run(self):
1023
1025
        from bzrlib.osutils import quotefn
1024
 
        for f in WorkingTree.open_containing('.')[0].unknowns():
 
1026
        for f in WorkingTree.open_containing(u'.')[0].unknowns():
1025
1027
            print quotefn(f)
1026
1028
 
1027
1029
 
1050
1052
        from bzrlib.atomicfile import AtomicFile
1051
1053
        import os.path
1052
1054
 
1053
 
        tree, relpath = WorkingTree.open_containing('.')
 
1055
        tree, relpath = WorkingTree.open_containing(u'.')
1054
1056
        ifn = tree.abspath('.bzrignore')
1055
1057
 
1056
1058
        if os.path.exists(ifn):
1090
1092
    See also: bzr ignore"""
1091
1093
    @display_command
1092
1094
    def run(self):
1093
 
        tree = WorkingTree.open_containing('.')[0]
 
1095
        tree = WorkingTree.open_containing(u'.')[0]
1094
1096
        for path, file_class, kind, file_id, entry in tree.list_files():
1095
1097
            if file_class != 'I':
1096
1098
                continue
1115
1117
        except ValueError:
1116
1118
            raise BzrCommandError("not a valid revision-number: %r" % revno)
1117
1119
 
1118
 
        print WorkingTree.open_containing('.')[0].branch.get_rev_id(revno)
 
1120
        print WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
1119
1121
 
1120
1122
 
1121
1123
class cmd_export(Command):
1145
1147
    def run(self, dest, revision=None, format=None, root=None):
1146
1148
        import os.path
1147
1149
        from bzrlib.export import export
1148
 
        tree = WorkingTree.open_containing('.')[0]
 
1150
        tree = WorkingTree.open_containing(u'.')[0]
1149
1151
        b = tree.branch
1150
1152
        if revision is None:
1151
1153
            # should be tree.last_revision  FIXME
1232
1234
            unchanged=False, strict=False):
1233
1235
        from bzrlib.errors import (PointlessCommit, ConflictsInTree,
1234
1236
                StrictCommitFailed)
1235
 
        from bzrlib.msgeditor import edit_commit_message
 
1237
        from bzrlib.msgeditor import edit_commit_message, \
 
1238
                make_commit_message_template
1236
1239
        from bzrlib.status import show_status
1237
 
        from cStringIO import StringIO
1238
 
 
 
1240
        from tempfile import TemporaryFile
 
1241
        import codecs
 
1242
 
 
1243
        # TODO: Need a blackbox test for invoking the external editor; may be
 
1244
        # slightly problematic to run this cross-platform.
 
1245
 
 
1246
        # TODO: do more checks that the commit will succeed before 
 
1247
        # spending the user's valuable time typing a commit message.
 
1248
        #
 
1249
        # TODO: if the commit *does* happen to fail, then save the commit 
 
1250
        # message to a temporary file where it can be recovered
1239
1251
        tree, selected_list = tree_files(selected_list)
1240
1252
        if message is None and not file:
1241
 
            catcher = StringIO()
1242
 
            show_status(tree.branch, specific_files=selected_list,
1243
 
                        to_file=catcher)
1244
 
            message = edit_commit_message(catcher.getvalue())
1245
 
 
 
1253
            template = make_commit_message_template(tree, selected_list)
 
1254
            message = edit_commit_message(template)
1246
1255
            if message is None:
1247
1256
                raise BzrCommandError("please specify a commit message"
1248
1257
                                      " with either --message or --file")
1271
1280
            raise BzrCommandError("Commit refused because there are unknown "
1272
1281
                                  "files in the working tree.")
1273
1282
        note('Committed revision %d.' % (tree.branch.revno(),))
1274
 
        
 
1283
 
1275
1284
 
1276
1285
class cmd_check(Command):
1277
1286
    """Validate consistency of branch history.
1297
1306
    def run(self):
1298
1307
        from bzrlib.hashcache import HashCache
1299
1308
 
1300
 
        c = HashCache('.')
 
1309
        c = HashCache(u'.')
1301
1310
        c.read()
1302
1311
        c.scan()
1303
1312
            
1323
1332
    """
1324
1333
    takes_args = ['dir?']
1325
1334
 
1326
 
    def run(self, dir='.'):
 
1335
    def run(self, dir=u'.'):
1327
1336
        from bzrlib.upgrade import upgrade
1328
1337
        upgrade(dir)
1329
1338
 
1335
1344
    @display_command
1336
1345
    def run(self, email=False):
1337
1346
        try:
1338
 
            b = WorkingTree.open_containing('.')[0].branch
 
1347
            b = WorkingTree.open_containing(u'.')[0].branch
1339
1348
            config = bzrlib.config.BranchConfig(b)
1340
1349
        except NotBranchError:
1341
1350
            config = bzrlib.config.GlobalConfig()
1353
1362
    """
1354
1363
    takes_args = ['nickname?']
1355
1364
    def run(self, nickname=None):
1356
 
        branch = Branch.open_containing('.')[0]
 
1365
        branch = Branch.open_containing(u'.')[0]
1357
1366
        if nickname is None:
1358
1367
            self.printme(branch)
1359
1368
        else:
1518
1527
        if merge_type is None:
1519
1528
            merge_type = ApplyMerge3
1520
1529
        if branch is None:
1521
 
            branch = WorkingTree.open_containing('.')[0].branch.get_parent()
 
1530
            branch = WorkingTree.open_containing(u'.')[0].branch.get_parent()
1522
1531
            if branch is None:
1523
1532
                raise BzrCommandError("No merge location known or specified.")
1524
1533
            else:
1641
1650
            file_list = []
1642
1651
        if revision is None:
1643
1652
            revno = -1
1644
 
            tree = WorkingTree.open_containing('.')[0]
 
1653
            tree = WorkingTree.open_containing(u'.')[0]
1645
1654
            # FIXME should be tree.last_revision
1646
1655
            rev_id = tree.branch.last_revision()
1647
1656
        elif len(revision) != 1:
1730
1739
        if verbose and is_quiet():
1731
1740
            raise BzrCommandError('Cannot pass both quiet and verbose')
1732
1741
 
1733
 
        tree = WorkingTree.open_containing('.')[0]
 
1742
        tree = WorkingTree.open_containing(u'.')[0]
1734
1743
        parent = tree.branch.get_parent()
1735
1744
        if remote is None:
1736
1745
            if parent is None:
1773
1782
    takes_options = ['revision', 'long']
1774
1783
    takes_args = ['branch?']
1775
1784
    @display_command
1776
 
    def run(self, branch='.', revision=None, long=False):
 
1785
    def run(self, branch=u'.', revision=None, long=False):
1777
1786
        from bzrlib.testament import Testament
1778
1787
        b = WorkingTree.open_containing(branch)[0].branch
1779
1788
        b.lock_read()
1840
1849
            raise BzrCommandError('You can only supply one of revision_id or --revision')
1841
1850
        if revision_id is None and revision is None:
1842
1851
            raise BzrCommandError('You must supply either --revision or a revision_id')
1843
 
        b = WorkingTree.open_containing('.')[0].branch
 
1852
        b = WorkingTree.open_containing(u'.')[0].branch
1844
1853
        gpg_strategy = gpg.GPGStrategy(config.BranchConfig(b))
1845
1854
        if revision_id is not None:
1846
1855
            b.sign_revision(revision_id, gpg_strategy)
1893
1902
        from bzrlib.uncommit import uncommit
1894
1903
 
1895
1904
        if location is None:
1896
 
            location = '.'
 
1905
            location = u'.'
1897
1906
        b, relpath = Branch.open_containing(location)
1898
1907
 
1899
1908
        if revision is None: