~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Jamie Wilkinson
  • Date: 2006-07-18 23:59:52 UTC
  • mfrom: (1868 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1874.
  • Revision ID: jaq@spacepants.org-20060718235952-1e362401a7858958
merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
      - compared to a revision
88
88
    """
89
89
 
 
90
    long_header = 'bazaar-ng testament version 1\n'
 
91
    short_header = 'bazaar-ng testament short form 1\n'
 
92
 
90
93
    @classmethod
91
94
    def from_revision(cls, repository, revision_id):
92
95
        """Produce a new testament from a historical revision"""
115
118
        """
116
119
        r = []
117
120
        a = r.append
118
 
        a('bazaar-ng testament version 1\n')
 
121
        a(self.long_header)
119
122
        a('revision-id: %s\n' % self.revision_id)
120
123
        a('committer: %s\n' % self.committer)
121
124
        a('timestamp: %d\n' % self.timestamp)
156
159
            assert ie.symlink_target
157
160
            l += ' ' + self._escape_path(ie.symlink_target)
158
161
        l += '\n'
159
 
        return l
 
162
        return l.decode('utf-8')
160
163
 
161
164
    def as_text(self):
162
165
        return ''.join(self.as_text_lines())
163
166
 
164
167
    def as_short_text(self):
165
168
        """Return short digest-based testament."""
166
 
        s = sha()
167
 
        map(s.update, self.as_text_lines())
168
 
        return ('bazaar-ng testament short form 1\n'
 
169
        return (self.short_header + 
169
170
                'revision-id: %s\n'
170
171
                'sha1: %s\n'
171
 
                % (self.revision_id, s.hexdigest()))
 
172
                % (self.revision_id, self.as_sha1()))
172
173
 
173
174
    def _revprops_to_lines(self):
174
175
        """Pack up revision properties."""
184
185
                    line = line.encode('utf-8')
185
186
                r.append('    %s\n' % line)
186
187
        return r
 
188
 
 
189
    def as_sha1(self):
 
190
        s = sha()
 
191
        map(s.update, self.as_text_lines())
 
192
        return s.hexdigest()
 
193
 
 
194
 
 
195
class StrictTestament(Testament):
 
196
    """This testament format is for use as a checksum in changesets"""
 
197
 
 
198
    long_header = 'bazaar-ng testament version 2.1\n'
 
199
    short_header = 'bazaar-ng testament short form 2.1\n'
 
200
    def _entry_to_line(self, path, ie):
 
201
        l = Testament._entry_to_line(self, path, ie)[:-1]
 
202
        l += ' ' + ie.revision.decode('utf-8')
 
203
        l += {True: ' yes\n', False: ' no\n'}[ie.executable]
 
204
        return l