218
230
shafile._text = string
233
def _parse_text(self):
234
"""Grab the metadata attached to the tag"""
237
assert text.startswith(OBJECT_ID), "Invalid tag object, " \
238
"must start with %s" % OBJECT_ID
239
count += len(OBJECT_ID)
240
assert text[count] == ' ', "Invalid tag object, " \
241
"%s must be followed by space not %s" % (OBJECT_ID, text[count])
243
self._object_sha = text[count:count+40]
245
assert text[count] == '\n', "Invalid tag object, " \
246
"%s sha must be followed by newline" % OBJECT_ID
248
assert text[count:].startswith(TYPE_ID), "Invalid tag object, " \
249
"%s sha must be followed by %s" % (OBJECT_ID, TYPE_ID)
250
count += len(TYPE_ID)
251
assert text[count] == ' ', "Invalid tag object, " \
252
"%s must be followed by space not %s" % (TAG_ID, text[count])
254
self._object_type = ""
255
while text[count] != '\n':
256
self._object_type += text[count]
259
assert self._object_type in (COMMIT_ID, BLOB_ID, TREE_ID, TAG_ID), "Invalid tag object, " \
260
"unexpected object type %s" % self._object_type
261
self._object_type = type_map[self._object_type]
263
assert text[count:].startswith(TAG_ID), "Invalid tag object, " \
264
"object type must be followed by %s" % (TAG_ID)
266
assert text[count] == ' ', "Invalid tag object, " \
267
"%s must be followed by space not %s" % (TAG_ID, text[count])
270
while text[count] != '\n':
271
self._name += text[count]
275
assert text[count:].startswith(TAGGER_ID), "Invalid tag object, " \
276
"%s must be followed by %s" % (TAG_ID, TAGGER_ID)
277
count += len(TAGGER_ID)
278
assert text[count] == ' ', "Invalid tag object, " \
279
"%s must be followed by space not %s" % (TAGGER_ID, text[count])
282
while text[count] != '>':
283
assert text[count] != '\n', "Malformed tagger information"
284
self._tagger += text[count]
286
self._tagger += text[count]
288
assert text[count] == ' ', "Invalid tag object, " \
289
"tagger information must be followed by space not %s" % text[count]
291
self._tag_time = int(text[count:count+10])
292
while text[count] != '\n':
295
assert text[count] == '\n', "There must be a new line after the headers"
297
self._message = text[count:]
301
"""Returns the object pointed by this tag, represented as a tuple(type, sha)"""
302
return (self._object_type, self._object_sha)
306
"""Returns the name of this tag"""
311
"""Returns the name of the person who created this tag"""
316
"""Returns the creation timestamp of the tag.
318
Returns it as the number of seconds since the epoch"""
319
return self._tag_time
323
"""Returns the message attached to this tag"""
222
327
class Tree(ShaFile):
223
328
"""A Git tree object"""
228
337
def from_file(cls, filename):
258
369
chr = self._text[count]
259
370
sha = self._text[count:count+20]
260
371
hexsha = sha_to_hex(sha)
261
self._entries.append((mode, name, hexsha))
372
self.add(mode, name, hexsha)
262
373
count = count + 20
377
for mode, name, hexsha in self._entries:
378
self._text += "%04o %s\0%s" % (mode, name, hex_to_sha(hexsha))
264
381
class Commit(ShaFile):
265
382
"""A git commit object"""
267
384
_type = COMMIT_ID
270
391
def from_file(cls, filename):
339
460
# XXX: There can be an encoding field.
340
461
self._message = text[count:]
465
self._text += "%s %s\n" % (TREE_ID, self._tree)
466
for p in self._parents:
467
self._text += "%s %s\n" % (PARENT_ID, p)
468
self._text += "%s %s %s +0000\n" % (AUTHOR_ID, self._author, str(self._commit_time))
469
self._text += "%s %s %s +0000\n" % (COMMITTER_ID, self._committer, str(self._commit_time))
470
self._text += "\n" # There must be a new line after the headers
471
self._text += self._message
344
475
"""Returns the tree that is the state of this commit"""