~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

revert destroys merge-created content auotmatically

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"
32
33
 
33
34
# FIXME: I don't know if writing out the cache from the destructor is really a
34
35
# good idea, because destructors are considered poor taste in Python, and it's
84
85
                            )
85
86
from bzrlib.progress import DummyProgress
86
87
from bzrlib.revision import NULL_REVISION
 
88
from bzrlib.rio import RioReader, RioWriter, Stanza
87
89
from bzrlib.symbol_versioning import *
88
90
from bzrlib.textui import show_status
89
91
import bzrlib.tree
605
607
    def set_pending_merges(self, rev_list):
606
608
        self._control_files.put_utf8('pending-merges', '\n'.join(rev_list))
607
609
 
 
610
    @needs_write_lock
 
611
    def set_merge_modified(self, modified_hashes):
 
612
        my_file = StringIO()
 
613
        my_file.write(MERGE_MODIFIED_HEADER_1 + '\n')
 
614
        writer = RioWriter(my_file)
 
615
        for file_id, hash in modified_hashes.iteritems():
 
616
            s = Stanza(file_id=file_id, hash=hash)
 
617
            writer.write_stanza(s)
 
618
        my_file.seek(0)
 
619
        self._control_files.put('merge-hashes', my_file)
 
620
 
 
621
    @needs_read_lock
 
622
    def merge_modified(self):
 
623
        try:
 
624
            hashfile = self._control_files.get('merge-hashes')
 
625
        except NoSuchFile:
 
626
            return {}
 
627
        merge_hashes = {}
 
628
        try:
 
629
            if hashfile.next() != MERGE_MODIFIED_HEADER_1 + '\n':
 
630
                raise MergeModifiedFormatError()
 
631
        except StopIteration:
 
632
            raise MergeModifiedFormatError()
 
633
        for s in RioReader(hashfile):
 
634
            file_id = s.get("file_id")
 
635
            hash = s.get("hash")
 
636
            if hash == self.get_file_sha1(file_id):
 
637
                merge_hashes[file_id] = hash
 
638
        return merge_hashes
 
639
 
608
640
    def get_symlink_target(self, file_id):
609
641
        return os.readlink(self.id2abspath(file_id))
610
642