From 6fd195d76c7f52baae5540e287affe2259900d36 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Nov 2010 18:42:42 +0200 Subject: [PATCH] Change git_repository initialization to use a path The constructor to git_repository is now called 'git_repository_open(path)' and takes a path to a git repository instead of an existing ODB object. Unit tests have been updated accordingly and the two test repositories have been merged into one. Signed-off-by: Vicent Marti --- src/fileops.c | 7 ++ src/fileops.h | 1 + src/git/index.h | 50 ++++++++- src/git/repository.h | 33 +++++- src/index.c | 18 +++- src/index.h | 27 +---- src/repository.c | 101 ++++++++++++++++-- src/repository.h | 9 ++ tests/resources/pack-odb/info/packs | Bin 54 -> 0 bytes tests/resources/testrepo.git/HEAD | Bin tests/resources/{ => testrepo.git}/index | Bin .../13/85f264afb75a56a5bec74243be9b367ba4ca08 | Bin .../18/1037049a54a1eb5fab404658a3a250b44335d7 | Bin .../18/10dff58d8a660512d4832e740f692884338ccd | Bin .../45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 | Bin .../4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 | Bin .../5b/5b025afb0b4c913b4c338a42934a3863bf3644 | Bin .../75/057dd4114e74cca1d750d0aee1647c903cb60a | Bin .../7b/4384978d2493e851f9cca7858815fac9b10980 | Bin .../81/4889a078c031f61ed08ab5fa863aea9314344d | Bin .../84/96071c1b46c854b31185ea97743be6a8774479 | Bin .../9f/d738e8f7967c078dceed8190330fc8648ee56a | Bin .../a4/a7dce85cf63874e984719f4fdd239f5145052f | Bin .../a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd | Bin .../a8/233120f6ad708f843d861ce2b7228ec4e3dec6 | Bin .../b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 | Bin .../be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 | Bin .../c4/7800c7266a2be04c571c04d5a6614691ea99bd | Bin .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin .../f6/0079018b664e4e79329a7ef9559c8d9e0378d1 | Bin .../fa/49b077972391ad58037050f2a75f74e3671e92 | Bin .../fd/093bff70906175335656e6ce6ae05783708765 | Bin ...1e489679b7d3418f9ab594bda8ceb37dd4c695.idx | Bin ...e489679b7d3418f9ab594bda8ceb37dd4c695.pack | Bin ...c6adf9f61318f041845b01440d09aa7a91e1b5.idx | Bin ...6adf9f61318f041845b01440d09aa7a91e1b5.pack | Bin ...5f5d483273108c9d8dd0e4728ccf0b2982423a.idx | Bin ...f5d483273108c9d8dd0e4728ccf0b2982423a.pack | Bin tests/t0204-readpack.c | 2 - tests/t0205-readheader.c | 7 +- tests/t0401-parse.c | 9 +- tests/t0402-details.c | 8 +- tests/t0403-write.c | 18 +--- tests/t0501-walk.c | 7 +- tests/t0601-read.c | 12 +-- tests/t0602-write.c | 4 +- tests/t0603-sort.c | 4 +- tests/t0801-readtag.c | 7 +- tests/t0802-write.c | 9 +- tests/t0901-readtree.c | 14 +-- tests/t0902-modify.c | 20 +--- tests/test_helpers.c | 19 ++-- tests/test_helpers.h | 2 + 53 files changed, 247 insertions(+), 141 deletions(-) delete mode 100644 tests/resources/pack-odb/info/packs create mode 100644 tests/resources/testrepo.git/HEAD rename tests/resources/{ => testrepo.git}/index (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/13/85f264afb75a56a5bec74243be9b367ba4ca08 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/18/1037049a54a1eb5fab404658a3a250b44335d7 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/18/10dff58d8a660512d4832e740f692884338ccd (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/5b/5b025afb0b4c913b4c338a42934a3863bf3644 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/75/057dd4114e74cca1d750d0aee1647c903cb60a (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/7b/4384978d2493e851f9cca7858815fac9b10980 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/81/4889a078c031f61ed08ab5fa863aea9314344d (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/84/96071c1b46c854b31185ea97743be6a8774479 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/9f/d738e8f7967c078dceed8190330fc8648ee56a (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/a4/a7dce85cf63874e984719f4fdd239f5145052f (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/c4/7800c7266a2be04c571c04d5a6614691ea99bd (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/fa/49b077972391ad58037050f2a75f74e3671e92 (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/fd/093bff70906175335656e6ce6ae05783708765 (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx (100%) rename tests/resources/{sample-odb => testrepo.git/objects}/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx (100%) rename tests/resources/{pack-odb => testrepo.git/objects}/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack (100%) diff --git a/src/fileops.c b/src/fileops.c index f101cec32..e0a5ff461 100644 --- a/src/fileops.c +++ b/src/fileops.c @@ -53,6 +53,13 @@ int gitfo_write(git_file fd, void *buf, size_t cnt) return GIT_SUCCESS; } +int gitfo_isdir(const char *path) +{ + struct stat st; + return (path && gitfo_stat(path, &st) == 0 && S_ISDIR(st.st_mode)) ? + GIT_SUCCESS : GIT_ENOTFOUND; +} + int gitfo_exists(const char *path) { return access(path, F_OK); diff --git a/src/fileops.h b/src/fileops.h index 2da4231d0..618bddd5b 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -57,6 +57,7 @@ typedef struct { /* file io buffer */ extern int gitfo_exists(const char *path); extern int gitfo_open(const char *path, int flags); extern int gitfo_creat(const char *path, int mode); +extern int gitfo_isdir(const char *path); #define gitfo_close(fd) close(fd) extern int gitfo_read(git_file fd, void *buf, size_t cnt); diff --git a/src/git/index.h b/src/git/index.h index 46fccbd74..3b262355e 100644 --- a/src/git/index.h +++ b/src/git/index.h @@ -1,6 +1,7 @@ #ifndef INCLUDE_git_index_h__ #define INCLUDE_git_index_h__ +#include #include "common.h" #include "oid.h" @@ -16,18 +17,50 @@ GIT_BEGIN_DECL /** Memory representation of an index file. */ typedef struct git_index git_index; + +/** Time used in a git index entry */ +typedef struct { + uint32_t seconds; + uint32_t nanoseconds; +} git_index_time; + /** Memory representation of a file entry in the index. */ -typedef struct git_index_entry git_index_entry; +typedef struct git_index_entry { + git_index_time ctime; + git_index_time mtime; + + uint32_t dev; + uint32_t ino; + uint32_t mode; + uint32_t uid; + uint32_t gid; + uint32_t file_size; + + git_oid oid; + + uint16_t flags; + uint16_t flags_extended; + + char *path; +} git_index_entry; /** * Create a new Git index object as a memory representation * of the Git index file in 'index_path'. * + * The argument 'working_dir' is the root path of the indexed + * files in the index and is used to calculate the relative path + * when inserting new entries from existing files on disk. + * + * If 'working _dir' is NULL (e.g for bare repositories), the + * methods working on on-disk files will fail. + * * @param index_path the path to the index file in disk + * @param working_dir working dir for the git repository * @return the index object; NULL if the index could not be created */ -GIT_EXTERN(git_index *) git_index_alloc(const char *index_path); +GIT_EXTERN(git_index *) git_index_alloc(const char *index_path, const char *working_dir); /** * Clear the contents (all the entries) of an index object. @@ -83,6 +116,19 @@ GIT_EXTERN(int) git_index_find(git_index *index, const char *path); */ GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); +/** + * Get a pointer to one of the entries in the index + * + * This entry can be modified, and the changes will be written + * back to disk on the next write() call. + * + * @param index an existing index object + * @param n the position of the entry + * @return a pointer to the entry; NULL if out of bounds + */ +GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, int n); + + /** @} */ GIT_END_DECL #endif diff --git a/src/git/repository.h b/src/git/repository.h index 0a50fe1ef..058849b7f 100644 --- a/src/git/repository.h +++ b/src/git/repository.h @@ -4,6 +4,7 @@ #include "common.h" #include "odb.h" #include "commit.h" +#include "index.h" /** * @file git/repository.h @@ -15,15 +16,28 @@ GIT_BEGIN_DECL /** - * Allocate a new repository object. + * Open a git repository. * - * TODO: specify the repository's path instead - * of its object database + * The 'path' argument must point to an existing git repository + * folder, e.g. * - * @param odb an existing object database to back the repo + * /path/to/my_repo/.git/ (normal repository) + * objects/ + * index + * HEAD + * + * /path/to/bare_repo/ (bare repository) + * objects/ + * index + * HEAD + * + * The method will automatically detect if 'path' is a normal + * or bare repository or fail is 'path' is neither. + * + * @param path the path to the repository * @return the new repository handle; NULL on error */ -GIT_EXTERN(git_repository *) git_repository_alloc(git_odb *odb); +GIT_EXTERN(git_repository *) git_repository_open(const char *path); /** @@ -57,6 +71,15 @@ GIT_EXTERN(git_object *) git_repository_lookup(git_repository *repo, const git_o */ GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo); +/** + * Get the Index file of a Git repository + * + * @param repo a repository object + * @return a pointer to the Index object; + * NULL if the index cannot be opened + */ +GIT_EXTERN(git_index *) git_repository_index(git_repository *rpeo); + /** * Create a new in-memory repository object with * the given type. diff --git a/src/index.c b/src/index.c index 991f1b126..9996c50fe 100644 --- a/src/index.c +++ b/src/index.c @@ -97,7 +97,7 @@ static int read_tree(git_index *index, const char *buffer, size_t buffer_size); static git_index_tree *read_tree_internal(const char **, const char *, git_index_tree *); -git_index *git_index_alloc(const char *index_path) +git_index *git_index_alloc(const char *index_path, const char *work_dir) { git_index *index; @@ -116,6 +116,9 @@ git_index *git_index_alloc(const char *index_path) return NULL; } + if (work_dir != NULL) + index->working_path = git__strdup(work_dir); + /* Check if index file is stored on disk already */ if (gitfo_exists(index->index_file_path) == 0) index->on_disk = 1; @@ -126,6 +129,9 @@ git_index *git_index_alloc(const char *index_path) void git_index_clear(git_index *index) { unsigned int i; + + assert(index); + for (i = 0; i < index->entry_count; ++i) free(index->entries[i].path); @@ -139,6 +145,9 @@ void git_index_clear(git_index *index) void git_index_free(git_index *index) { + if (index == NULL) + return; + git_index_clear(index); free(index->entries); index->entries = NULL; @@ -213,6 +222,11 @@ int git_index_write(git_index *index) return 0; } +git_index_entry *git_index_get(git_index *index, int n) +{ + return (n >= 0 && (unsigned int)n < index->entry_count) ? &index->entries[n] : NULL; +} + int git_index_add(git_index *index, const char *filename, int stage) { git_index_entry entry; @@ -225,7 +239,7 @@ int git_index_add(git_index *index, const char *filename, int stage) if (path_length < GIT_IDXENTRY_NAMEMASK) entry.flags |= path_length; else - entry.flags |= path_length; + entry.flags |= GIT_IDXENTRY_NAMEMASK;; if (stage < 0 || stage > 3) return GIT_ERROR; diff --git a/src/index.h b/src/index.h index 44da78f9b..6a3c11e82 100644 --- a/src/index.h +++ b/src/index.h @@ -12,31 +12,6 @@ #define GIT_IDXENTRY_VALID (0x8000) #define GIT_IDXENTRY_STAGESHIFT 12 -typedef struct { - uint32_t seconds; - uint32_t nanoseconds; -} git_index_time; - -struct git_index_entry { - git_index_time ctime; - git_index_time mtime; - - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t file_size; - - git_oid oid; - - uint16_t flags; - uint16_t flags_extended; - - char *path; -}; - - struct git_index_tree { char *name; @@ -53,6 +28,8 @@ typedef struct git_index_tree git_index_tree; struct git_index { char *index_file_path; + char *working_path; + time_t last_modified; git_index_entry *entries; diff --git a/src/repository.c b/src/repository.c index fe7b870fe..433e72916 100644 --- a/src/repository.c +++ b/src/repository.c @@ -28,6 +28,7 @@ #include "repository.h" #include "commit.h" #include "tag.h" +#include "fileops.h" static const int default_table_size = 32; static const double max_load_factor = 0.65; @@ -43,7 +44,7 @@ static const size_t object_sizes[] = { }; -uint32_t git_object_hash(const void *key) +uint32_t git__objtable_hash(const void *key) { uint32_t r; git_oid *id; @@ -53,7 +54,7 @@ uint32_t git_object_hash(const void *key) return r; } -int git_object_haskey(void *object, const void *key) +int git__objtable_haskey(void *object, const void *key) { git_object *obj; git_oid *oid; @@ -64,7 +65,62 @@ int git_object_haskey(void *object, const void *key) return (git_oid_cmp(oid, &obj->id) == 0); } -git_repository *git_repository_alloc(git_odb *odb) +static int parse_repository_folders(git_repository *repo, const char *repository_path) +{ + char path_aux[GIT_PATH_MAX]; + int path_len, i; + + if (gitfo_isdir(repository_path) < 0) + return GIT_ERROR; + + path_len = strlen(repository_path); + strcpy(path_aux, repository_path); + + if (path_aux[path_len - 1] != '/') { + path_aux[path_len] = '/'; + path_aux[path_len + 1] = 0; + + path_len = path_len + 1; + } + + repo->path_repository = git__strdup(path_aux); + + /* objects database */ + strcpy(path_aux + path_len, "objects/"); + if (gitfo_isdir(path_aux) < 0) + return GIT_ERROR; + repo->path_odb = git__strdup(path_aux); + + /* index file */ + strcpy(path_aux + path_len, "index"); + if (gitfo_exists(path_aux) < 0) + return GIT_ERROR; + repo->path_index = git__strdup(path_aux); + + /* HEAD file */ + strcpy(path_aux + path_len, "HEAD"); + if (gitfo_exists(path_aux) < 0) + return GIT_ERROR; + + i = path_len - 2; + while (path_aux[i] != '/') + i--; + + if (strcmp(path_aux, "/.git/") == 0) { + repo->is_bare = 0; + + path_aux[i + 1] = 0; + repo->path_workdir = git__strdup(path_aux); + + } else { + repo->is_bare = 1; + repo->path_workdir = NULL; + } + + return GIT_SUCCESS; +} + +git_repository *git_repository__alloc() { git_repository *repo = git__malloc(sizeof(git_repository)); if (!repo) @@ -74,15 +130,30 @@ git_repository *git_repository_alloc(git_odb *odb) repo->objects = git_hashtable_alloc( default_table_size, - git_object_hash, - git_object_haskey); + git__objtable_hash, + git__objtable_haskey); if (repo->objects == NULL) { free(repo); return NULL; } - repo->db = odb; /* TODO: create ODB manually! */ + return repo; +} + +git_repository *git_repository_open(const char *path) +{ + git_repository *repo; + + repo = git_repository__alloc(); + if (repo == NULL) + return NULL; + + if (parse_repository_folders(repo, path) < 0 || + git_odb_open(&repo->db, repo->path_odb) < 0) { + git_repository_free(repo); + return NULL; + } return repo; } @@ -92,6 +163,11 @@ void git_repository_free(git_repository *repo) git_hashtable_iterator it; git_object *object; + free(repo->path_workdir); + free(repo->path_index); + free(repo->path_repository); + free(repo->path_odb); + git_hashtable_iterator_init(repo->objects, &it); while ((object = (git_object *) @@ -99,10 +175,21 @@ void git_repository_free(git_repository *repo) git_object_free(object); git_hashtable_free(repo->objects); - /* TODO: free odb */ + git_odb_close(repo->db); + git_index_free(repo->index); free(repo); } +git_index *git_repository_index(git_repository *repo) +{ + if (repo->index == NULL) { + repo->index = git_index_alloc(repo->path_index, repo->path_workdir); + assert(repo->index && repo->index->on_disk); + } + + return repo->index; +} + static int source_resize(git_odb_source *src) { size_t write_offset, new_size; diff --git a/src/repository.h b/src/repository.h index 0ccfc5e92..ca76d4558 100644 --- a/src/repository.h +++ b/src/repository.h @@ -7,6 +7,7 @@ #include "git/repository.h" #include "hashtable.h" +#include "index.h" typedef struct { git_rawobj raw; @@ -24,7 +25,15 @@ struct git_object { struct git_repository { git_odb *db; + git_index *index; git_hashtable *objects; + + char *path_repository; + char *path_index; + char *path_odb; + char *path_workdir; + + unsigned is_bare:1; }; diff --git a/tests/resources/pack-odb/info/packs b/tests/resources/pack-odb/info/packs deleted file mode 100644 index 895b1c3b3e757cd2762a9620790be54f5780b34a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 54 zcmWGgC`e4s)=jZ6O*2g~u`o6=H#Rh|NVZI|NJ%kBH8D4`NKQ^ONHVgtFfuVRPSgXb H=HdbXpCb;r diff --git a/tests/resources/testrepo.git/HEAD b/tests/resources/testrepo.git/HEAD new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/resources/index b/tests/resources/testrepo.git/index similarity index 100% rename from tests/resources/index rename to tests/resources/testrepo.git/index diff --git a/tests/resources/sample-odb/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 similarity index 100% rename from tests/resources/sample-odb/13/85f264afb75a56a5bec74243be9b367ba4ca08 rename to tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 diff --git a/tests/resources/sample-odb/18/1037049a54a1eb5fab404658a3a250b44335d7 b/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 similarity index 100% rename from tests/resources/sample-odb/18/1037049a54a1eb5fab404658a3a250b44335d7 rename to tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 diff --git a/tests/resources/sample-odb/18/10dff58d8a660512d4832e740f692884338ccd b/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd similarity index 100% rename from tests/resources/sample-odb/18/10dff58d8a660512d4832e740f692884338ccd rename to tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd diff --git a/tests/resources/sample-odb/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 similarity index 100% rename from tests/resources/sample-odb/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 rename to tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 diff --git a/tests/resources/sample-odb/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 similarity index 100% rename from tests/resources/sample-odb/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 rename to tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 diff --git a/tests/resources/sample-odb/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 similarity index 100% rename from tests/resources/sample-odb/5b/5b025afb0b4c913b4c338a42934a3863bf3644 rename to tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 diff --git a/tests/resources/sample-odb/75/057dd4114e74cca1d750d0aee1647c903cb60a b/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a similarity index 100% rename from tests/resources/sample-odb/75/057dd4114e74cca1d750d0aee1647c903cb60a rename to tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a diff --git a/tests/resources/pack-odb/7b/4384978d2493e851f9cca7858815fac9b10980 b/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 similarity index 100% rename from tests/resources/pack-odb/7b/4384978d2493e851f9cca7858815fac9b10980 rename to tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 diff --git a/tests/resources/sample-odb/81/4889a078c031f61ed08ab5fa863aea9314344d b/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d similarity index 100% rename from tests/resources/sample-odb/81/4889a078c031f61ed08ab5fa863aea9314344d rename to tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d diff --git a/tests/resources/sample-odb/84/96071c1b46c854b31185ea97743be6a8774479 b/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 similarity index 100% rename from tests/resources/sample-odb/84/96071c1b46c854b31185ea97743be6a8774479 rename to tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 diff --git a/tests/resources/sample-odb/9f/d738e8f7967c078dceed8190330fc8648ee56a b/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a similarity index 100% rename from tests/resources/sample-odb/9f/d738e8f7967c078dceed8190330fc8648ee56a rename to tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a diff --git a/tests/resources/sample-odb/a4/a7dce85cf63874e984719f4fdd239f5145052f b/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f similarity index 100% rename from tests/resources/sample-odb/a4/a7dce85cf63874e984719f4fdd239f5145052f rename to tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f diff --git a/tests/resources/sample-odb/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd similarity index 100% rename from tests/resources/sample-odb/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd rename to tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd diff --git a/tests/resources/sample-odb/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 similarity index 100% rename from tests/resources/sample-odb/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 rename to tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 diff --git a/tests/resources/pack-odb/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 b/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 similarity index 100% rename from tests/resources/pack-odb/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 rename to tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 diff --git a/tests/resources/sample-odb/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 b/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 similarity index 100% rename from tests/resources/sample-odb/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 rename to tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 diff --git a/tests/resources/sample-odb/c4/7800c7266a2be04c571c04d5a6614691ea99bd b/tests/resources/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd similarity index 100% rename from tests/resources/sample-odb/c4/7800c7266a2be04c571c04d5a6614691ea99bd rename to tests/resources/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd diff --git a/tests/resources/sample-odb/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/tests/resources/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 similarity index 100% rename from tests/resources/sample-odb/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 rename to tests/resources/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/resources/sample-odb/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 b/tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 similarity index 100% rename from tests/resources/sample-odb/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 rename to tests/resources/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 diff --git a/tests/resources/sample-odb/fa/49b077972391ad58037050f2a75f74e3671e92 b/tests/resources/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 similarity index 100% rename from tests/resources/sample-odb/fa/49b077972391ad58037050f2a75f74e3671e92 rename to tests/resources/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 diff --git a/tests/resources/sample-odb/fd/093bff70906175335656e6ce6ae05783708765 b/tests/resources/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 similarity index 100% rename from tests/resources/sample-odb/fd/093bff70906175335656e6ce6ae05783708765 rename to tests/resources/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 diff --git a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx similarity index 100% rename from tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx rename to tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx diff --git a/tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack b/tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack similarity index 100% rename from tests/resources/pack-odb/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack rename to tests/resources/testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.pack diff --git a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx similarity index 100% rename from tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx rename to tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx diff --git a/tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack b/tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack similarity index 100% rename from tests/resources/sample-odb/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack rename to tests/resources/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack diff --git a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx similarity index 100% rename from tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx rename to tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.idx diff --git a/tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack b/tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack similarity index 100% rename from tests/resources/pack-odb/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack rename to tests/resources/testrepo.git/objects/pack/pack-d85f5d483273108c9d8dd0e4728ccf0b2982423a.pack diff --git a/tests/t0204-readpack.c b/tests/t0204-readpack.c index 8310ea3d9..44694543a 100644 --- a/tests/t0204-readpack.c +++ b/tests/t0204-readpack.c @@ -2,8 +2,6 @@ #include "test_helpers.h" #include -#define ODB_FOLDER "../resources/pack-odb" - static const char *packed_objects[] = { "0266163a49e280c4f5ed1e08facd36a2bd716bcf", "53fc32d17276939fc79ed05badaef2db09990016", diff --git a/tests/t0205-readheader.c b/tests/t0205-readheader.c index f1fc0e7aa..626c5a5ac 100644 --- a/tests/t0205-readheader.c +++ b/tests/t0205-readheader.c @@ -2,9 +2,6 @@ #include "test_helpers.h" #include -#define PACK_ODB_FOLDER "../resources/pack-odb" -#define LOOSE_ODB_FOLDER "../resources/sample-odb" - static const char *packed_objects[] = { "0266163a49e280c4f5ed1e08facd36a2bd716bcf", "53fc32d17276939fc79ed05badaef2db09990016", @@ -161,7 +158,7 @@ BEGIN_TEST(readheader_packed_test) unsigned int i; git_odb *db; - must_pass(git_odb_open(&db, PACK_ODB_FOLDER)); + must_pass(git_odb_open(&db, ODB_FOLDER)); for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { git_oid id; @@ -186,7 +183,7 @@ BEGIN_TEST(readheader_loose_test) unsigned int i; git_odb *db; - must_pass(git_odb_open(&db, LOOSE_ODB_FOLDER)); + must_pass(git_odb_open(&db, ODB_FOLDER)); for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) { git_oid id; diff --git a/tests/t0401-parse.c b/tests/t0401-parse.c index 06427a185..1a2806bf1 100644 --- a/tests/t0401-parse.c +++ b/tests/t0401-parse.c @@ -6,8 +6,6 @@ #include #include -static const char *odb_dir = "../resources/pack-odb"; - static char *test_commits_broken[] = { /* empty commit */ @@ -225,11 +223,8 @@ BEGIN_TEST(parse_buffer_test) int i; git_repository *repo; - git_odb *db; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); for (i = 0; i < broken_commit_count; ++i) { @@ -265,6 +260,4 @@ BEGIN_TEST(parse_buffer_test) } git_repository_free(repo); - git_odb_close(db); - END_TEST diff --git a/tests/t0402-details.c b/tests/t0402-details.c index 1e002942b..d60b6481b 100644 --- a/tests/t0402-details.c +++ b/tests/t0402-details.c @@ -7,7 +7,6 @@ #include #include -static const char *odb_dir = "../resources/sample-odb"; static const char *commit_ids[] = { "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ @@ -21,14 +20,10 @@ BEGIN_TEST(query_details_test) const size_t commit_count = sizeof(commit_ids) / sizeof(const char *); unsigned int i; - git_odb *db; git_repository *repo; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); - for (i = 0; i < commit_count; ++i) { git_oid id; @@ -59,5 +54,4 @@ BEGIN_TEST(query_details_test) } git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0403-write.c b/tests/t0403-write.c index d4669e0ed..60133c409 100644 --- a/tests/t0403-write.c +++ b/tests/t0403-write.c @@ -6,7 +6,6 @@ #include #include -static const char *odb_dir = "../resources/sample-odb"; static const char *commit_ids[] = { "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ @@ -21,16 +20,13 @@ static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; #define COMMITTER_EMAIL "vicent@github.com" BEGIN_TEST(writenew_test) - git_odb *db; git_repository *repo; git_commit *commit, *parent; git_tree *tree; git_oid id; /* char hex_oid[41]; */ - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); /* Create commit in memory */ @@ -71,27 +67,22 @@ This is a commit created in memory and it will be written back to disk\n"); printf("Written new commit, SHA1: %s\n", hex_oid); */ - must_pass(remove_loose_object(odb_dir, (git_object *)commit)); + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); //git_person_free(&author); //git_person_free(&committer); git_repository_free(repo); - git_odb_close(db); - END_TEST BEGIN_TEST(writeback_test) - git_odb *db; git_repository *repo; git_oid id; git_commit *commit, *parent; const char *message; /* char hex_oid[41]; */ - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id, commit_ids[0]); @@ -123,8 +114,7 @@ BEGIN_TEST(writeback_test) printf("New SHA1: %s\n", hex_oid); */ - must_pass(remove_loose_object(odb_dir, (git_object *)commit)); + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0501-walk.c b/tests/t0501-walk.c index 9aa7261d2..55ae936d2 100644 --- a/tests/t0501-walk.c +++ b/tests/t0501-walk.c @@ -6,7 +6,6 @@ #include #include -static const char *odb_dir = "../resources/sample-odb"; /* $ git log --oneline --graph --decorate * a4a7dce (HEAD, br2) Merge branch 'master' into br2 @@ -91,15 +90,12 @@ static int test_walk(git_revwalk *walk, git_commit *start_from, } BEGIN_TEST(simple_walk_test) - git_odb *db; git_oid id; git_repository *repo; git_revwalk *walk; git_commit *head = NULL; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); walk = git_revwalk_alloc(repo); @@ -130,5 +126,4 @@ BEGIN_TEST(simple_walk_test) git_revwalk_free(walk); git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0601-read.c b/tests/t0601-read.c index 4c31be9c3..345e5b534 100644 --- a/tests/t0601-read.c +++ b/tests/t0601-read.c @@ -5,7 +5,7 @@ #include #include -#define TEST_INDEX_PATH "../resources/index" +#define TEST_INDEX_PATH "../resources/testrepo.git/index" #define TEST_INDEX2_PATH "../resources/gitgit.index" #define TEST_INDEX_ENTRY_COUNT 109 @@ -29,7 +29,7 @@ struct test_entry TEST_ENTRIES[] = { BEGIN_TEST(index_loadempty_test) git_index *index; - index = git_index_alloc("in-memory-index"); + index = git_index_alloc("in-memory-index", NULL); must_be_true(index != NULL); must_be_true(index->on_disk == 0); @@ -46,7 +46,7 @@ BEGIN_TEST(index_load_test) git_index *index; unsigned int i; - index = git_index_alloc(TEST_INDEX_PATH); + index = git_index_alloc(TEST_INDEX_PATH, NULL); must_be_true(index != NULL); must_be_true(index->on_disk); @@ -70,7 +70,7 @@ END_TEST BEGIN_TEST(index2_load_test) git_index *index; - index = git_index_alloc(TEST_INDEX2_PATH); + index = git_index_alloc(TEST_INDEX2_PATH, NULL); must_be_true(index != NULL); must_be_true(index->on_disk); @@ -88,7 +88,7 @@ BEGIN_TEST(index_find_test) git_index *index; unsigned int i; - index = git_index_alloc(TEST_INDEX_PATH); + index = git_index_alloc(TEST_INDEX_PATH, NULL); must_be_true(index != NULL); must_pass(git_index_read(index)); @@ -104,7 +104,7 @@ BEGIN_TEST(index_findempty_test) git_index *index; unsigned int i; - index = git_index_alloc("fake-index"); + index = git_index_alloc("fake-index", NULL); must_be_true(index != NULL); for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) { diff --git a/tests/t0602-write.c b/tests/t0602-write.c index c5e5c7d94..d232193b7 100644 --- a/tests/t0602-write.c +++ b/tests/t0602-write.c @@ -5,7 +5,7 @@ #include #include -#define TEST_INDEX_PATH "../resources/index" +#define TEST_INDEX_PATH "../resources/testrepo.git/index" int filecmp(const char *filename1, const char *filename2) { @@ -35,7 +35,7 @@ BEGIN_TEST(index_load_test) git_index *index; git_filelock out_file; - index = git_index_alloc(TEST_INDEX_PATH); + index = git_index_alloc(TEST_INDEX_PATH, NULL); must_be_true(index != NULL); must_pass(git_index_read(index)); must_be_true(index->on_disk); diff --git a/tests/t0603-sort.c b/tests/t0603-sort.c index 28292377a..dfbb6e175 100644 --- a/tests/t0603-sort.c +++ b/tests/t0603-sort.c @@ -36,7 +36,7 @@ BEGIN_TEST(index_sort_test) git_index *index; unsigned int i; - index = git_index_alloc(TEST_INDEX_PATH); + index = git_index_alloc(TEST_INDEX_PATH, NULL); must_be_true(index != NULL); must_pass(git_index_read(index)); @@ -54,7 +54,7 @@ END_TEST BEGIN_TEST(index_sort_empty_test) git_index *index; - index = git_index_alloc("fake-index"); + index = git_index_alloc("fake-index", NULL); must_be_true(index != NULL); git_index__sort(index); diff --git a/tests/t0801-readtag.c b/tests/t0801-readtag.c index 9e675e8b7..798fa8f49 100644 --- a/tests/t0801-readtag.c +++ b/tests/t0801-readtag.c @@ -6,21 +6,17 @@ #include #include -static const char *odb_dir = "../resources/pack-odb"; static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"; static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980"; static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d"; BEGIN_TEST(readtag) - git_odb *db; git_repository *repo; git_tag *tag1, *tag2; git_commit *commit; git_oid id1, id2, id_commit; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id1, tag1_id); @@ -44,5 +40,4 @@ BEGIN_TEST(readtag) must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0); git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0802-write.c b/tests/t0802-write.c index 4fc262177..20c1eab0a 100644 --- a/tests/t0802-write.c +++ b/tests/t0802-write.c @@ -6,19 +6,15 @@ #include #include -static const char *odb_dir = "../resources/pack-odb"; static const char *tag_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"; BEGIN_TEST(tag_writeback_test) - git_odb *db; git_oid id; git_repository *repo; git_tag *tag; /* char hex_oid[41]; */ - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id, tag_id); @@ -36,8 +32,7 @@ BEGIN_TEST(tag_writeback_test) printf("TAG New SHA1: %s\n", hex_oid); */ - must_pass(remove_loose_object(odb_dir, (git_object *)tag)); + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag)); git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0901-readtree.c b/tests/t0901-readtree.c index eba6ecf46..e3a85c52d 100644 --- a/tests/t0901-readtree.c +++ b/tests/t0901-readtree.c @@ -6,18 +6,14 @@ #include #include -static const char *odb_dir = "../resources/sample-odb"; static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; BEGIN_TEST(tree_entry_access_test) - git_odb *db; git_oid id; git_repository *repo; git_tree *tree; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id, tree_oid); @@ -34,19 +30,15 @@ BEGIN_TEST(tree_entry_access_test) must_be_true(git_tree_entry_byindex(tree, -1) == NULL); git_repository_free(repo); - git_odb_close(db); END_TEST BEGIN_TEST(tree_read_test) - git_odb *db; git_oid id; git_repository *repo; git_tree *tree; git_tree_entry *entry; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id, tree_oid); @@ -61,9 +53,7 @@ BEGIN_TEST(tree_read_test) must_be_true(strcmp(git_tree_entry_name(entry), "README") == 0); - must_be_true(git_tree_entry_2object(entry) != NULL); git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/t0902-modify.c b/tests/t0902-modify.c index 67ae1fa64..23fc03cb2 100644 --- a/tests/t0902-modify.c +++ b/tests/t0902-modify.c @@ -6,22 +6,17 @@ #include #include -static const char *odb_dir = "../resources/sample-odb"; static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; BEGIN_TEST(tree_in_memory_add_test) const unsigned int entry_count = 128; - - git_odb *db; git_repository *repo; git_tree *tree; unsigned int i; git_oid entry_id; - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); tree = git_tree_new(repo); @@ -36,16 +31,14 @@ BEGIN_TEST(tree_in_memory_add_test) must_be_true(git_tree_entrycount(tree) == entry_count); must_pass(git_object_write((git_object *)tree)); - must_pass(remove_loose_object(odb_dir, (git_object *)tree)); + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tree)); git_object_free((git_object *)tree); git_repository_free(repo); - git_odb_close(db); END_TEST BEGIN_TEST(tree_add_entry_test) - git_odb *db; git_oid id; git_repository *repo; git_tree *tree; @@ -53,9 +46,7 @@ BEGIN_TEST(tree_add_entry_test) unsigned int i; /* char hex_oid[41]; */ - must_pass(git_odb_open(&db, odb_dir)); - - repo = git_repository_alloc(db); + repo = git_repository_open(REPOSITORY_FOLDER); must_be_true(repo != NULL); git_oid_mkstr(&id, tree_oid); @@ -92,10 +83,7 @@ BEGIN_TEST(tree_add_entry_test) printf("TREE New SHA1: %s\n", hex_oid); */ - must_pass(remove_loose_object(odb_dir, (git_object *)tree)); - + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tree)); git_object_free((git_object *)tree); - git_repository_free(repo); - git_odb_close(db); END_TEST diff --git a/tests/test_helpers.c b/tests/test_helpers.c index 08434b8e1..86192233a 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -84,18 +84,23 @@ int remove_object_files(const char *odb_dir, object_data *d) return 0; } -int remove_loose_object(const char *odb_dir, git_object *object) +int remove_loose_object(const char *repository_folder, git_object *object) { + static const char *objects_folder = "objects/"; + char *ptr, *full_path, *top_folder; - int path_length; + int path_length, objects_length; - assert(odb_dir && object); + assert(repository_folder && object); - path_length = strlen(odb_dir); - ptr = full_path = git__malloc(path_length + GIT_OID_HEXSZ + 3); + objects_length = strlen(objects_folder); + path_length = strlen(repository_folder); + ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3); - strcpy(ptr, odb_dir); - ptr = top_folder = ptr + path_length; + strcpy(ptr, repository_folder); + strcpy(ptr + path_length, objects_folder); + + ptr = top_folder = ptr + path_length + objects_length; *ptr++ = '/'; git_oid_pathfmt(ptr, git_object_id(object)); ptr += GIT_OID_HEXSZ + 1; diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 0d79d43bb..7085c645e 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -29,6 +29,8 @@ #include "test_lib.h" #include +#define ODB_FOLDER "../resources/testrepo.git/objects/" +#define REPOSITORY_FOLDER "../resources/testrepo.git/" typedef struct object_data { unsigned char *bytes; /* (compressed) bytes stored in object store */