Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added some structs and started in on some of the basic api

  • Loading branch information...
commit 34197fb6abac000a2af7482f4876de45ba33d1f0 1 parent 09c9caf
@schacon authored
View
1  .gitignore
@@ -1 +1,2 @@
.#*
+*.o
View
2  API
@@ -11,8 +11,6 @@ OBJECTS
git_get_object(sha)
- git_type_to_flag(type)
-
git_object_from_sha(sha)
git_get_raw_object(sha1)
View
4 src/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-g -Wall -O3
+CFLAGS=-fPIC -g -c -Wall -O3
all:
- gcc -o testgit git*.c -lm
+ gcc $(CFLAGS) git.c
View
55 src/git.c
@@ -2,39 +2,76 @@
* libGit
*/
-#define LIBGIT_VERSION "0.1"
-
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "git.h"
+struct git_object {
+ char type;
+ int size;
+ char sha[40];
+};
+
+struct git_tree_node {
+ char mode[7];
+ struct git_object *object;
+ char name[255];
+};
+
+struct git_commit_data {
+ char *author_name;
+ int author_date;
+ char *committer_name;
+ int committer_date;
+ struct git_object *tree;
+ struct git_parent *parent;
+ char *message;
+};
+
+struct git_parent {
+ struct git_object *object;
+ struct git_parent *parent;
+};
+
static const char *git_repo_dir;
/*
* sets up git environment for the rest of the methods
*/
-static void git_setup(char *git_directory)
+void git_setup(char *git_directory)
{
git_repo_dir = git_directory;
}
+/*
+ * return git_object struct of object pointed to by sha
+ */
+struct git_object git_get_object(char *sha)
+{
+ struct git_object object;
+ strcpy(object.sha, sha);
+ return object;
+}
+
+char *git_get_contents(struct git_object obj)
+{
+ return "contents";
+}
/*
- * return version
+ * return version of libgit
*/
char *libgit_version()
{
return LIBGIT_VERSION;
}
-
/*
- * libgit test driver
+ * return git repository directory
*/
-int main(int argc, char *argv[])
+const char *get_git_repo_dir()
{
- git_setup(".git");
- fprintf(stderr, "gd: %s\n", git_repo_dir);
+ return git_repo_dir;
}
View
21 src/git.h
@@ -0,0 +1,21 @@
+#define LIBGIT_VERSION "0.1"
+
+#define NULL_SHA = '0000000000000000000000000000000000000000'
+
+#define OBJ_NONE = 0
+#define OBJ_COMMIT = 1
+#define OBJ_TREE = 2
+#define OBJ_BLOB = 3
+#define OBJ_TAG = 4
+#define OBJ_OFS_DELTA = 6
+#define OBJ_REF_DELTA = 7
+
+void git_setup(char *git_directory);
+
+struct git_object git_get_object(char *sha);
+
+char *git_get_contents(struct git_object obj);
+
+char *libgit_version();
+
+const char *get_git_repo_dir();
View
BIN  src/testgit
Binary file not shown
View
4 test/Makefile
@@ -2,7 +2,7 @@ all: build
./test
build: test*.c
- gcc -o test test*.c -lm
+ gcc -o test test*.c ../src/git.o
clean:
- rm test
+ rm test
View
19 test/test_basic.c
@@ -1,26 +1,25 @@
-/* file minunit_example.c */
+/* file minunit_basic.c */
#include <stdio.h>
#include "minunit.h"
+#include "../src/git.h"
int tests_run = 0;
-int foo = 7;
-int bar = 4;
-
-static char * test_foo() {
- mu_assert("error, foo != 7", foo == 7);
+static char * test_git_version() {
+ mu_assert("libGit version not returned", libgit_version() == "0.1");
return 0;
}
-static char * test_bar() {
- mu_assert("error, bar != 5", bar == 5);
+static char * test_git_setup() {
+ git_setup("/tmp/git.git");
+ mu_assert("git setup failed", get_git_repo_dir() == "/tmp/git.git");
return 0;
}
static char * all_tests() {
- mu_run_test(test_foo);
- mu_run_test(test_bar);
+ mu_run_test(test_git_version);
+ mu_run_test(test_git_setup);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.