shithub: libgit

ref: 254e6855efd805fda2826f324169009c8b0a4105
dir: /README/

View raw version

     GIT(2)                                                     GIT(2)

     NAME
          Initgit, gitcommit, gitadd, gitrm, gitlog, Gitlog - git C
          library

     SYNOPSIS
          #include <u.h>
          #include <libc.h>
          #include <git.h>

          typedef struct Gitlog
          {
               char*hash;
               char*author;
               char*date;
               char*message;
          } Gitlog;

          int initgit(char *dir)
          int freegitlogs(Gitlog *logs)

          int gitcommit(char *msg, char *file, ...)
          int gitadd(char *file, ...)
          int gitrm(char *file, ...)
          int gitlog(Gitlog **logs, int n, char *commit, ...)

     DESCRIPTION
          Libgit is a wrapper around git9. It does not provide its own
          git functionality.

          Git functions that receive a list of files expect the last
          element to be nil.  All the file names are expected to be
          relative to the repository root directory.

          Initgit initializes libgit with an existing repository at
          location dir.  This will use git(1) to start the backend
          filesystem.

          Gitadd and gitrm add and remove files from the git file
          tracking system by adjusting the INDEX9 file directly.

          Gitcommit will use git(1) to commit the numbered list of
          files.  Arguments are forwarded unchanged, so it should be
          possible to use wildcards like . or *.  Msg will be used as
          the commit message; it can be multiple lines.

          Gitlog allocates the pointer pointed to by logs with as many
          Gitlog structs as needed, plus an additional sentinel Gitlog
          structure.  It will fill this array with the last n commits
          starting from commit or HEAD if commit is nil.  The remain-
          ing arguments can be a list of files used for filtering,
          ending with nil.

          The last Gitlog structure in the initialized array acts as a
          sentinel and has its hash member set to nil.  The array and
          all its strings are allocated with malloc and should be
          freed after using.

          Freegitlogs can be used for that, which is recommended for
          future updates.

     EXAMPLE
               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);

     SOURCE
          /sys/src/libgit/git.c

     SEE ALSO
          git(1)

     DIAGNOSTICS
          All commands return 1 or 0 and set errstr.

     BUGS
          Sure.

          There should be a collection of functions that receive an
          array of files instead of a va_list.

          Libgit is incomplete.