def as_text_lines(self): """Yield text form as a sequence of lines. The result is returned in utf-8, because it should be signed or hashed in that encoding. """ r = [] a = r.append a(self.long_header) a('revision-id: %s\n' % self.revision_id) a('committer: %s\n' % self.committer) a('timestamp: %d\n' % self.timestamp) a('timezone: %d\n' % self.timezone) # inventory length contains the root, which is not shown here a('parents:\n') for parent_id in sorted(self.parent_ids): if contains_whitespace(parent_id): raise ValueError(parent_id) a(' %s\n' % parent_id) a('message:\n') for l in self.message.splitlines(): a(' %s\n' % l) a('inventory:\n') for path, ie in self._get_entries(): a(self._entry_to_line(path, ie)) r.extend(self._revprops_to_lines()) return [line.encode('utf-8') for line in r]
def _check_properties(self): """Verify that all revision properties are OK.""" for name, value in self.properties.iteritems(): if not isinstance(name, basestring) or contains_whitespace(name): raise ValueError("invalid property name %r" % name) if not isinstance(value, basestring): raise ValueError("invalid property value %r for %r" % (name, value))
def _check_properties(self): """Verify that all revision properties are OK.""" for name, value in self.properties.iteritems(): if not isinstance(name, basestring) or contains_whitespace(name): raise ValueError("invalid property name %r" % name) if not isinstance(value, basestring): raise ValueError("invalid property value %r for %r" % (value, name))
def _revprops_to_lines(self): """Pack up revision properties.""" if not self.revprops: return [] r = ['properties:\n'] for name, value in sorted(self.revprops.items()): if contains_whitespace(name): raise ValueError(name) r.append(' %s:\n' % name) for line in value.splitlines(): r.append(u' %s\n' % line) return r
def __init__(self, rev, inventory): """Create a new testament for rev using inventory.""" self.revision_id = rev.revision_id self.committer = rev.committer self.timezone = rev.timezone or 0 self.timestamp = rev.timestamp self.message = rev.message self.parent_ids = rev.parent_ids[:] self.inventory = inventory self.revprops = copy(rev.properties) if contains_whitespace(self.revision_id): raise ValueError(self.revision_id) if contains_linebreaks(self.committer): raise ValueError(self.committer)
def __init__(self, rev, tree): """Create a new testament for rev using tree.""" self.revision_id = rev.revision_id self.committer = rev.committer self.timezone = rev.timezone or 0 self.timestamp = rev.timestamp self.message = rev.message self.parent_ids = rev.parent_ids[:] if not isinstance(tree, Tree): raise TypeError("As of bzr 2.4 Testament.__init__() takes a " "Revision and a Tree.") self.tree = tree self.revprops = copy(rev.properties) if contains_whitespace(self.revision_id): raise ValueError(self.revision_id) if contains_linebreaks(self.committer): raise ValueError(self.committer)
def _entry_to_line(self, path, ie): """Turn an inventory entry into a testament line""" if contains_whitespace(ie.file_id): raise ValueError(ie.file_id) content = '' content_spacer = '' if ie.kind == 'file': # TODO: avoid switching on kind if not ie.text_sha1: raise AssertionError() content = ie.text_sha1 content_spacer = ' ' elif ie.kind == 'symlink': if not ie.symlink_target: raise AssertionError() content = self._escape_path(ie.symlink_target) content_spacer = ' ' l = u' %s %s %s%s%s\n' % (ie.kind, self._escape_path(path), ie.file_id.decode('utf8'), content_spacer, content) return l
def _entry_to_line(self, path, ie): """Turn an inventory entry into a testament line""" if contains_whitespace(ie.file_id): raise ValueError(ie.file_id) content = '' content_spacer='' if ie.kind == 'file': # TODO: avoid switching on kind if not ie.text_sha1: raise AssertionError() content = ie.text_sha1 content_spacer = ' ' elif ie.kind == 'symlink': if not ie.symlink_target: raise AssertionError() content = self._escape_path(ie.symlink_target) content_spacer = ' ' l = u' %s %s %s%s%s\n' % (ie.kind, self._escape_path(path), ie.file_id.decode('utf8'), content_spacer, content) return l