1 # objects.py -- Access to base git objects
2 # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
3 # Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; version 2
8 # of the License or (at your option) a later version of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 """Access to base git objects."""
25 from cStringIO import (
33 from dulwich.errors import (
39 ObjectFormatException,
41 from dulwich.file import GitFile
42 from dulwich.misc import (
47 # Header fields for commits
49 _PARENT_HEADER = "parent"
50 _AUTHOR_HEADER = "author"
51 _COMMITTER_HEADER = "committer"
52 _ENCODING_HEADER = "encoding"
55 # Header fields for objects
56 _OBJECT_HEADER = "object"
59 _TAGGER_HEADER = "tagger"
65 return (stat.S_IFMT(m) == S_IFGITLINK)
68 def _decompress(string):
69 dcomp = zlib.decompressobj()
70 dcomped = dcomp.decompress(string)
71 dcomped += dcomp.flush()
76 """Takes a string and returns the hex of the sha within"""
77 hexsha = binascii.hexlify(sha)
78 assert len(hexsha) == 40, "Incorrect length of sha1 string: %d" % hexsha
83 """Takes a hex sha and returns a binary sha"""
84 assert len(hex) == 40, "Incorrent length of hexsha: %s" % hex
85 return binascii.unhexlify(hex)
88 def hex_to_filename(path, hex):
89 """Takes a hex sha and returns its filename relative to the given path."""
92 # Check from object dir
93 return os.path.join(path, dir, file)
96 def filename_to_hex(filename):
97 """Takes an object filename and returns its corresponding hex sha."""
98 # grab the last (up to) two path components
99 names = filename.rsplit(os.path.sep, 2)[-2:]
100 errmsg = "Invalid object filename: %s" % filename
101 assert len(names) == 2, errmsg
103 assert len(base) == 2 and len(rest) == 38, errmsg
109 def object_header(num_type, length):
110 """Return an object header for the given numeric type and text length."""
111 return "%s %d\0" % (object_class(num_type).type_name, length)
114 def serializable_property(name, docstring=None):
117 setattr(obj, "_"+name, value)
118 obj._needs_serialization = True
121 return getattr(obj, "_"+name)
122 return property(get, set, doc=docstring)
125 def object_class(type):
126 """Get the object class corresponding to the given type.
128 :param type: Either a type name string or a numeric type.
129 :return: The ShaFile subclass corresponding to the given type, or None if
130 type is not a valid type name/number.
132 return _TYPE_MAP.get(type, None)
135 def check_hexsha(hex, error_msg):
138 except (TypeError, AssertionError):
139 raise ObjectFormatException("%s %s" % (error_msg, hex))
142 def check_identity(identity, error_msg):
143 email_start = identity.find("<")
144 email_end = identity.find(">")
145 if (email_start < 0 or email_end < 0 or email_end <= email_start
146 or identity.find("<", email_start + 1) >= 0
147 or identity.find(">", email_end + 1) >= 0
148 or not identity.endswith(">")):
149 raise ObjectFormatException(error_msg)
152 class FixedSha(object):
153 """SHA object that behaves like hashlib's but is given a fixed value."""
155 def __init__(self, hexsha):
156 self._hexsha = hexsha
157 self._sha = hex_to_sha(hexsha)
166 class ShaFile(object):
167 """A git SHA file."""
170 def _parse_legacy_object_header(magic, f):
171 """Parse a legacy object, creating it but not reading the file."""
173 decomp = zlib.decompressobj()
174 header = decomp.decompress(magic)
178 header += decomp.decompress(f.read(bufsize))
179 end = header.find("\0", start)
181 header = header[:end]
182 type_name, size = header.split(" ", 1)
183 size = int(size) # sanity check
184 obj_class = object_class(type_name)
186 raise ObjectFormatException("Not a known type: %s" % type_name)
188 obj._filename = f.name
191 def _parse_legacy_object(self, f):
192 """Parse a legacy object, setting the raw string."""
193 size = os.path.getsize(f.name)
194 map = mmap.mmap(f.fileno(), size, access=mmap.ACCESS_READ)
196 text = _decompress(map)
199 header_end = text.find('\0')
201 raise ObjectFormatException("Invalid object header")
202 self.set_raw_string(text[header_end+1:])
204 def as_legacy_object_chunks(self):
205 compobj = zlib.compressobj()
206 yield compobj.compress(self._header())
207 for chunk in self.as_raw_chunks():
208 yield compobj.compress(chunk)
209 yield compobj.flush()
211 def as_legacy_object(self):
212 return "".join(self.as_legacy_object_chunks())
214 def as_raw_chunks(self):
215 if self._needs_parsing:
216 self._ensure_parsed()
217 elif self._needs_serialization:
218 self._chunked_text = self._serialize()
219 return self._chunked_text
221 def as_raw_string(self):
222 return "".join(self.as_raw_chunks())
225 return self.as_raw_string()
230 def as_pretty_string(self):
231 return self.as_raw_string()
233 def _ensure_parsed(self):
234 if self._needs_parsing:
235 if not self._chunked_text:
236 assert self._filename, "ShaFile needs either text or filename"
238 self._deserialize(self._chunked_text)
239 self._needs_parsing = False
241 def set_raw_string(self, text):
242 if type(text) != str:
243 raise TypeError(text)
244 self.set_raw_chunks([text])
246 def set_raw_chunks(self, chunks):
247 self._chunked_text = chunks
248 self._deserialize(chunks)
250 self._needs_parsing = False
251 self._needs_serialization = False
254 def _parse_object_header(magic, f):
255 """Parse a new style object, creating it but not reading the file."""
256 num_type = (ord(magic[0]) >> 4) & 7
257 obj_class = object_class(num_type)
259 raise ObjectFormatException("Not a known type: %d" % num_type)
261 obj._filename = f.name
264 def _parse_object(self, f):
265 """Parse a new style object, setting self._text."""
266 size = os.path.getsize(f.name)
267 map = mmap.mmap(f.fileno(), size, access=mmap.ACCESS_READ)
269 # skip type and size; type must have already been determined, and we
270 # trust zlib to fail if it's otherwise corrupted
273 while (byte & 0x80) != 0:
274 byte = ord(map[used])
277 self.set_raw_string(_decompress(raw))
282 def _is_legacy_object(cls, magic):
283 b0, b1 = map(ord, magic)
284 word = (b0 << 8) + b1
285 return b0 == 0x78 and (word % 31) == 0
288 def _parse_file_header(cls, f):
290 if cls._is_legacy_object(magic):
291 return cls._parse_legacy_object_header(magic, f)
293 return cls._parse_object_header(magic, f)
296 """Don't call this directly"""
298 self._filename = None
299 self._chunked_text = []
300 self._needs_parsing = False
301 self._needs_serialization = True
303 def _deserialize(self, chunks):
304 raise NotImplementedError(self._deserialize)
306 def _serialize(self):
307 raise NotImplementedError(self._serialize)
309 def _parse_file(self):
310 f = GitFile(self._filename, 'rb')
313 if self._is_legacy_object(magic):
314 self._parse_legacy_object(f)
316 self._parse_object(f)
321 def from_path(cls, path):
322 f = GitFile(path, 'rb')
324 obj = cls.from_file(f)
325 obj._sha = FixedSha(filename_to_hex(path))
331 def from_file(cls, f):
332 """Get the contents of a SHA file on disk."""
334 obj = cls._parse_file_header(f)
336 obj._needs_parsing = True
337 obj._needs_serialization = True
339 except (IndexError, ValueError), e:
340 raise ObjectFormatException("invalid object header")
343 def from_raw_string(type_num, string):
344 """Creates an object of the indicated type from the raw string given.
346 :param type_num: The numeric type of the object.
347 :param string: The raw uncompressed contents.
349 obj = object_class(type_num)()
350 obj.set_raw_string(string)
354 def from_raw_chunks(type_num, chunks):
355 """Creates an object of the indicated type from the raw chunks given.
357 :param type_num: The numeric type of the object.
358 :param chunks: An iterable of the raw uncompressed contents.
360 obj = object_class(type_num)()
361 obj.set_raw_chunks(chunks)
365 def from_string(cls, string):
366 """Create a ShaFile from a string."""
368 obj.set_raw_string(string)
371 def _check_has_member(self, member, error_msg):
372 """Check that the object has a given member variable.
374 :param member: the member variable to check for
375 :param error_msg: the message for an error if the member is missing
376 :raise ObjectFormatException: with the given error_msg if member is
379 if getattr(self, member, None) is None:
380 raise ObjectFormatException(error_msg)
383 """Check this object for internal consistency.
385 :raise ObjectFormatException: if the object is malformed in some way
386 :raise ChecksumMismatch: if the object was created with a SHA that does
387 not match its contents
389 # TODO: if we find that error-checking during object parsing is a
390 # performance bottleneck, those checks should be moved to the class's
391 # check() method during optimization so we can still check the object
395 self._deserialize(self.as_raw_chunks())
399 raise ObjectFormatException(e)
400 if old_sha != new_sha:
401 raise ChecksumMismatch(new_sha, old_sha)
404 return object_header(self.type, self.raw_length())
406 def raw_length(self):
407 """Returns the length of the raw string of this object."""
409 for chunk in self.as_raw_chunks():
415 ret.update(self._header())
416 for chunk in self.as_raw_chunks():
421 """The SHA1 object that is the name of this object."""
422 if self._sha is None:
423 # this is a local because as_raw_chunks() overwrites self._sha
425 new_sha.update(self._header())
426 for chunk in self.as_raw_chunks():
427 new_sha.update(chunk)
433 return self.sha().hexdigest()
438 def set_type(self, type):
441 # DEPRECATED: use type_num or type_name as needed.
442 type = property(get_type, set_type)
445 return "<%s %s>" % (self.__class__.__name__, self.id)
447 def __ne__(self, other):
448 return self.id != other.id
450 def __eq__(self, other):
451 """Return true if the sha of the two objects match.
453 The __le__ etc methods aren't overriden as they make no sense,
454 certainly at this level.
456 return self.id == other.id
460 """A Git Blob object."""
466 super(Blob, self).__init__()
467 self._chunked_text = []
468 self._needs_parsing = False
469 self._needs_serialization = False
472 return self.as_raw_string()
474 def _set_data(self, data):
475 self.set_raw_string(data)
477 data = property(_get_data, _set_data,
478 "The text contained within the blob object.")
480 def _get_chunked(self):
481 self._ensure_parsed()
482 return self._chunked_text
484 def _set_chunked(self, chunks):
485 self._chunked_text = chunks
487 def _serialize(self):
488 if not self._chunked_text:
489 self._ensure_parsed()
490 self._needs_serialization = False
491 return self._chunked_text
493 def _deserialize(self, chunks):
494 self._chunked_text = chunks
496 chunked = property(_get_chunked, _set_chunked,
497 "The text within the blob object, as chunks (not necessarily lines).")
500 def from_path(cls, path):
501 blob = ShaFile.from_path(path)
502 if not isinstance(blob, cls):
503 raise NotBlobError(path)
507 """Check this object for internal consistency.
509 :raise ObjectFormatException: if the object is malformed in some way
511 super(Blob, self).check()
514 def _parse_tag_or_commit(text):
515 """Parse tag or commit text.
517 :param text: the raw text of the tag or commit object.
518 :yield: tuples of (field, value), one per header line, in the order read
519 from the text, possibly including duplicates. Includes a field named
520 None for the freeform tag/commit text.
526 # Empty line indicates end of headers
528 yield l.split(" ", 1)
529 yield (None, f.read())
534 return _parse_tag_or_commit(text)
538 """A Git Tag object."""
544 super(Tag, self).__init__()
545 self._tag_timezone_neg_utc = False
548 def from_path(cls, filename):
549 tag = ShaFile.from_path(filename)
550 if not isinstance(tag, cls):
551 raise NotTagError(filename)
555 """Check this object for internal consistency.
557 :raise ObjectFormatException: if the object is malformed in some way
559 super(Tag, self).check()
560 self._check_has_member("_object_sha", "missing object sha")
561 self._check_has_member("_object_class", "missing object type")
562 self._check_has_member("_name", "missing tag name")
565 raise ObjectFormatException("empty tag name")
567 check_hexsha(self._object_sha, "invalid object sha")
569 if getattr(self, "_tagger", None):
570 check_identity(self._tagger, "invalid tagger")
573 for field, _ in parse_tag("".join(self._chunked_text)):
574 if field == _OBJECT_HEADER and last is not None:
575 raise ObjectFormatException("unexpected object")
576 elif field == _TYPE_HEADER and last != _OBJECT_HEADER:
577 raise ObjectFormatException("unexpected type")
578 elif field == _TAG_HEADER and last != _TYPE_HEADER:
579 raise ObjectFormatException("unexpected tag name")
580 elif field == _TAGGER_HEADER and last != _TAG_HEADER:
581 raise ObjectFormatException("unexpected tagger")
584 def _serialize(self):
586 chunks.append("%s %s\n" % (_OBJECT_HEADER, self._object_sha))
587 chunks.append("%s %s\n" % (_TYPE_HEADER, self._object_class.type_name))
588 chunks.append("%s %s\n" % (_TAG_HEADER, self._name))
590 if self._tag_time is None:
591 chunks.append("%s %s\n" % (_TAGGER_HEADER, self._tagger))
593 chunks.append("%s %s %d %s\n" % (
594 _TAGGER_HEADER, self._tagger, self._tag_time,
595 format_timezone(self._tag_timezone,
596 self._tag_timezone_neg_utc)))
597 chunks.append("\n") # To close headers
598 chunks.append(self._message)
601 def _deserialize(self, chunks):
602 """Grab the metadata attached to the tag"""
604 for field, value in parse_tag("".join(chunks)):
605 if field == _OBJECT_HEADER:
606 self._object_sha = value
607 elif field == _TYPE_HEADER:
608 obj_class = object_class(value)
610 raise ObjectFormatException("Not a known type: %s" % value)
611 self._object_class = obj_class
612 elif field == _TAG_HEADER:
614 elif field == _TAGGER_HEADER:
616 sep = value.index("> ")
619 self._tag_time = None
620 self._tag_timezone = None
621 self._tag_timezone_neg_utc = False
623 self._tagger = value[0:sep+1]
625 (timetext, timezonetext) = value[sep+2:].rsplit(" ", 1)
626 self._tag_time = int(timetext)
627 self._tag_timezone, self._tag_timezone_neg_utc = \
628 parse_timezone(timezonetext)
629 except ValueError, e:
630 raise ObjectFormatException(e)
632 self._message = value
634 raise ObjectFormatException("Unknown field %s" % field)
636 def _get_object(self):
637 """Get the object pointed to by this tag.
639 :return: tuple of (object class, sha).
641 self._ensure_parsed()
642 return (self._object_class, self._object_sha)
644 def _set_object(self, value):
645 self._ensure_parsed()
646 (self._object_class, self._object_sha) = value
647 self._needs_serialization = True
649 object = property(_get_object, _set_object)
651 name = serializable_property("name", "The name of this tag")
652 tagger = serializable_property("tagger",
653 "Returns the name of the person who created this tag")
654 tag_time = serializable_property("tag_time",
655 "The creation timestamp of the tag. As the number of seconds since the epoch")
656 tag_timezone = serializable_property("tag_timezone",
657 "The timezone that tag_time is in.")
658 message = serializable_property("message", "The message attached to this tag")
661 def parse_tree(text):
662 """Parse a tree text.
664 :param text: Serialized text to parse
665 :yields: tuples of (name, mode, sha)
670 mode_end = text.index(' ', count)
671 mode = int(text[count:mode_end], 8)
672 name_end = text.index('\0', mode_end)
673 name = text[mode_end+1:name_end]
675 sha = text[name_end+1:count]
676 yield (name, mode, sha_to_hex(sha))
679 def serialize_tree(items):
680 """Serialize the items in a tree to a text.
682 :param items: Sorted iterable over (name, mode, sha) tuples
683 :return: Serialized tree text as chunks
685 for name, mode, hexsha in items:
686 yield "%04o %s\0%s" % (mode, name, hex_to_sha(hexsha))
689 def sorted_tree_items(entries):
690 """Iterate over a tree entries dictionary in the order in which
691 the items would be serialized.
693 :param entries: Dictionary mapping names to (mode, sha) tuples
694 :return: Iterator over (name, mode, sha)
696 for name, entry in sorted(entries.iteritems(), cmp=cmp_entry):
697 yield name, entry[0], entry[1]
700 def cmp_entry((name1, value1), (name2, value2)):
701 """Compare two tree entries."""
702 if stat.S_ISDIR(value1[0]):
704 if stat.S_ISDIR(value2[0]):
706 return cmp(name1, name2)
710 """A Git tree object"""
716 super(Tree, self).__init__()
720 def from_path(cls, filename):
721 tree = ShaFile.from_path(filename)
722 if not isinstance(tree, cls):
723 raise NotTreeError(filename)
726 def __contains__(self, name):
727 self._ensure_parsed()
728 return name in self._entries
730 def __getitem__(self, name):
731 self._ensure_parsed()
732 return self._entries[name]
734 def __setitem__(self, name, value):
735 assert isinstance(value, tuple)
736 assert len(value) == 2
737 self._ensure_parsed()
738 self._entries[name] = value
739 self._needs_serialization = True
741 def __delitem__(self, name):
742 self._ensure_parsed()
743 del self._entries[name]
744 self._needs_serialization = True
747 self._ensure_parsed()
748 return len(self._entries)
751 self._ensure_parsed()
752 return iter(self._entries)
754 def add(self, mode, name, hexsha):
755 assert type(mode) == int
756 assert type(name) == str
757 assert type(hexsha) == str
758 self._ensure_parsed()
759 self._entries[name] = mode, hexsha
760 self._needs_serialization = True
763 """Return a list of tuples describing the tree entries"""
764 self._ensure_parsed()
765 # The order of this is different from iteritems() for historical
768 (mode, name, hexsha) for (name, mode, hexsha) in self.iteritems()]
771 """Iterate over entries in the order in which they would be serialized.
773 :return: Iterator over (name, mode, sha) tuples
775 self._ensure_parsed()
776 return sorted_tree_items(self._entries)
778 def _deserialize(self, chunks):
779 """Grab the entries in the tree"""
781 parsed_entries = parse_tree("".join(chunks))
782 except ValueError, e:
783 raise ObjectFormatException(e)
784 # TODO: list comprehension is for efficiency in the common (small) case;
785 # if memory efficiency in the large case is a concern, use a genexp.
786 self._entries = dict([(n, (m, s)) for n, m, s in parsed_entries])
789 """Check this object for internal consistency.
791 :raise ObjectFormatException: if the object is malformed in some way
793 super(Tree, self).check()
795 allowed_modes = (stat.S_IFREG | 0755, stat.S_IFREG | 0644,
796 stat.S_IFLNK, stat.S_IFDIR, S_IFGITLINK,
797 # TODO: optionally exclude as in git fsck --strict
799 for name, mode, sha in parse_tree("".join(self._chunked_text)):
800 check_hexsha(sha, 'invalid sha %s' % sha)
801 if '/' in name or name in ('', '.', '..'):
802 raise ObjectFormatException('invalid name %s' % name)
804 if mode not in allowed_modes:
805 raise ObjectFormatException('invalid mode %06o' % mode)
807 entry = (name, (mode, sha))
809 if cmp_entry(last, entry) > 0:
810 raise ObjectFormatException('entries not sorted')
812 raise ObjectFormatException('duplicate entry %s' % name)
815 def _serialize(self):
816 return list(serialize_tree(self.iteritems()))
818 def as_pretty_string(self):
820 for name, mode, hexsha in self.iteritems():
821 if mode & stat.S_IFDIR:
825 text.append("%04o %s %s\t%s\n" % (mode, kind, hexsha, name))
829 def parse_timezone(text):
831 negative_utc = (offset == 0 and text[0] == '-')
832 signum = (offset < 0) and -1 or 1
834 hours = int(offset / 100)
835 minutes = (offset % 100)
836 return signum * (hours * 3600 + minutes * 60), negative_utc
839 def format_timezone(offset, negative_utc=False):
841 raise ValueError("Unable to handle non-minute offset.")
842 if offset < 0 or (offset == 0 and negative_utc):
847 return '%c%02d%02d' % (sign, offset / 3600, (offset / 60) % 60)
850 def parse_commit(text):
851 return _parse_tag_or_commit(text)
854 class Commit(ShaFile):
855 """A git commit object"""
861 super(Commit, self).__init__()
863 self._encoding = None
865 self._author_timezone_neg_utc = False
866 self._commit_timezone_neg_utc = False
869 def from_path(cls, path):
870 commit = ShaFile.from_path(path)
871 if not isinstance(commit, cls):
872 raise NotCommitError(path)
875 def _deserialize(self, chunks):
879 for field, value in parse_commit("".join(self._chunked_text)):
880 if field == _TREE_HEADER:
882 elif field == _PARENT_HEADER:
883 self._parents.append(value)
884 elif field == _AUTHOR_HEADER:
885 self._author, timetext, timezonetext = value.rsplit(" ", 2)
886 self._author_time = int(timetext)
887 self._author_timezone, self._author_timezone_neg_utc =\
888 parse_timezone(timezonetext)
889 elif field == _COMMITTER_HEADER:
890 self._committer, timetext, timezonetext = value.rsplit(" ", 2)
891 self._commit_time = int(timetext)
892 self._commit_timezone, self._commit_timezone_neg_utc =\
893 parse_timezone(timezonetext)
894 elif field == _ENCODING_HEADER:
895 self._encoding = value
897 self._message = value
899 self._extra.append((field, value))
902 """Check this object for internal consistency.
904 :raise ObjectFormatException: if the object is malformed in some way
906 super(Commit, self).check()
907 self._check_has_member("_tree", "missing tree")
908 self._check_has_member("_author", "missing author")
909 self._check_has_member("_committer", "missing committer")
910 # times are currently checked when set
912 for parent in self._parents:
913 check_hexsha(parent, "invalid parent sha")
914 check_hexsha(self._tree, "invalid tree sha")
916 check_identity(self._author, "invalid author")
917 check_identity(self._committer, "invalid committer")
920 for field, _ in parse_commit("".join(self._chunked_text)):
921 if field == _TREE_HEADER and last is not None:
922 raise ObjectFormatException("unexpected tree")
923 elif field == _PARENT_HEADER and last not in (_PARENT_HEADER,
925 raise ObjectFormatException("unexpected parent")
926 elif field == _AUTHOR_HEADER and last not in (_TREE_HEADER,
928 raise ObjectFormatException("unexpected author")
929 elif field == _COMMITTER_HEADER and last != _AUTHOR_HEADER:
930 raise ObjectFormatException("unexpected committer")
931 elif field == _ENCODING_HEADER and last != _COMMITTER_HEADER:
932 raise ObjectFormatException("unexpected encoding")
935 # TODO: optionally check for duplicate parents
937 def _serialize(self):
939 chunks.append("%s %s\n" % (_TREE_HEADER, self._tree))
940 for p in self._parents:
941 chunks.append("%s %s\n" % (_PARENT_HEADER, p))
942 chunks.append("%s %s %s %s\n" % (
943 _AUTHOR_HEADER, self._author, str(self._author_time),
944 format_timezone(self._author_timezone,
945 self._author_timezone_neg_utc)))
946 chunks.append("%s %s %s %s\n" % (
947 _COMMITTER_HEADER, self._committer, str(self._commit_time),
948 format_timezone(self._commit_timezone,
949 self._commit_timezone_neg_utc)))
951 chunks.append("%s %s\n" % (_ENCODING_HEADER, self.encoding))
952 for k, v in self.extra:
953 if "\n" in k or "\n" in v:
954 raise AssertionError("newline in extra data: %r -> %r" % (k, v))
955 chunks.append("%s %s\n" % (k, v))
956 chunks.append("\n") # There must be a new line after the headers
957 chunks.append(self._message)
960 tree = serializable_property("tree", "Tree that is the state of this commit")
962 def _get_parents(self):
963 """Return a list of parents of this commit."""
964 self._ensure_parsed()
967 def _set_parents(self, value):
968 """Set a list of parents of this commit."""
969 self._ensure_parsed()
970 self._needs_serialization = True
971 self._parents = value
973 parents = property(_get_parents, _set_parents)
975 def _get_extra(self):
976 """Return extra settings of this commit."""
977 self._ensure_parsed()
980 extra = property(_get_extra)
982 author = serializable_property("author",
983 "The name of the author of the commit")
985 committer = serializable_property("committer",
986 "The name of the committer of the commit")
988 message = serializable_property("message",
989 "The commit message")
991 commit_time = serializable_property("commit_time",
992 "The timestamp of the commit. As the number of seconds since the epoch.")
994 commit_timezone = serializable_property("commit_timezone",
995 "The zone the commit time is in")
997 author_time = serializable_property("author_time",
998 "The timestamp the commit was written. as the number of seconds since the epoch.")
1000 author_timezone = serializable_property("author_timezone",
1001 "Returns the zone the author time is in.")
1003 encoding = serializable_property("encoding",
1004 "Encoding of the commit message.")
1016 for cls in OBJECT_CLASSES:
1017 _TYPE_MAP[cls.type_name] = cls
1018 _TYPE_MAP[cls.type_num] = cls
1022 # Hold on to the pure-python implementations for testing
1023 _parse_tree_py = parse_tree
1024 _sorted_tree_items_py = sorted_tree_items
1026 # Try to import C versions
1027 from dulwich._objects import parse_tree, sorted_tree_items