diff options
author | EuAndreh <eu@euandre.org> | 2021-08-02 11:08:20 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-08-02 11:08:20 -0300 |
commit | 2d12718803a9c7571ad14a58b6c47512184159bc (patch) | |
tree | 58052c9f66b03d082f4ca22b3e2a145a44303e57 /src | |
parent | src/gistatic.c: Tweak CSS and HTML, and some libgit2 error logging (diff) | |
download | gistatic-2d12718803a9c7571ad14a58b6c47512184159bc.tar.gz gistatic-2d12718803a9c7571ad14a58b6c47512184159bc.tar.xz |
src/gistatic.c: WIP implementation of repo_write_snapshots()
Diffstat (limited to 'src')
-rw-r--r-- | src/gistatic.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/gistatic.c b/src/gistatic.c index 5c03432..5679b2e 100644 --- a/src/gistatic.c +++ b/src/gistatic.c @@ -1589,6 +1589,73 @@ cleanup: return ret; } +static int repo_write_snapshots( + const char *const outdir, + struct git_repository *const repo, + const char *const project_name +) { + int ret = 0; + int e; + (void)outdir; + (void)repo; + (void)project_name; + char *snapshots_dir = NULL; + struct git_reference_iterator *ref_iter = NULL; + + if (!(snapshots_dir = strjoin(outdir, "/snapshots"))) { + ret = -1; + goto cleanup; + } + + errno = 0; + if (mkdir(snapshots_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) + && errno != EEXIST) { + logerrs("mkdir(\"", snapshots_dir, "\")", strerror(errno), + __LINE__); + ret = EXIT_ERROR; + goto cleanup; + } + + if (git_reference_iterator_new(&ref_iter, repo)) { + const git_error *const error = git_error_last(); + assert(error); + logerr("git_reference_iterator_new()", error->message, + __LINE__); + ret = -1; + goto cleanup; + } + + struct git_reference *ref; + while (!(e = git_reference_next(&ref, ref_iter))) { + if ( + !git_reference_is_tag(ref) + && !git_reference_is_branch(ref) + && !git_reference_is_note(ref) + ) { + git_reference_free(ref); + continue; + } + + // 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" + // printf("reference name: %s\n", git_reference_shorthand(ref)); + git_reference_free(ref); + } + if (e != GIT_ITEROVER) { + const git_error *const error = git_error_last(); + assert(error); + logerr("git_reference_next()", error->message, __LINE__); + ret = -1; + goto cleanup; + } + +cleanup: + git_reference_iterator_free(ref_iter); + free(snapshots_dir); + return ret; +} + static int repo_write( const char *const outdir, char *const reporelpath, |