diff options
author | EuAndreh <eu@euandre.org> | 2021-08-22 12:45:11 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-08-22 12:45:11 -0300 |
commit | c0074cb7d7d52cfb6e958b20b95a0be3b90a8705 (patch) | |
tree | bb7e1c7ad19ce10914301da23e216ea45241fc5e /src | |
parent | src/lib.c: Tweak test_start() name (diff) | |
download | gistatic-c0074cb7d7d52cfb6e958b20b95a0be3b90a8705.tar.gz gistatic-c0074cb7d7d52cfb6e958b20b95a0be3b90a8705.tar.xz |
src/lib.c: Write repo_tarballs_refs_each, calling stub tarzify() function
Diffstat (limited to '')
-rw-r--r-- | src/lib.c | 106 | ||||
-rw-r--r-- | src/tar.c | 5 | ||||
-rw-r--r-- | src/tar.h | 2 |
3 files changed, 95 insertions, 18 deletions
@@ -1957,6 +1957,87 @@ cleanup: return ret; } +static int repo_tarballs_refs_each( + struct git_repository *const repo, + struct git_reference *const ref, + const char *const project_name +) { + int ret = 0; + char *out = NULL; + struct git_commit *commit = NULL; + struct git_tree *tree = NULL; + + const bool is_tag = git_reference_is_tag(ref); + const bool is_branch = git_reference_is_branch(ref); + + if (!is_branch || !is_tag) { + goto cleanup; + } + + const char *const name = git_reference_shorthand(ref); + assert(name); + const struct git_oid *const oid = git_reference_target(ref); + assert(oid != NULL); + + char template[] = "/tmp/gistatic.XXXXXX"; + const char *const tmpdir = mkdtemp(template); + if (!tmpdir) { + logerrs("mkdtemp(", tmpdir, ")", strerror(errno), __LINE__); + ret = -1; + goto cleanup; + } + out = strsjoin((const char *const []) + { tmpdir, "/", project_name, "-", name, NULL }); + if (!out) { + ret = -1; + goto cleanup; + } + + git_checkout_options options; + if (git_checkout_options_init(&options, GIT_CHECKOUT_OPTIONS_VERSION)) { + const git_error *const error = git_error_last(); + assert(error); + logerr("git_checkout_options_init()", error->message, __LINE__); + ret = -1; + goto cleanup; + } + + options.target_directory = out; + options.checkout_strategy = + GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; + + if (git_commit_lookup(&commit, repo, oid)) { + const git_error *const error = git_error_last(); + assert(error); + logerrs("git_commit_lookup(", name, ")", error->message, + __LINE__); + ret = -1; + goto cleanup; + } + + const struct git_object *const treeish = + (const git_object *const)commit; + if (git_checkout_tree(repo, treeish, &options)) { + const git_error *const error = git_error_last(); + assert(error); + logerr("git_reference_iterator_new()", error->message, + __LINE__); + ret = -1; + goto cleanup; + } + + if (tarzify(out)) { + ret = -1; + goto cleanup; + } + +cleanup: + git_tree_free(tree); + git_commit_free(commit); + free(out); + return ret; +} + static int repo_tarballs_write( const char *const outdir, struct git_repository *const repo, @@ -1992,26 +2073,15 @@ static int repo_tarballs_write( struct git_reference *ref; while (!(e = git_reference_next(&ref, ref_iter))) { - const char *const name = git_reference_shorthand(ref); - assert(name); - const bool is_tag = git_reference_is_tag(ref); - const bool is_branch = git_reference_is_branch(ref); - const bool is_note = git_reference_is_note(ref); - - if (!is_tag && !is_branch && !is_note) { - goto loop_cleanup; + e = repo_tarballs_refs_each(repo, ref, project_name); + git_reference_free(ref); + if (e == -1) { + ret = -1; + goto cleanup; } - if (is_note && strcmp(name, "notes/signatures/tar.xz") != 0) { - goto loop_cleanup; + if (e) { + ret = 1; } - - // printf("reference name: %s\n", git_reference_shorthand(ref)); - - // https://github.com/ionescu007/minlzma - // https://git.tukaani.org/?p=xz.git;a=tree;f=src;h=665b39e6439f1bb5afd9181ec0890c2ed26d047e;hb=HEAD - // git archive --format tar.xz --prefix "$PROJECT-$tag/" "$tag" - loop_cleanup: - git_reference_free(ref); } if (e != GIT_ITEROVER) { const git_error *const error = git_error_last(); @@ -1,6 +1,11 @@ #include "config.h" #include "tar.h" +int tarzify(const char *const directory_path) { + (void)directory_path; + return 1; +} + #ifdef TEST void unit_tests_tar(void) {} #endif @@ -1,6 +1,8 @@ #ifndef GISTATIC_TAR_H #define GISTATIC_TAR_H +int tarzify(const char *const directory_path); + #ifdef TEST void unit_tests_tar(void); #endif |