/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import BZRDIR
27
27
from bzrlib.commands import Command, display_command
28
28
from bzrlib.branch import Branch
 
29
from bzrlib.revision import common_ancestor
29
30
import bzrlib.errors as errors
30
 
from bzrlib.errors import BzrError, BzrCheckError, BzrCommandError, NotBranchError
31
 
from bzrlib.errors import DivergedBranches, NoSuchFile, NoWorkingTree
 
31
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
 
32
                           NotBranchError, DivergedBranches, NotConflicted,
 
33
                           NoSuchFile, NoWorkingTree)
32
34
from bzrlib.option import Option
33
35
from bzrlib.revisionspec import RevisionSpec
34
36
import bzrlib.trace
37
39
 
38
40
 
39
41
def branch_files(file_list, default_branch='.'):
 
42
    try:
 
43
        return inner_branch_files(file_list, default_branch)
 
44
    except NotBranchError:
 
45
        raise BzrCommandError("%s is not in the same branch as %s" %
 
46
                             (filename, file_list[0]))
 
47
 
 
48
def inner_branch_files(file_list, default_branch='.'):
40
49
    """\
41
50
    Return a branch and list of branch-relative paths.
42
51
    If supplied file_list is empty or None, the branch default will be used,
53
62
    tree = WorkingTree(b.base, b)
54
63
    new_list = []
55
64
    for filename in file_list:
56
 
        try:
57
 
            new_list.append(tree.relpath(filename))
58
 
        except NotBranchError:
59
 
            raise BzrCommandError("%s is not in the same branch as %s" % 
60
 
                                  (filename, file_list[0]))
 
65
        new_list.append(tree.relpath(filename))
61
66
    return b, new_list
62
67
 
63
68
 
107
112
    that revision, or between two revisions if two are provided.
108
113
    """
109
114
    
110
 
    # XXX: FIXME: bzr status should accept a -r option to show changes
111
 
    # relative to a revision, or between revisions
112
 
 
113
115
    # TODO: --no-recurse, --recurse options
114
116
    
115
117
    takes_args = ['file*']
116
 
    takes_options = ['all', 'show-ids']
 
118
    takes_options = ['all', 'show-ids', 'revision']
117
119
    aliases = ['st', 'stat']
118
120
    
119
121
    @display_command
622
624
    @display_command
623
625
    def run(self, filename):
624
626
        b, relpath = Branch.open_containing(filename)
625
 
        i = b.inventory.path2id(relpath)
 
627
        i = b.working_tree().inventory.path2id(relpath)
626
628
        if i == None:
627
629
            raise BzrError("%r is not a versioned file" % filename)
628
630
        else:
739
741
    @display_command
740
742
    def run(self, revision=None, file_list=None, diff_options=None):
741
743
        from bzrlib.diff import show_diff
742
 
        
743
 
        b, file_list = branch_files(file_list)
 
744
        try:
 
745
            b, file_list = inner_branch_files(file_list)
 
746
            b2 = None
 
747
        except NotBranchError:
 
748
            if len(file_list) != 2:
 
749
                raise BzrCommandError("Files are in different branches")
 
750
 
 
751
            b, file1 = Branch.open_containing(file_list[0])
 
752
            b2, file2 = Branch.open_containing(file_list[1])
 
753
            if file1 != "" or file2 != "":
 
754
                raise BzrCommandError("Files are in different branches")
 
755
            file_list = None
744
756
        if revision is not None:
 
757
            if b2 is not None:
 
758
                raise BzrCommandError("Can't specify -r with two branches")
745
759
            if len(revision) == 1:
746
760
                return show_diff(b, revision[0], specific_files=file_list,
747
761
                                 external_diff_options=diff_options)
753
767
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
754
768
        else:
755
769
            return show_diff(b, None, specific_files=file_list,
756
 
                             external_diff_options=diff_options)
 
770
                             external_diff_options=diff_options, b2=b2)
757
771
 
758
772
 
759
773
class cmd_deleted(Command):
1307
1321
        else:
1308
1322
            print config.username()
1309
1323
 
 
1324
class cmd_nick(Command):
 
1325
    """\
 
1326
    Print or set the branch nickname.  
 
1327
    If unset, the tree root directory name is used as the nickname
 
1328
    To print the current nickname, execute with no argument.  
 
1329
    """
 
1330
    takes_args = ['nickname?']
 
1331
    def run(self, nickname=None):
 
1332
        branch = Branch.open_containing('.')[0]
 
1333
        if nickname is None:
 
1334
            self.printme(branch)
 
1335
        else:
 
1336
            branch.nick = nickname
 
1337
 
 
1338
    @display_command
 
1339
    def printme(self, branch):
 
1340
        print branch.nick 
1310
1341
 
