/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: Canonical.com Patch Queue Manager
  • Date: 2006-04-09 16:49:22 UTC
  • mfrom: (1534.10.27 bzr.ttransform)
  • Revision ID: pqm@pqm.ubuntu.com-20060409164922-071803e906c8b96d
New conflict-handling system

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
"""
31
31
 
32
32
MERGE_MODIFIED_HEADER_1 = "BZR merge-modified list format 1"
 
33
CONFLICT_HEADER_1 = "BZR conflict list format 1"
33
34
 
34
35
# TODO: Give the workingtree sole responsibility for the working inventory;
35
36
# remove the variable and references to it from the branch.  This may require
49
50
from bzrlib.atomicfile import AtomicFile
50
51
from bzrlib.branch import (Branch,
51
52
                           quotefn)
 
53
from bzrlib.conflicts import Conflict, ConflictList, CONFLICT_SUFFIXES
52
54
import bzrlib.bzrdir as bzrdir
53
55
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
56
import bzrlib.errors as errors
55
57
from bzrlib.errors import (BzrCheckError,
56
58
                           BzrError,
 
59
                           ConflictFormatError,
57
60
                           DivergedBranches,
58
61
                           WeaveRevisionNotPresent,
59
62
                           NotBranchError,
60
63
                           NoSuchFile,
61
64
                           NotVersionedError,
62
 
                           MergeModifiedFormatError)
 
65
                           MergeModifiedFormatError,
 
66
                           UnsupportedOperation,
 
67
                           )
63
68
from bzrlib.inventory import InventoryEntry, Inventory
64
69
from bzrlib.lockable_files import LockableFiles, TransportLock
65
70
from bzrlib.lockdir import LockDir
84
89
                            )
85
90
from bzrlib.progress import DummyProgress, ProgressPhase
86
91
from bzrlib.revision import NULL_REVISION
87
 
from bzrlib.rio import RioReader, RioWriter, Stanza
 
92
from bzrlib.rio import RioReader, rio_file, Stanza
88
93
from bzrlib.symbol_versioning import *
89
94
from bzrlib.textui import show_status
90
95
import bzrlib.tree
234
239
        if deprecated_passed(branch):
235
240
            if not _internal:
236
241
                warn("WorkingTree(..., branch=XXX) is deprecated as of bzr 0.8."
237
 
                     " Please use bzrdir.open_workingtree() or WorkingTree.open().",
 
242
                     " Please use bzrdir.open_workingtree() or"
 
243
                     " WorkingTree.open().",
238
244
                     DeprecationWarning,
239
245
                     stacklevel=2
240
246
                     )
607
613
 
608
614
    @needs_write_lock
609
615
    def set_merge_modified(self, modified_hashes):
610
 
        my_file = StringIO()
611
 
        my_file.write(MERGE_MODIFIED_HEADER_1 + '\n')
612
 
        writer = RioWriter(my_file)
613
 
        for file_id, hash in modified_hashes.iteritems():
614
 
            s = Stanza(file_id=file_id, hash=hash)
615
 
            writer.write_stanza(s)
616
 
        my_file.seek(0)
617
 
        self._control_files.put('merge-hashes', my_file)
 
616
        def iter_stanzas():
 
617
            for file_id, hash in modified_hashes.iteritems():
 
618
                yield Stanza(file_id=file_id, hash=hash)
 
619
        self._put_rio('merge-hashes', iter_stanzas(), MERGE_MODIFIED_HEADER_1)
 
620
 
 
621
    @needs_write_lock
 
622
    def _put_rio(self, filename, stanzas, header):
 
623
        my_file = rio_file(stanzas, header)
 
624
        self._control_files.put(filename, my_file)
618
625
 
619
626
    @needs_read_lock
620
627
    def merge_modified(self):
861
868
            if not self.is_ignored(subp):
862
869
                yield subp
863
870
 
 
871
    @deprecated_method(zero_eight)
864
872
    def iter_conflicts(self):
 
873
        """List all files in the tree that have text or content conflicts.
 
