Permalink
Browse files

initial commit - libGit

  • Loading branch information...
0 parents commit 09c9caf38c61629d5dea5c3bb5c64ec77b0c0616 @schacon committed Aug 20, 2008
Showing with 262 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +100 −0 API
  3. +21 −0 LICENSE
  4. +2 −0 Makefile
  5. +43 −0 README
  6. +4 −0 src/Makefile
  7. +40 −0 src/git.c
  8. 0 src/git.h
  9. BIN src/testgit
  10. +8 −0 test/Makefile
  11. +5 −0 test/minunit.h
  12. +38 −0 test/test_basic.c
1 .gitignore
@@ -0,0 +1 @@
+.#*
100 API
@@ -0,0 +1,100 @@
+BASIC
+
+ git_init(path, bare = false)
+ create_initial_config(bare = false)
+ add_file(name, contents)
+
+ git_setup(path)
+
+
+OBJECTS
+
+ git_get_object(sha)
+
+ git_type_to_flag(type)
+
+ git_object_from_sha(sha)
+
+ git_get_raw_object(sha1)
+
+ git_build_object_list_from_commit(sha)
+
+ git_build_object_list_from_tree(sha)
+
+ git_has_object?(sha1)
+
+ git_legacy_loose_object?(buf)
+
+ git_put_object(type, contents)
+
+
+PACKFILE
+
+ git_build_pack_file
+
+ git_write_pack(bits)
+
+ git_check_delta(sha)
+
+ git_unpack_delta_cached(sha)
+
+ git_unpack_object_header_gently(buf)
+
+ git_put_raw_object(content, type)
+
+ git_unpack_deltified(type, size)
+
+ git_get_data(size)
+
+ git_patch_delta(base, delta)
+
+ git_patch_delta_header_size(delta, pos)
+
+ git_read_pack_header
+
+ git_unpack_all(entries)
+
+ git_unpack_object(number)
+
+ git_unpack_compressed(type, size)
+
+
+SERVER
+
+ git_server_listen
+
+ git_receive_pack(stream)
+
+ git_upload_pack(stream)
+
+ git_write_refs(refs)
+
+ git_read_refs(stream)
+
+ git_refs
+
+ git_read_pack(stream)
+
+ git_packet_read_line
+
+ git_packet_flush
+
+ git_send_nack
+
+ git_send_refs
+
+ git_send_ref(path, sha)
+
+ git_write_server(data)
+
+ git_upload_pack(path)
+
+ git_receive_needs
+
+ git_upload_pack_file
+
+ git_read_header()
+
+ git_read_until_null(debug = false)
+
+
21 LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2008 Scott Chacon
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
2 Makefile
@@ -0,0 +1,2 @@
+test:
+ $(MAKE) -C test/ all
43 README
@@ -0,0 +1,43 @@
+libGit Project
+=======================
+
+Why, oh why would anyone re-implement Git functionality in C? Git is
+already written in C!
+
+There are two reasons for this insanity. The first is that the core
+Git code is GPL'd, which means you can't embed it in any commercial or
+closed source distributed product. We specifically want to do some
+commercial stuff with Git and don't want to fork out to shell calls to
+do it.
+
+The second major reason is that this library does not do any
+command line stuff and never will, so it's not really competing with
+Git for anything. It is a linked library and is meant to be used by
+other programs only. It is being built for an Obj-C program, but should
+be able to be built as bindings for Ruby, Perl or Python (or whatever).
+
+It is not designed to do _everything_ that the core git project can do,
+it is meant to provide object and packfile read and write access and basic
+server functions.
+
+
+Testing libGit
+=========================
+
+ cd test
+ make test
+
+Thats about it. It's a pretty simple testing framework, but it'll do.
+
+
+TODO
+=========================
+
+ Examples : genx
+ Ruby Bindings :
+ http://www.onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html
+
+Authors
+=========================
+
+ * Scott Chacon <schacon@gmail.com>
4 src/Makefile
@@ -0,0 +1,4 @@
+CFLAGS=-g -Wall -O3
+
+all:
+ gcc -o testgit git*.c -lm
40 src/git.c
@@ -0,0 +1,40 @@
+/*
+ * libGit
+ */
+
+#define LIBGIT_VERSION "0.1"
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "git.h"
+
+static const char *git_repo_dir;
+
+/*
+ * sets up git environment for the rest of the methods
+ */
+static void git_setup(char *git_directory)
+{
+ git_repo_dir = git_directory;
+}
+
+
+/*
+ * return version
+ */
+char *libgit_version()
+{
+ return LIBGIT_VERSION;
+}
+
+
+/*
+ * libgit test driver
+ */
+int main(int argc, char *argv[])
+{
+ git_setup(".git");
+ fprintf(stderr, "gd: %s\n", git_repo_dir);
+}
0 src/git.h
No changes.
BIN src/testgit
Binary file not shown.
8 test/Makefile
@@ -0,0 +1,8 @@
+all: build
+ ./test
+
+build: test*.c
+ gcc -o test test*.c -lm
+
+clean:
+ rm test
5 test/minunit.h
@@ -0,0 +1,5 @@
+/* file: minunit.h */
+#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
+#define mu_run_test(test) do { char *message = test(); tests_run++; \
+ if (message) return message; } while (0)
+extern int tests_run;
38 test/test_basic.c
@@ -0,0 +1,38 @@
+/* file minunit_example.c */
+
+#include <stdio.h>
+#include "minunit.h"
+
+int tests_run = 0;
+
+int foo = 7;
+int bar = 4;
+
+static char * test_foo() {
+ mu_assert("error, foo != 7", foo == 7);
+ return 0;
+}
+
+static char * test_bar() {
+ mu_assert("error, bar != 5", bar == 5);
+ return 0;
+}
+
+static char * all_tests() {
+ mu_run_test(test_foo);
+ mu_run_test(test_bar);
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ char *result = all_tests();
+ if (result != 0) {
+ printf("%s\n", result);
+ }
+ else {
+ printf("ALL TESTS PASSED\n");
+ }
+ printf("Tests run: %d\n", tests_run);
+
+ return result != 0;
+}

0 comments on commit 09c9caf

Please sign in to comment.