/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Ā fromĀ remote-transport

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
75
75
 
76
76
    :param file_list: Filenames to convert.  
77
77
 
78
 
    :param default_branch: Fallback tree path to use if file_list is empty or None.
 
78
    :param default_branch: Fallback tree path to use if file_list is empty or
 
79
        None.
79
80
 
80
81
    :return: workingtree, [relative_paths]
81
82
    """
82
83
    if file_list is None or len(file_list) == 0:
83
84
        return WorkingTree.open_containing(default_branch)[0], file_list
84
 
    tree = WorkingTree.open_containing(file_list[0])[0]
 
85
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
85
86
    new_list = []
86
87
    for filename in file_list:
87
88
        try:
88
 
            new_list.append(tree.relpath(filename))
 
89
            new_list.append(tree.relpath(osutils.dereference_path(filename)))
89
90
        except errors.PathNotChild:
90
91
            raise errors.FileInWrongBranch(tree.branch, filename)
91
92
    return tree, new_list
849
850
 
850
851
    def run(self, dir='.'):
851
852
        tree = WorkingTree.open_containing(dir)[0]
852
 
        tree.lock_write()
 
853
        master = tree.branch.get_master_branch()
 
854
        if master is not None:
 
855
            tree.lock_write()
 
856
        else:
 
857
            tree.lock_tree_write()
853
858
        try:
854
859
            existing_pending_merges = tree.get_parent_ids()[1:]
855
860
            last_rev = tree.last_revision()
1291
1296
        for file_id in inv:
1292
1297
            if file_id in basis_inv:
1293
1298
                continue
 
1299
            if inv.is_root(file_id) and len(basis_inv) == 0:
 
1300
                continue
1294
1301
            path = inv.id2path(file_id)
1295
1302
            if not os.access(osutils.abspath(path), os.F_OK):
1296
1303
                continue
1374
1381
                    # either no tree, or is remote.
1375
1382
                    inv = b.basis_tree().inventory
1376
1383
                file_id = inv.path2id(fp)
 
1384
                if file_id is None:
 
1385
                    raise errors.BzrCommandError(
 
1386
                        "Path does not have any revision history: %s" %
 
1387
                        location)
1377
1388
        else:
1378
1389
            # local dir only
1379
1390
            # FIXME ? log the current subdir only RBC 20060203 
1503
1514
            tree = tree.branch.repository.revision_tree(
1504
1515
                revision[0].in_history(tree.branch).rev_id)
1505
1516
 
1506
 
        for fp, fc, kind, fid, entry in tree.list_files():
 
1517
        for fp, fc, kind, fid, entry in tree.list_files(include_root=False):
1507
1518
            if fp.startswith(relpath):
1508
1519
                fp = fp[len(relpath):]
1509
1520
                if non_recursive and '/' in fp:
1529
1540
 
1530
1541
 
1531
1542
class cmd_ignore(Command):
1532
 
    """Ignore a command or pattern.
 
1543
    """Ignore specified files or patterns.
1533
1544
 
1534
1545
    To remove patterns from the ignore list, edit the .bzrignore file.
1535
1546
 
 
1547
    Trailing slashes on patterns are ignored. 
1536
1548
    If the pattern contains a slash, it is compared to the whole path
1537
1549
    from the branch root.  Otherwise, it is compared to only the last
1538
1550
    component of the path.  To match a file only in the root directory,
1539
1551
    prepend './'.
1540
1552
 
 
1553
    Ignore patterns specifying absolute paths are not allowed.
 
1554
 
1541
1555
    Ignore patterns are case-insensitive on case-insensitive systems.
1542
1556
 
1543
1557
    Note: wildcards must be quoted from the shell on Unix.
1546
1560
        bzr ignore ./Makefile
1547
1561
        bzr ignore '*.class'
1548
1562
    """
1549
 
    # TODO: Complain if the filename is absolute
1550
 
    takes_args = ['name_pattern?']
 
1563
    takes_args = ['name_pattern*']
1551
1564
    takes_options = [
1552
1565
                     Option('old-default-rules',
1553
1566
                            help='Out the ignore rules bzr < 0.9 always used.')
1554
1567
                     ]
1555
1568
    
1556
 
    def run(self, name_pattern=None, old_default_rules=None):
 
1569
    def run(self, name_pattern_list=None, old_default_rules=None):
1557
1570
        from bzrlib.atomicfile import AtomicFile
1558
1571
        if old_default_rules is not None:
1559
1572
            # dump the rules and exit
1560
1573
            for pattern in ignores.OLD_DEFAULTS:
1561
1574
                print pattern
1562
1575
            return
1563
 
        if name_pattern is None:
1564
 
            raise errors.BzrCommandError("ignore requires a NAME_PATTERN")
 
1576
        if not name_pattern_list:
 
1577
            raise errors.BzrCommandError("ignore requires at least one "
 
1578
                                  "NAME_PATTERN or --old-default-rules")
 
1579
        for name_pattern in name_pattern_list:
 
1580
            if name_pattern[0] == '/':
 
1581
                raise errors.BzrCommandError(
 
1582
                    "NAME_PATTERN should not be an absolute path")