874
        DEPRECATED.  Use conflicts instead."""
 
875
        return self._iter_conflicts()
 
876
 
 
877
    def _iter_conflicts(self):
865
878
        conflicted = set()
866
879
        for path in (s[0] for s in self.list_files()):
867
880
            stem = get_conflicted_stem(path)
1130
1143
    def revert(self, filenames, old_tree=None, backups=True, 
1131
1144
               pb=DummyProgress()):
1132
1145
        from transform import revert
 
1146
        from conflicts import resolve
1133
1147
        if old_tree is None:
1134
1148
            old_tree = self.basis_tree()
1135
1149
        conflicts = revert(self, old_tree, filenames, backups, pb)
1136
1150
        if not len(filenames):
1137
1151
            self.set_pending_merges([])
 
1152
            resolve(self)
 
1153
        else:
 
1154
            resolve(self, filenames, ignore_misses=True)
1138
1155
        return conflicts
1139
1156
 
1140
1157
    @needs_write_lock
1273
1290
        self._set_inventory(inv)
1274
1291
        mutter('wrote working inventory')
1275
1292
 
 
1293
    def set_conflicts(self, arg):
 
1294
        raise UnsupportedOperation(self.set_conflicts, self)
 
1295
 
 
1296
    @needs_read_lock
 
1297
    def conflicts(self):
 
1298
        conflicts = ConflictList()
 
1299
        for conflicted in self._iter_conflicts():
 
1300
            text = True
 
1301
            try:
 
1302
                if file_kind(self.abspath(conflicted)) != "file":
 
1303
                    text = False
 
1304
            except OSError, e:
 
1305
                if e.errno == errno.ENOENT:
 
1306
                    text = False
 
1307
                else:
 
1308
                    raise
 
1309
            if text is True:
 
1310
                for suffix in ('.THIS', '.OTHER'):
 
1311
                    try:
 
1312
                        kind = file_kind(self.abspath(conflicted+suffix))
 
1313
                    except OSError, e:
 
1314
                        if e.errno == errno.ENOENT:
 
1315
                            text = False
 
1316
                            break
 
1317
                        else:
 
1318
                            raise
 
1319
                    if kind != "file":
 
1320
                        text = False
 
1321
                        break
 
1322
            ctype = {True: 'text conflict', False: 'contents conflict'}[text]
 
1323
            conflicts.append(Conflict.factory(ctype, path=conflicted,
 
1324
                             file_id=self.path2id(conflicted)))
 
1325
        return conflicts
 
1326
 
1276
1327
 
1277
1328
class WorkingTree3(WorkingTree):
1278
1329
    """This is the Format 3 working tree.
1308
1359
            self._control_files.put_utf8('last-revision', revision_id)
1309
1360
            return True
1310
1361
 
1311
 
 
1312
 
CONFLICT_SUFFIXES = ('.THIS', '.BASE', '.OTHER')
 
1362
    @needs_write_lock
 
1363
    def set_conflicts(self, conflicts):
 
1364
        self._put_rio('conflicts', conflicts.to_stanzas(), 
 
1365
                      CONFLICT_HEADER_1)
 
1366
 
 
1367
    @needs_read_lock
 
1368
    def conflicts(self):
 
1369
        try:
 
1370
            confile = self._control_files.get('conflicts')
 
1371
        except NoSuchFile:
 
1372
            return ConflictList()
 
1373
        try:
 
1374
            if confile.next() != CONFLICT_HEADER_1 + '\n':
 
1375
                raise ConflictFormatError()
 
1376
        except StopIteration:
 
1377
            raise ConflictFormatError()
 
1378
        return ConflictList.from_stanzas(RioReader(confile))
 
1379
 
 
1380
 
1313
1381
def get_conflicted_stem(path):
1314
1382
    for suffix in CONFLICT_SUFFIXES:
1315
1383
        if path.endswith(suffix):