Initial commit
authorSofian Brabez <sbz@6dev.net>
Mon, 13 Jul 2020 22:58:07 +0000 (23:58 +0100)
committerSofian Brabez <sbz@6dev.net>
Mon, 13 Jul 2020 22:58:07 +0000 (23:58 +0100)
Makefile [new file with mode: 0644]
README.md [new file with mode: 0644]
gitlite.c [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..ccdadda
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+PROG=  gitlite
+
+WARNS= 2
+MK_MAN=        no
+MK_DEBUG_FILES=no
+
+SRC=   gitlite.c
+
+CFLAGS=        -I/usr/local/include -L/usr/local/lib -g
+LDFLAGS=-lgit2 -Wl
+
+.include <bsd.prog.mk>
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..d301720
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# gitlite
+
+Experimentation similar to svnlite with libgit2
diff --git a/gitlite.c b/gitlite.c
new file mode 100644 (file)
index 0000000..8ffc3d6
--- /dev/null
+++ b/gitlite.c
@@ -0,0 +1,59 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <git2/global.h>
+#include <git2/clone.h>
+#include <git2/errors.h>
+
+// Compile with:
+// clang90 -o gitlite gitlite.c -lgit2 -I/usr/local/include -L/usr/local/lib -g
+
+void
+git_bail_error(int rc)
+{
+    const git_error *err = NULL;
+
+       if (rc < 0) {
+               err = git_error_last();
+               if (err) 
+            printf("ERROR %d: %s\n", err->klass, err->message);
+               else 
+            printf("ERROR %d: cannot fetch error info\n", rc);
+
+    }
+}
+
+int
+main(int argc, char *argv[])
+{
+       int rc;
+       const char *url = "https://github.com/freebsd/pkg.git";
+       //const char *url = "https://github.com/freebsd/freebsd.git";
+       const char *local_path = "/home/sbz/git/src";
+       git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
+       git_checkout_options co_opts = GIT_CHECKOUT_OPTIONS_INIT;
+       git_repository *cloned_repo = NULL;
+
+       co_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+       co_opts.progress_cb = NULL;
+       co_opts.progress_payload = NULL;
+       clone_opts.checkout_opts = co_opts;
+       clone_opts.fetch_opts.callbacks.sideband_progress = NULL;
+       clone_opts.fetch_opts.callbacks.transfer_progress = NULL;
+       clone_opts.fetch_opts.callbacks.credentials = NULL;
+       clone_opts.fetch_opts.callbacks.payload = NULL;
+
+       rc = git_libgit2_init();
+       git_bail_error(rc);
+
+       rc = git_clone(&cloned_repo, url, local_path, &clone_opts);
+       git_bail_error(rc);
+
+       if (cloned_repo)
+               git_repository_free(cloned_repo);
+
+       rc = git_libgit2_shutdown();
+       git_bail_error(rc);
+
+    return (rc);
+}