/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/workingtree.py

  • Committer: Aaron Bentley
  • Date: 2006-10-12 01:50:46 UTC
  • mfrom: (2072 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: aaron.bentley@utoronto.ca-20061012015046-a5a625ca88adf11c
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
WorkingTree.open(dir).
30
30
"""
31
31
 
32
 
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
33
 
CONFLICT_HEADER_1 = "BZR conflict list format 1"
34
 
 
35
32
# TODO: Give the workingtree sole responsibility for the working inventory;
36
33
# remove the variable and references to it from the branch.  This may require
37
34
# updating the commit code so as to update the inventory within the working
39
36
# At the moment they may alias the inventory and have old copies of it in
40
37
# memory.  (Now done? -- mbp 20060309)
41
38
 
42
 
from binascii import hexlify
 
39
from cStringIO import StringIO
 
40
import os
 
41
import re
 
42
 
 
43
from bzrlib.lazy_import import lazy_import
 
44
lazy_import(globals(), """
43
45
import collections
44
46
from copy import deepcopy
45
 
from cStringIO import StringIO
46
47
import errno
47
48
import fnmatch
48
 
import os
49
 
import re
50
49
import stat
51
50
from time import time
52
51
import warnings
53
52
 
54
53
import bzrlib
55
 
from bzrlib import bzrdir, errors, ignores, osutils, urlutils
56
 
from bzrlib.atomicfile import AtomicFile
 
54
from bzrlib import (
 
55
    bzrdir,
 
56
    conflicts as _mod_conflicts,
 
57
    errors,
 
58
    ignores,
 
59
    merge,
 
60
    osutils,
 
61
    urlutils,
 
62
    textui,
 
63
    transform,
 
64
    xml5,
 
65
    xml6,
 
66
    )
57
67
import bzrlib.branch
58
 
from bzrlib.conflicts import Conflict, ConflictList, CONFLICT_SUFFIXES
 
68
from bzrlib.transport import get_transport
 
69
import bzrlib.ui
 
70
""")
 
71
 
59
72
from bzrlib.decorators import needs_read_lock, needs_write_lock
60
73
from bzrlib.errors import (BzrCheckError,
61
74
                           BzrError,
70
83
from bzrlib.inventory import InventoryEntry, Inventory
71
84
from bzrlib.lockable_files import LockableFiles, TransportLock
72
85
from bzrlib.lockdir import LockDir
73
 
from bzrlib.merge import merge_inner, transform_tree
74
86
import bzrlib.mutabletree
75
87
from bzrlib.mutabletree import needs_tree_write_lock
76
88
from bzrlib.osutils import (
77
 
                            abspath,
78
 
                            compact_date,
79
 
                            file_kind,
80
 
                            isdir,
81
 
                            getcwd,
82
 
                            pathjoin,
83
 
                            pumpfile,
84
 
                            safe_unicode,
85
 
                            splitpath,
86
 
                            rand_chars,
87
 
                            normpath,
88
 
                            realpath,
89
 
                            relpath,
90
 
                            rename,
91
 
                            supports_executable,
92
 
                            )
 
89
    compact_date,
 
90
    file_kind,
 
91
    isdir,
 
92
    pathjoin,
 
93
    safe_unicode,
 
94
    splitpath,
 
95
    rand_chars,
 
96
    normpath,
 
97
    realpath,
 
98
    supports_executable,
 
99
    )
 
100
from bzrlib.trace import mutter, note
 
101
from bzrlib.transport.local import LocalTransport
 
102
import bzrlib.tree
93
103
from bzrlib.progress import DummyProgress, ProgressPhase
94
104
from bzrlib.revision import NULL_REVISION
95
105
import bzrlib.revisiontree
101
111
        zero_eight,
102
112
        zero_eleven,
103
113
        )
104
 
from bzrlib.trace import mutter, note
105
 
from bzrlib.transform import build_tree
106
 
from bzrlib.transport import get_transport
107
 
from bzrlib.transport.local import LocalTransport
108
 
from bzrlib.textui import show_status
109
 
import bzrlib.ui
110
 
import bzrlib.xml5
111
 
 
 
114
 
 
115
 
 
116
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
 
117
CONFLICT_HEADER_1 = "BZR conflict list format 1"
112
118
 
113
119
# the regex removes any weird characters; we don't escape them 
114
120
# but rather just pull them out
399
405
        else:
400
406
            try:
401
407
                xml = self.read_basis_inventory()
402
 
                inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(xml)
 
408
                inv = xml6.serializer_v6.read_inventory_from_string(xml)
403
409
                if inv is not None and inv.revision_id == revision_id:
404
 
                    return bzrlib.tree.RevisionTree(self.branch.repository, 
 
410
                    return bzrlib.tree.RevisionTree(self.branch.repository,
405
411
                                                    inv, revision_id)
406
412
            except (NoSuchFile, errors.BadInventoryFormat):
407
413
                pass
463
469
        The path may be absolute or relative. If its a relative path it is 
464
470
        interpreted relative to the python current working directory.
465
471
        """
466
 
        return relpath(self.basedir, path)
 
472
        return osutils.relpath(self.basedir, path)
467
473
 
468
474
    def has_filename(self, filename):
469
475
        return osutils.lexists(self.abspath(filename))
534
540
        """Copy the current content and user files of this tree into tree."""
535
541
        tree.set_root_id(self.get_root_id())
536
542
        if revision_id is None:
537
 
            transform_tree(tree, self)
 
543
            merge.transform_tree(tree, self)
538
544
        else:
539
545
            # TODO now merge from tree.last_revision to revision (to preserve
540
546
            # user local changes)
541
 
            transform_tree(tree, self)
 
547
            merge.transform_tree(tree, self)
542
548
            tree.set_parent_ids([revision_id])
543
549
 
544
550
    def id2abspath(self, file_id):
1012
1018
                result.append((f, dest_path))
1013
1019
                inv.rename(inv.path2id(f), to_dir_id, name_tail)
1014
1020
                try:
1015
 
                    rename(self.abspath(f), self.abspath(dest_path))
 
1021
                    osutils.rename(self.abspath(f), self.abspath(dest_path))
1016
1022
                except OSError, e:
1017
1023
                    raise BzrError("failed to rename %r to %r: %s" %
1018
1024
                                   (f, dest_path, e[1]),
1064
1070
        from_abs = self.abspath(from_rel)
1065
1071
        to_abs = self.abspath(to_rel)
1066
1072
        try:
1067
 
            rename(from_abs, to_abs)
 
1073
            osutils.rename(from_abs, to_abs)
1068
1074
        except OSError, e:
1069
1075
            inv.rename(file_id, from_parent, from_name)
1070
1076
            raise BzrError("failed to rename %r to %r: %s"
1147
1153
                pb = bzrlib.ui.ui_factory.nested_progress_bar()
1148
1154
                try:
1149
1155
                    new_basis_tree = self.branch.basis_tree()
1150
 
                    merge_inner(self.branch,
 
1156
                    merge.merge_inner(
 
1157
                                self.branch,
1151
1158
                                new_basis_tree,
1152
1159
                                basis_tree,
1153
1160
                                this_tree=self,
1432
1439
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1433
1440
        """Create the text that will be saved in basis-inventory"""
1434
1441
        inventory.revision_id = revision_id
1435
 
        return bzrlib.xml6.serializer_v6.write_inventory_to_string(inventory)
 
1442
        return xml6.serializer_v6.write_inventory_to_string(inventory)
1436
1443
 
1437
1444
    def _cache_basis_inventory(self, new_revision):
1438
1445
        """Cache new_revision as the basis inventory."""
1471
1478
        """Read the working inventory."""
1472
1479
        # ElementTree does its own conversion from UTF-8, so open in
1473
1480
        # binary.
1474
 
        result = bzrlib.xml5.serializer_v5.read_inventory(
 
1481
        result = xml5.serializer_v5.read_inventory(
1475
1482
            self._control_files.get('inventory'))
1476
1483
        self._set_inventory(result)
1477
1484
        return result
1511
1518
                    new_status = 'I'
1512
1519
                else:
1513
1520
                    new_status = '?'
1514
 
                show_status(new_status, inv[fid].kind, f, to_file=to_file)
 
1521
                textui.show_status(new_status, inv[fid].kind, f,
 
1522
                                   to_file=to_file)
1515
1523
            del inv[fid]
1516
1524
 
1517
1525
        self._write_inventory(inv)
1519
1527
    @needs_tree_write_lock
1520
1528
    def revert(self, filenames, old_tree=None, backups=True, 
1521
1529
               pb=DummyProgress()):
1522
 
        from transform import revert
1523
 
        from conflicts import resolve
 
1530
        from bzrlib.conflicts import resolve
1524
1531
        if old_tree is None:
1525
1532
            old_tree = self.basis_tree()
1526
 
        conflicts = revert(self, old_tree, filenames, backups, pb)
 
1533
        conflicts = transform.revert(self, old_tree, filenames, backups, pb)
1527
1534
        if not len(filenames):
1528
1535
            self.set_parent_ids(self.get_parent_ids()[:1])
1529
1536
            resolve(self)
1630
1637
            to_tree = self.branch.basis_tree()
1631
1638
            if basis.inventory.root is None:
1632
1639
                self.set_root_id(to_tree.inventory.root.file_id)
1633
 
            result += merge_inner(self.branch,
 
1640
            result += merge.merge_inner(
 
1641
                                  self.branch,
1634
1642
                                  to_tree,
1635
1643
                                  basis,
1636
1644
                                  this_tree=self)
1671
1679
                base_rev_id = None
1672
1680
            base_tree = self.branch.repository.revision_tree(base_rev_id)
1673
1681
            other_tree = self.branch.repository.revision_tree(old_tip)
1674
 
            result += merge_inner(self.branch,
 
1682
            result += merge.merge_inner(
 
1683
                                  self.branch,
1675
1684
                                  other_tree,
1676
1685
                                  base_tree,
1677
1686
                                  this_tree=self)
1681
1690
    def _write_inventory(self, inv):
1682
1691
        """Write inventory as the current inventory."""
1683
1692
        sio = StringIO()
1684
 
        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
 
1693
        xml5.serializer_v5.write_inventory(inv, sio)
1685
1694
        sio.seek(0)
1686
1695
        self._control_files.put('inventory', sio)
1687
1696
        self._set_inventory(inv)
1695
1704
 
1696
1705
    @needs_read_lock
1697
1706
    def conflicts(self):
1698
 
        conflicts = ConflictList()
 
1707
        conflicts = _mod_conflicts.ConflictList()
1699
1708
        for conflicted in self._iter_conflicts():
1700
1709
            text = True
1701
1710
            try:
1714
1723
                    if text == False:
1715
1724
                        break
1716
1725
            ctype = {True: 'text conflict', False: 'contents conflict'}[text]
1717
 
            conflicts.append(Conflict.factory(ctype, path=conflicted,
 
1726
            conflicts.append(_mod_conflicts.Conflict.factory(ctype,
 
1727
                             path=conflicted,
1718
1728
                             file_id=self.path2id(conflicted)))
1719
1729
        return conflicts
1720
1730
 
1790
1800
    def add_conflicts(self, new_conflicts):
1791
1801
        conflict_set = set(self.conflicts())
1792
1802
        conflict_set.update(set(list(new_conflicts)))
1793
 
        self.set_conflicts(ConflictList(sorted(conflict_set,
1794
 
                                               key=Conflict.sort_key)))
 
1803
        self.set_conflicts(_mod_conflicts.ConflictList(sorted(conflict_set,
 
1804
                                       key=_mod_conflicts.Conflict.sort_key)))
1795
1805
 
1796
1806
    @needs_read_lock
1797
1807
    def conflicts(self):
1798
1808
        try:
1799
1809
            confile = self._control_files.get('conflicts')
1800
1810
        except NoSuchFile:
1801
 
            return ConflictList()
 
1811
            return _mod_conflicts.ConflictList()
1802
1812
        try:
1803
1813
            if confile.next() != CONFLICT_HEADER_1 + '\n':
1804
1814
                raise ConflictFormatError()
1805
1815
        except StopIteration:
1806
1816
            raise ConflictFormatError()
1807
 
        return ConflictList.from_stanzas(RioReader(confile))
 
1817
        return _mod_conflicts.ConflictList.from_stanzas(RioReader(confile))
1808
1818
 
1809
1819
    def unlock(self):
1810
1820
        if self._hashcache.needs_write and self._control_files._lock_count==1:
1817
1827
 
1818
1828
 
1819
1829
def get_conflicted_stem(path):
1820
 
    for suffix in CONFLICT_SUFFIXES:
 
1830
    for suffix in _mod_conflicts.CONFLICT_SUFFIXES:
1821
1831
        if path.endswith(suffix):
1822
1832
            return path[:-len(suffix)]
1823
1833
 
1929
1939
        """
1930
1940
        sio = StringIO()
1931
1941
        inv = Inventory()
1932
 
        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
 
1942
        xml5.serializer_v5.write_inventory(inv, sio)
1933
1943
        sio.seek(0)
1934
1944
        control_files.put('inventory', sio)
1935
1945
 
1966
1976
            inv.root.file_id = basis_tree.inventory.root.file_id
1967
1977
        wt._write_inventory(inv)
1968
1978
        wt.set_parent_trees([(revision, basis_tree)])
1969
 
        build_tree(basis_tree, wt)
 
1979
        transform.build_tree(basis_tree, wt)
1970
1980
        return wt
1971
1981
 
1972
1982
    def __init__(self):
2052
2062
                wt.set_parent_trees([])
2053
2063
            else:
2054
2064
                wt.set_parent_trees([(revision_id, basis_tree)])
2055
 
            build_tree(basis_tree, wt)
 
2065
            transform.build_tree(basis_tree, wt)
2056
2066
        finally:
2057
2067
            wt.unlock()
2058
2068
            control_files.unlock()