1565
1583
        tree, relpath = WorkingTree.open_containing(u'.')
1566
1584
        ifn = tree.abspath('.bzrignore')
1567
1585
        if os.path.exists(ifn):
1578
1596
 
1579
1597
        if igns and igns[-1] != '\n':
1580
1598
            igns += '\n'
1581
 
        igns += name_pattern + '\n'
 
1599
        for name_pattern in name_pattern_list:
 
1600
            igns += name_pattern.rstrip('/') + '\n'
1582
1601
 
1583
 
        f = AtomicFile(ifn, 'wt')
 
1602
        f = AtomicFile(ifn, 'wb')
1584
1603
        try:
1585
1604
            f.write(igns.encode('utf-8'))
1586
1605
            f.commit()
1641
1660
    Root may be the top directory for tar, tgz and tbz2 formats. If none
1642
1661
    is given, the top directory will be the root name of the file.
1643
1662
 
 
1663
    If branch is omitted then the branch containing the CWD will be used.
 
1664
 
1644
1665
    Note: export of tree with non-ascii filenames to zip is not supported.
1645
1666
 
1646
1667
     Supported formats       Autodetected by extension
1651
1672
         tgz                      .tar.gz, .tgz
1652
1673
         zip                          .zip
1653
1674
    """
1654
 
    takes_args = ['dest']
 
1675
    takes_args = ['dest', 'branch?']
1655
1676
    takes_options = ['revision', 'format', 'root']
1656
 
    def run(self, dest, revision=None, format=None, root=None):
 
1677
    def run(self, dest, branch=None, revision=None, format=None, root=None):
1657
1678
        from bzrlib.export import export
1658
 
        tree = WorkingTree.open_containing(u'.')[0]
1659
 
        b = tree.branch
 
1679
 
 
1680
        if branch is None:
 
1681
            tree = WorkingTree.open_containing(u'.')[0]
 
1682
            b = tree.branch
 
1683
        else:
 
1684
            b = Branch.open(branch)
 
1685
            
1660
1686
        if revision is None:
1661
1687
            # should be tree.last_revision  FIXME
1662
1688
            rev_id = b.last_revision()
1675
1701
class cmd_cat(Command):
1676
1702
    """Write a file's text from a previous revision."""
1677
1703
 
1678
 
    takes_options = ['revision']
 
1704
    takes_options = ['revision', 'name-from-revision']
1679
1705
    takes_args = ['filename']
1680
1706
 
1681
1707
    @display_command
1682
 
    def run(self, filename, revision=None):
 
1708
    def run(self, filename, revision=None, name_from_revision=False):
1683
1709
        if revision is not None and len(revision) != 1:
1684
 
            raise errors.BzrCommandError("bzr cat --revision takes exactly one number")
 
1710
            raise errors.BzrCommandError("bzr cat --revision takes exactly"
 
1711
                                        " one number")
 
1712
 
1685
1713
        tree = None
1686
1714
        try:
1687
1715
            tree, relpath = WorkingTree.open_containing(filename)
1697
1725
            revision_id = b.last_revision()
1698
1726
        else:
1699
1727
            revision_id = revision[0].in_history(b).rev_id
1700
 
        b.print_file(relpath, revision_id)
 
1728
 
 
1729
        cur_file_id = tree.path2id(relpath)
 
1730
        rev_tree = b.repository.revision_tree(revision_id)
 
1731
        old_file_id = rev_tree.path2id(relpath)
 
1732
        
 
1733
        if name_from_revision:
 
1734
            if old_file_id is None:
 
1735
                raise errors.BzrCommandError("%r is not present in revision %s"
 
1736
                                                % (filename, revision_id))
 
1737
            else:
 
1738
                rev_tree.print_file(old_file_id)
 
1739
        elif cur_file_id is not None:
 
1740
            rev_tree.print_file(cur_file_id)
 
1741
        elif old_file_id is not None:
 
1742
            rev_tree.print_file(old_file_id)
 
1743
        else:
 
1744
            raise errors.BzrCommandError("%r is not present in revision %s" %
 
1745
                                         (filename, revision_id))
1701
1746
 
1702
1747
 
1703
1748
class cmd_local_time_offset(Command):
2326
2371
                    for name, ie in tree.inventory.iter_entries(file_id):
2327
2372
                        interesting_ids.add(ie.file_id)
2328
2373
                new_conflicts = conflicts.select_conflicts(tree, file_list)[0]
 
2374
            else:
 
2375
                # Remerge only supports resolving contents conflicts
 
2376
                allowed_conflicts = ('text conflict', 'contents conflict')
 
2377
                restore_files = [c.path for c in conflicts
 
2378
                                 if c.typestring in allowed_conflicts]
2329
2379
            _mod_merge.transform_tree(tree, tree.basis_tree(), interesting_ids)
2330
2380
            tree.set_conflicts(ConflictList(new_conflicts))
2331
 
            if file_list is None:
2332
 
                restore_files = list(tree.iter_conflicts())
2333
 
            else:
 
2381
            if file_list is not None:
2334
2382
                restore_files = file_list
2335
2383
            for filename in restore_files:
2336
2384
                try: