ref: 254e6855efd805fda2826f324169009c8b0a4105
dir: /git.2/
.TH GIT 2 .SH NAME Initgit, gitcommit, gitadd, gitrm, gitlog, Gitlog \- git C library .SH SYNOPSIS .ft L .nf #include <u.h> #include <libc.h> #include <git.h> .fi .PP .ft L .nf .ta \w'\fLFile 'u typedef struct Gitlog { char *hash; char *author; char *date; char *message; } Gitlog; .fi .PP .ft L .nf .ta \w'\fLint 'u +4n +4n int initgit(char *dir) int freegitlogs(Gitlog *logs) .fi .PP .ft L .nf .ta \w'\fLint 'u +4n +4n int gitcommit(char *msg, char *file, ...) int gitadd(char *file, ...) int gitrm(char *file, ...) int gitlog(Gitlog **logs, int n, char *commit, ...) .fi .SH DESCRIPTION .I Libgit is a wrapper around git9. It does .I not provide its own git functionality. .PP Git functions that receive a list of files expect the last element to be .BR nil . All the file names are expected to be relative to the repository root directory. .PP .B Initgit initializes libgit with an existing repository at location .BR dir . This will use .IR git (1) to start the backend filesystem. .PP .B Gitadd and .B gitrm add and remove files from the git file tracking system by adjusting the .I INDEX9 file directly. .PP .B Gitcommit will use .IR git (1) to commit the numbered list of files. Arguments are forwarded unchanged, so it should be possible to use wildcards like .B . or .BR * . .B Msg will be used as the commit message; it can be multiple lines. .PP .B Gitlog allocates the pointer pointed to by .B logs with as many .B Gitlog structs as needed, plus an additional sentinel Gitlog structure. It will fill this array with the last .B n commits starting from .B commit or .I HEAD if .B commit is .BR nil . The remaining arguments can be a list of files used for filtering, ending with .BR nil . .PP The last .B Gitlog structure in the initialized array acts as a sentinel and has its .B hash member set to .BR nil . The array and all its strings are allocated with .B malloc and should be freed after using. .PP .B Freegitlogs can be used for that, which is recommended for future updates. .SH EXAMPLE .IP .EX Gitlogs *logs; if (!initgit("/path/to/repo")) sysfatal("%r"); gitadd("addfileA", "addfileB", nil); gitrm("rmfileA", "rmfileB", nil); gitcommit("adds and removes files\\n\\nfor demonstration only", "addfileA", "addfileB", "rmfileA", "rmfileB", nil); gitlog(&logs, 2, nil, nil); for (Gitlog *l = logs; l->hash; l++) { print("hash: %s\\n", l->hash); print("author: %s\\n", l->author); print("date: %s\\n", l->date); print("msg: %s\\n", l->message); } freegitlogs(logs); .EE .SH SOURCE .B /sys/src/libgit/git.c .SH SEE ALSO .IR git (1) .SH DIAGNOSTICS All commands return 1 or 0 and set errstr. .SH BUGS Sure. .PP There should be a collection of functions that receive an array of files instead of a .BR va_list . .PP .I Libgit is incomplete.