~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Robert Collins
  • Date: 2005-10-18 23:47:12 UTC
  • mfrom: (0.2.1)
  • Revision ID: robertc@robertcollins.net-20051018234712-45a83974f691c860
Bugfix the new pull --clobber to not generate spurious conflicts.

When --clobber clobbered the history, a bad merge base was used.

Supporting this:
* merge.merge_inner now has tempdir as an optional parameter. (Robert Collins)

* Tree.kind is not recorded at the top level of the hierarchy, as it was
  missing on EmptyTree, leading to a bug with merge on EmptyTrees.
  (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
# TODO: Perhaps these should just be different formats in which inventories/
70
70
# revisions can be serialized.
71
71
 
 
72
from copy import copy
72
73
from cStringIO import StringIO
73
74
import string
74
75
from sha import sha
89
90
    @classmethod
90
91
    def from_revision(cls, branch, revision_id):
91
92
        """Produce a new testament from a historical revision"""
92
 
        t = cls()
93
93
        rev = branch.get_revision(revision_id)
94
 
        t.revision_id = str(revision_id)
95
 
        t.committer = rev.committer
96
 
        t.timezone = rev.timezone or 0
97
 
        t.timestamp = rev.timestamp
98
 
        t.message = rev.message
99
 
        t.parent_ids = rev.parent_ids[:]
100
 
        t.inventory = branch.get_inventory(revision_id)
101
 
        assert not contains_whitespace(t.revision_id)
102
 
        assert not contains_linebreaks(t.committer)
103
 
        return t
 
94
        inventory = branch.get_inventory(revision_id)
 
95
        return cls(rev, inventory)
 
96
 
 
97
    def __init__(self, rev, inventory):
 
98
        """Create a new testament for rev using inventory."""
 
99
        self.revision_id = str(rev.revision_id)
 
100
        self.committer = rev.committer
 
101
        self.timezone = rev.timezone or 0
 
102
        self.timestamp = rev.timestamp
 
103
        self.message = rev.message
 
104
        self.parent_ids = rev.parent_ids[:]
 
105
        self.inventory = inventory
 
106
        self.revprops = copy(rev.properties)
 
107
        assert not contains_whitespace(self.revision_id)
 
108
        assert not contains_linebreaks(self.committer)
104
109
 
105
110
    def as_text_lines(self):
106
111
        """Yield text form as a sequence of lines.
127
132
        a('inventory:\n')
128
133
        for path, ie in self.inventory.iter_entries():
129
134
            a(self._entry_to_line(path, ie))
 
135
        r.extend(self._revprops_to_lines())
130
136
        if __debug__:
131
137
            for l in r:
132
 
                assert isinstance(l, str), \
 
138
                assert isinstance(l, basestring), \
133
139
                    '%r of type %s is not a plain string' % (l, type(l))
134
140
        return r
135
141
 
165
171
                'sha1: %s\n'
166
172
                % (self.revision_id, s.hexdigest()))
167
173
 
 
174
    def _revprops_to_lines(self):
 
175
        """Pack up revision properties."""
 
176
        if not self.revprops:
 
177
            return []
 
178
        r = ['properties:\n']
 
179
        for name, value in sorted(self.revprops.items()):
 
180
            assert isinstance(name, str)
 
181
            assert not contains_whitespace(name)
 
182
            r.append('  %s:\n' % name)
 
183
            for line in value.splitlines():
 
184
                if not isinstance(line, str):
 
185
                    line = line.encode('utf-8')
 
186
                r.append('    %s\n' % line)
 
187
        return r