def check(self): """Check this object for internal consistency. Raises: ObjectFormatException: if the object is malformed in some way """ super(Tree, self).check() last = None allowed_modes = ( stat.S_IFREG | 0o755, stat.S_IFREG | 0o644, stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK, # TODO: optionally exclude as in git fsck --strict stat.S_IFREG | 0o664, ) for name, mode, sha in parse_tree(b"".join(self._chunked_text), True): check_hexsha(sha, "invalid sha %s" % sha) if b"/" in name or name in (b"", b".", b"..", b".git"): raise ObjectFormatException("invalid name %s" % name.decode("utf-8", "replace")) if mode not in allowed_modes: raise ObjectFormatException("invalid mode %06o" % mode) entry = (name, (mode, sha)) if last: if key_entry(last) > key_entry(entry): raise ObjectFormatException("entries not sorted") if name == last[0]: raise ObjectFormatException("duplicate entry %s" % name) last = entry
def check(self): """Check this object for internal consistency. :raise ObjectFormatException: if the object is malformed in some way """ super(Tree, self).check() last = None allowed_modes = (stat.S_IFREG | 0755, stat.S_IFREG | 0644, stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK, # TODO: optionally exclude as in git fsck --strict stat.S_IFREG | 0664) for name, mode, sha in parse_tree(''.join(self._chunked_text), True): check_hexsha(sha, 'invalid sha %s' % sha) if '/' in name or name in ('', '.', '..'): raise ObjectFormatException('invalid name %s' % name) if mode not in allowed_modes: raise ObjectFormatException('invalid mode %06o' % mode) entry = (name, (mode, sha)) if last: if cmp_entry(last, entry) > 0: raise ObjectFormatException('entries not sorted') if name == last[0]: raise ObjectFormatException('duplicate entry %s' % name) last = entry
def check(self): """Check this object for internal consistency. :raise ObjectFormatException: if the object is malformed in some way """ super(Tree, self).check() last = None allowed_modes = ( stat.S_IFREG | 0755, stat.S_IFREG | 0644, stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK, # TODO: optionally exclude as in git fsck --strict stat.S_IFREG | 0664) for name, mode, sha in parse_tree(''.join(self._chunked_text), True): check_hexsha(sha, 'invalid sha %s' % sha) if '/' in name or name in ('', '.', '..'): raise ObjectFormatException('invalid name %s' % name) if mode not in allowed_modes: raise ObjectFormatException('invalid mode %06o' % mode) entry = (name, (mode, sha)) if last: if cmp_entry(last, entry) > 0: raise ObjectFormatException('entries not sorted') if name == last[0]: raise ObjectFormatException('duplicate entry %s' % name) last = entry
def check(self): """Check this object for internal consistency. :raise ObjectFormatException: if the object is malformed in some way """ super(Tree, self).check() last = None allowed_modes = ( stat.S_IFREG | 0o755, stat.S_IFREG | 0o644, stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK, # TODO: optionally exclude as in git fsck --strict stat.S_IFREG | 0o664, ) for name, mode, sha in parse_tree(b"".join(self._chunked_text), True): check_hexsha(sha, "invalid sha %s" % sha) if b"/" in name or name in (b"", b".", b".."): raise ObjectFormatException("invalid name %s" % name) if mode not in allowed_modes: raise ObjectFormatException("invalid mode %06o" % mode) entry = (name, (mode, sha)) if last: if key_entry(last) > key_entry(entry): raise ObjectFormatException("entries not sorted") if name == last[0]: raise ObjectFormatException("duplicate entry %s" % name) last = entry
def _deserialize(self, chunks): """Grab the entries in the tree""" try: parsed_entries = parse_tree(b''.join(chunks)) except ValueError as e: raise ObjectFormatException(e) # TODO: list comprehension is for efficiency in the common (small) # case; if memory efficiency in the large case is a concern, use a genexp. self._entries = dict([(n, (m, s)) for n, m, s in parsed_entries])
def _deserialize(self, chunks): """Grab the entries in the tree""" try: parsed_entries = parse_tree("".join(chunks)) except ValueError, e: raise ObjectFormatException(e)
def _parse_text(self): """Grab the entries in the tree""" self._entries = parse_tree(self._text) self._needs_parsing = False