~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to prepare_shelf.py

  • Committer: Aaron Bentley
  • Date: 2008-10-05 19:10:42 UTC
  • mto: (0.15.1 unshelve)
  • mto: This revision was merged to the branch mainline in revision 3820.
  • Revision ID: aaron@aaronbentley.com-20081005191042-go1c5kln21yw47ie
Implement shelving content

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
from cStringIO import StringIO
 
19
 
 
20
from bzrlib import merge3
18
21
from bzrlib import transform
19
22
 
20
23
 
34
37
            if names[0] != names[1] or parents[0] != parents[1]:
35
38
                self.renames[file_id] = (names, parents)
36
39
                yield ('rename', file_id) + paths
 
40
            if changed:
 
41
                yield ('modify text', file_id)
37
42
 
38
43
    def shelve_rename(self, file_id):
39
44
        names, parents = self.renames[file_id]
45
50
        shelf_parent = self.shelf_transform.trans_id_file_id(parents[1])
46
51
        self.shelf_transform.adjust_path(names[1], shelf_parent, s_trans_id)
47
52
 
 
53
    def shelve_text(self, file_id, new_text):
 
54
        s = StringIO()
 
55
        s.writelines(new_text)
 
56
        s.seek(0)
 
57
        new_lines = s.readlines()
 
58
        w_trans_id = self.work_transform.trans_id_file_id(file_id)
 
59
        self.work_transform.delete_contents(w_trans_id)
 
60
        self.work_transform.create_file(new_lines, w_trans_id)
 
61
 
 
62
        s_trans_id = self.shelf_transform.trans_id_file_id(file_id)
 
63
        self.shelf_transform.delete_contents(s_trans_id)
 
64
        inverse_lines = self._inverse_lines(new_lines, file_id)
 
65
        self.shelf_transform.create_file(inverse_lines, s_trans_id)
 
66
 
 
67
    def _inverse_lines(self, new_lines, file_id):
 
68
        """Produce a version with only those changes removed from new_lines."""
 
69
        base_lines = self.base_tree.get_file_lines(file_id)
 
70
        tree_file = self.work_tree.get_file(file_id)
 
71
        try:
 
72
            tree_lines = tree_file.readlines()
 
73
        finally:
 
74
            tree_file.close()
 
75
        return merge3.Merge3(new_lines, base_lines, tree_lines).merge_lines()
 
76
 
48
77
    def finalize(self):
49
78
        self.work_transform.finalize()
50
79
        self.shelf_transform.finalize()
 
80
 
 
81
    def transform(self):
 
82
        self.work_transform.apply()