1311
1342
class cmd_selftest(Command):
1312
1343
    """Run internal test suite.
1314
1345
    This creates temporary test directories in the working directory,
1315
1346
    but not existing data is affected.  These directories are deleted
1316
1347
    if the tests pass, or left behind to help in debugging if they
1317
 
    fail.
 
1348
    fail and --keep-output is specified.
1318
1349
    
1319
1350
    If arguments are given, they are regular expressions that say
1320
1351
    which tests should run.
1324
1355
    takes_args = ['testspecs*']
1325
1356
    takes_options = ['verbose', 
1326
1357
                     Option('one', help='stop when one test fails'),
 
1358
                     Option('keep-output', 
 
1359
                            help='keep output directories when tests fail')
1327
1360
                    ]
1328
1361
 
1329
 
    def run(self, testspecs_list=None, verbose=False, one=False):
 
1362
    def run(self, testspecs_list=None, verbose=False, one=False,
 
1363
            keep_output=False):
1330
1364
        import bzrlib.ui
1331
1365
        from bzrlib.selftest import selftest
1332
1366
        # we don't want progress meters from the tests to go to the
1342
1376
                pattern = ".*"
1343
1377
            result = selftest(verbose=verbose, 
1344
1378
                              pattern=pattern,
1345
 
                              stop_on_failure=one)
 
1379
                              stop_on_failure=one, 
 
1380
                              keep_output=keep_output)
1346
1381
            if result:
1347
1382
                bzrlib.trace.info('tests passed')
1348
1383
            else:
1501
1536
            log_error(m)
1502
1537
 
1503
1538
 
 
1539
class cmd_remerge(Command):
 
1540
    """Redo a merge.
 
1541
    """
 
1542
    takes_args = ['file*']
 
1543
    takes_options = ['merge-type', 'reprocess',
 
1544
                     Option('show-base', help="Show base revision text in "
 
1545
                            "conflicts")]
 
1546
 
 
1547
    def run(self, file_list=None, merge_type=None, show_base=False,
 
1548
            reprocess=False):
 
1549
        from bzrlib.merge import merge_inner, transform_tree
 
1550
        from bzrlib.merge_core import ApplyMerge3
 
1551
        if merge_type is None:
 
1552
            merge_type = ApplyMerge3
 
1553
        b, file_list = branch_files(file_list)
 
1554
        b.lock_write()
 
1555
        try:
 
1556
            pending_merges = b.working_tree().pending_merges() 
 
1557
            if len(pending_merges) != 1:
 
1558
                raise BzrCommandError("Sorry, remerge only works after normal"
 
1559
                                      + " merges.  Not cherrypicking or"
 
1560
                                      + "multi-merges.")
 
1561
            this_tree = b.working_tree()
 
1562
            base_revision = common_ancestor(b.last_revision(), 
 
1563
                                            pending_merges[0], b)
 
1564
            base_tree = b.revision_tree(base_revision)
 
1565
            other_tree = b.revision_tree(pending_merges[0])
 
1566
            interesting_ids = None
 
1567
            if file_list is not None:
 
1568
                interesting_ids = set()
 
1569
                for filename in file_list:
 
1570
                    file_id = this_tree.path2id(filename)
 
1571
                    interesting_ids.add(file_id)
 
1572
                    if this_tree.kind(file_id) != "directory":
 
1573
                        continue
 
1574
                    
 
1575
                    for name, ie in this_tree.inventory.iter_entries(file_id):
 
1576
                        interesting_ids.add(ie.file_id)
 
1577
            transform_tree(this_tree, b.basis_tree(), interesting_ids)
 
1578
            if file_list is None:
 
1579
                restore_files = list(this_tree.iter_conflicts())
 
1580
            else:
 
1581
                restore_files = file_list
 
1582
            for filename in restore_files:
 
1583
                try:
 
1584
                    restore(this_tree.abspath(filename))
 
1585
                except NotConflicted:
 
1586
                    pass
 
1587
            conflicts =  merge_inner(b, other_tree, base_tree, 
 
1588
                                     interesting_ids = interesting_ids, 
 
1589
                                     other_rev_id=pending_merges[0], 
 
1590
                                     merge_type=merge_type, 
 
1591
                                     show_base=show_base,
 
1592
                                     reprocess=reprocess)
 
1593
        finally:
 
1594
            b.unlock()
 
1595
        if conflicts > 0:
 
1596
            return 1
 
1597
        else:
 
1598
            return 0
 
1599
 
1504
1600
class cmd_revert(Command):
1505
1601
    """Reverse all changes since the last commit.
1506
1602
 
1749
1845
# TODO: Some more consistent way to split command definitions across files;
1750
1846
# we do need to load at least some information about them to know of 
1751
1847
# aliases.
1752
 
from bzrlib.conflicts import cmd_resolve, cmd_conflicts
 
1848
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore