maggit.io package

This module contains all the low level functions necessary to Maggit to read, write and parse all git files.

Thoses files includes git objects, pack, packedrefs, config, index, ...

Thoses function do not provide high level API. There are mainly intended to be use by Maggit itself.

maggit.io.loose module

maggit.io.loose.commit_parse(content)

Parse a commit content.

Parameters:content (bytes) – The content to parse (without header).
Returns:A tuple (tree, parents, message, author, committer) where:
  • tree is the sha of the tree object of the commit(unhexlified bytes).
  • parents is a list of sha of the parents commit.
  • message is the message of the commit.
  • author is the name (b’name <email> timestamp’) of the author.
  • author is the name (b’name <email> timestamp’) of the committer.
Return type:bytes, list[bytes], bytes, bytes, bytes
maggit.io.loose.object_content(filepath)

Return the content of a loose object.

Parameters:filepath – The path of the loose object.
Returns:A tuple (type, content) where:
  • type is the type of the object.
  • content is the content of the object (without header).
Return type:bytes, bytes
maggit.io.loose.object_rawsha(type_, content)

Generate the raw content and the sha of a object content.

Parameters:
  • type (bytes) – The type of the object.
  • content (bytes) – The content of the object (without header).
Returns:

A tuple (raw, sha) where:

  • raw is the full content of the object (with header).
  • sha is the sha of the object.

Return type:

bytes, bytes

maggit.io.loose.object_sha(type_, content)

Generate the sha of a object content.

Is the bit more performant than object_rawsha(...)[1] as the raw content is not generated.

Parameters:
  • type (bytes) – The type of the object.
  • content (bytes) – The content of the object (without header).
Returns:

The sha of the object.

maggit.io.loose.object_sha_from_raw(raw)

Generate the sha of a object from its content.

Parameters:raw (bytes) – The content of the object (with header)
Returns:The sha of the object.
maggit.io.loose.object_write(filepath, content, compress_level=1)

Correctly create the loose object file.

Parameters:
  • filepath – The path of the loose object to write.
  • content (bytes) – The full content (with header) to write.
  • compress_level (int) – The compression level to use (default=1).
maggit.io.loose.tag_parse(content)

Parse a tag content.

Parameters:content (bytes) – The content to parse (without header).
Returns:A tuple (object, objecttype, tag, tagger, message) where:
  • object is the sha of the tagged object (unhexlified bytes).
  • objecttype is the type of the tagged object.
  • tag is the name of the tag.
  • tagger is the name (b’name <email> timestamp’) of the tagger.
  • message is the message of the tag.
Return type:bytes, bytes, bytes, bytes, bytes
maggit.io.loose.tree_parse(content)

Parse a tree content.

Parameters:content (bytes) – The content to parse (without header).
Returns:A list of (path, (mode, sha)) where :
  • path is the name of the entry.
  • mode is the git mode.
  • sha is the sha of the blob/tree object.
Return type:List[Tuple[bytes, Tuple[bytes, bytes]]]

maggit.io.pack module

class maggit.io.pack.GitPack(packfile, idxfile)

A git pack file.

Parameters:
  • packfile (path) – The path of the packfile.
  • idxfile (GitPackIndex) – The index associated to the pack.
read_object(offset)

Return the content of a object at a offset.

Parameters:offset – The offset to read from.
Returns:A tuple (type, content) where:
  • type is the type of the object.
  • content is the content of the object (without header).
Return type:bytes, bytes
class maggit.io.pack.GitPackIndex(indexfile)

A pack index

Parameters:indexfile (path) – The path of the index file.
get_offset(sha)

Return the offset in the pack associated to the sha.

maggit.io.packedref module

maggit.io.packedref.packed_ref_parse(filename)

Parse a packed ref file.

Parameters:filename (path) – The path of the packed ref.
Returns:A list of (ref, sha, peeledsha) where:
  • ref is name of the ref
  • sha is the associated sha
  • peeledsha is the peeled sha associated to the ref if present. Else None.
Return type:List[Tuple[bytes, bytes, bytes]]