Guidedog मैनुअल 0.6.3
भाषा
इस पृष्ठ पर
Guidedog / दस्तावेज़ 0.6.3

git

Package git writes Git objects and sends them with Git’s push protocol, without a git program: object IDs, trees built from a list of files, commits, pack files, and the messages of a receive-pack exchange (the reference advertisement, the update request, and the report). It does no networking itself; a caller sends the request it builds over smart HTTP, or to any receive-pack, and gives the reply back to parse.

It uses only Odin’s core library and zlib. It allocates with context.allocator and frees nothing, so run it in an arena. Failure is an Error value with a message, never a panic. Only SHA-1 repositories, Git’s default, are supported.

Types

git.Advertisement :: struct

Advertisement is what receive-pack offers before an update: its references and capabilities.

refs: []Ref
capabilities: []string
git.Commit :: struct

Commit is a commit’s contents. Its message ends with a line break when it has text.

tree: Id
parents: []Id
author: Person
committer: Person
message: string
git.Error :: struct

Error is what went wrong, for a report; “” is no error.

message: string
git.File :: struct

File is a file a tree holds: its path from the tree’s root, with / between folders, its mode (File or Executable), and its blob’s ID.

path: string
mode: Mode
id: Id
git.Id :: distinct [20]u8

Id is an object’s ID: the SHA-1 of its type, size, and contents.

git.Kind :: enum u8

Kind is the type of an object.

Commit = 1
Tree = 2
Blob = 3
git.Mode :: enum u8

Mode is how a tree lists an entry: a file, an executable file, or a tree.

File
Executable
Tree
git.Pack_Writer :: struct

Pack_Writer writes a pack file: a header, objects compressed with zlib, and the SHA-1 of all that. Begin it with pack_begin, add exactly the number of objects it was begun with, and end it with pack_end; pack_abort closes and removes an unfinished one.

file: ^os.File
path: string
count: int
added: int
hash: sha1.Context
written: i64
git.Person :: struct

Person is an author or committer: a name, an email address, the time in seconds since 1970 (UTC), and the time zone’s offset from UTC in minutes.

name: string
email: string
time: i64
offset: int
git.Ref :: struct

Ref is a reference and the object it names.

name: string
id: Id
git.Ref_Status :: struct

Ref_Status is how receive-pack answered the update of one reference: ok, or why not.

name: string
ok: bool
reason: string
git.Report :: struct

Report is receive-pack’s answer to an update: whether it unpacked the pack, and the status of each reference.

unpacked: bool
unpack: string

receive-pack’s word on unpacking: “ok”, or the error.

refs: []Ref_Status
git.Tree :: struct

Tree is a tree object: the folder it is (“” for the root), its ID, and its contents.

path: string
id: Id
data: []u8

Procedures

git.build_trees :: proc(files: []File) -> (trees: []Tree, err: Error)

build_trees makes the tree objects that hold files: one for each folder, every folder before the folder that holds it, the root last. It refuses an empty list, a path Git does not accept (empty, absolute, with an empty, “.”, “..”, or “.git” part, or a NUL), two files with one path, and a path that is both a file and a folder.

git.commit_bytes :: proc(c: Commit) -> []u8

commit_bytes is the contents of the commit c, as Git writes it.

git.file_id :: proc(path: string) -> (id: Id, size: i64, err: Error)

file_id is the ID of the blob holding the file at path, which is read a chunk at a time, and the file’s size. It fails when the file cannot be read, or changes size while it is.

git.find :: proc(a: Advertisement, name: string) -> (Id, bool)

find is the ID of the reference name, and whether the advertisement lists it.

git.has_capability :: proc(a: Advertisement, capability: string) -> bool

has_capability tells whether the advertisement offers capability.

git.hex :: proc(id: Id) -> string

hex is id in lowercase hexadecimal, allocated with context.allocator.

git.object_id :: proc(kind: Kind, data: []u8) -> Id

object_id is the ID of an object of kind with contents data.

git.pack_abort :: proc(w: ^Pack_Writer)

pack_abort closes and removes an unfinished pack.

git.pack_add :: proc(w: ^Pack_Writer, kind: Kind, data: []u8) -> Error

pack_add adds the object of kind with contents data.

git.pack_add_file :: proc(w: ^Pack_Writer, path: string, size: i64, id: Id) -> Error

pack_add_file adds the blob holding the file at path, which must have size bytes and the ID id: a file that changed since its ID was taken is refused, not packed.

git.pack_begin :: proc(w: ^Pack_Writer, path: string, count: int) -> Error

pack_begin creates the pack file path, which must not exist, for count objects.

git.pack_end :: proc(w: ^Pack_Writer) -> (size: i64, err: Error)

pack_end writes the pack’s checksum and closes it; it fails unless every object pack_begin was given has been added.

git.parse_advertisement :: proc(data: []u8) -> (a: Advertisement, err: Error)

parse_advertisement reads receive-pack’s reference advertisement: as smart HTTP sends it (after a “# service=git-receive-pack” line), or as receive-pack –advertise-refs writes it.

git.parse_id :: proc(text: string) -> (id: Id, ok: bool)

parse_id reads an ID written in 40 hexadecimal digits; false for anything else.

git.parse_report :: proc(data: []u8) -> (r: Report, err: Error)

parse_report reads receive-pack’s report-status answer.

git.valid_path :: proc(path: string) -> bool

valid_path tells whether Git accepts path as a file’s path in a tree.

git.write_request :: proc(path, ref: string, old, new: Id, pack_path, agent: string) -> Error

write_request writes to path, which must not exist, an update request: change ref from old to new (ZERO old creates it), sending the pack at pack_path, and asking for a report. agent names the client, such as “guidedog-pages/0.6.1”.

Constants

git.MAX_ADVERTISEMENT :: 16 * 1024 * 1024

MAX_ADVERTISEMENT bounds the advertisement and the report parse reads.

git.ZERO :: Id{}

ZERO is the ID Git’s protocol uses for a reference that does not exist.