~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/testament.py

  • Committer: Michael Ellerman
  • Date: 2006-02-28 14:45:51 UTC
  • mto: (1558.1.18 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: michael@ellerman.id.au-20060228144551-3d9941ecde4a0b0a
Update contrib/pwk for -p1 diffs from bzr

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
 
 
93
90
    @classmethod
94
91
    def from_revision(cls, repository, revision_id):
95
92
        """Produce a new testament from a historical revision"""
118
115
        """
119
116
        r = []
120
117
        a = r.append
121
 
        a(self.long_header)
 
118
        a('bazaar-ng testament version 1\n')
122
119
        a('revision-id: %s\n' % self.revision_id)
123
120
        a('committer: %s\n' % self.committer)
124
121
        a('timestamp: %d\n' % self.timestamp)
159
156
            assert ie.symlink_target
160
157
            l += ' ' + self._escape_path(ie.symlink_target)
161
158
        l += '\n'
162
 
        return l.decode('utf-8')
 
159
        return l
163
160
 
164
161
    def as_text(self):
165
162
        return ''.join(self.as_text_lines())
166
163
 
167
164
    def as_short_text(self):
168
165
        """Return short digest-based testament."""
169
 
        return (self.short_header + 
 
166
        s = sha()
 
167
        map(s.update, self.as_text_lines())
 
168
        return ('bazaar-ng testament short form 1\n'
170
169
                'revision-id: %s\n'
171
170
                'sha1: %s\n'
172
 
                % (self.revision_id, self.as_sha1()))
 
171
                % (self.revision_id, s.hexdigest()))
173
172
 
174
173
    def _revprops_to_lines(self):
175
174
        """Pack up revision properties."""
185
184
                    line = line.encode('utf-8')
186
185
                r.append('    %s\n' % line)
187
186
        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