~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-22 18:37:26 UTC
  • mfrom: (1551.7.5 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20060622183726-70f1e7cb560cf090
Update StrictTestament support and as_sha1 algorithm, bump bundle version

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)
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."""
186
187
        return r
187
188
 
188
189
    def as_sha1(self):
189
 
        return sha(self.as_short_text()).hexdigest()
 
190
        s = sha()
 
191
        map(s.update, self.as_text_lines())
 
192
        return s.hexdigest()
190
193
 
191
194
 
192
195
class StrictTestament(Testament):
193
196
    """This testament format is for use as a checksum in changesets"""
194
197
 
 
198
    long_header = 'bazaar-ng testament version 2.1\n'
 
199
    short_header = 'bazaar-ng testament short form 2.1\n'
195
200
    def _entry_to_line(self, path, ie):
196
 
        l = ie.revision.decode('utf-8') + ' '
197
 
        l += {True: 'yes', False: 'no'}[ie.executable] + ' '
198
 
        l += Testament._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]
199
204
        return l
200
 
 
201
 
    def as_text_lines(self):
202
 
        lines = ['bazaar-ng testament version 2']
203
 
        lines.extend(Testament.as_text_lines(self)[1:])
204
 
        return lines