From f96ac27087ae28112f78ef51ef3907104a8d72bf Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 3 Jan 2016 22:36:48 +0100 Subject: [PATCH] no log per branch rename log.html to log/HEAD.html, small code cleanup --- stagit.c | 54 ++++++++++++++---------------------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/stagit.c b/stagit.c index 9bd3194..026992c 100644 --- a/stagit.c +++ b/stagit.c @@ -22,8 +22,8 @@ struct commitinfo { char parentoid[GIT_OID_HEXSZ + 1]; const git_signature *author; - const char *summary; - const char *msg; + const char *summary; + const char *msg; git_diff_stats *stats; git_diff *diff; @@ -263,7 +263,7 @@ writeheader(FILE *fp) fputs("", fp); } fputs("\n", fp); - fprintf(fp, "Log | ", relpath); + fprintf(fp, "Log | ", relpath); fprintf(fp, "Files | ", relpath); fprintf(fp, "Refs/branches", relpath); if (hasreadme) @@ -698,15 +698,15 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path) count = git_tree_entrycount(tree); for (i = 0; i < count; i++) { - if (!(entry = git_tree_entry_byindex(tree, i))) - return -1; - if (git_tree_entry_to_object(&obj, repo, entry)) + if (!(entry = git_tree_entry_byindex(tree, i)) || + git_tree_entry_to_object(&obj, repo, entry)) return -1; filename = git_tree_entry_name(entry); switch (git_object_type(obj)) { case GIT_OBJ_BLOB: break; case GIT_OBJ_TREE: + /* NOTE: recurses */ ret = writefilestree(fp, (git_tree *)obj, branch, filename); git_object_free(obj); @@ -722,7 +722,6 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path) path, filename); filename = filepath; } - filesize = git_blob_rawsize((git_blob *)obj); fputs("", fp); @@ -757,12 +756,9 @@ writefiles(FILE *fp, const char *branch) if (git_revparse_single(&obj, repo, branch)) goto err; id = git_object_id(obj); - if (git_commit_lookup(&commit, repo, id)) - goto err; - if (git_commit_tree(&tree, commit)) { - git_commit_free(commit); + if (git_commit_lookup(&commit, repo, id) || + git_commit_tree(&tree, commit)) goto err; - } ret = writefilestree(fp, tree, branch, ""); err: @@ -820,11 +816,9 @@ writebranches(FILE *fp) relpath = ""; - fputs("", fp); + fputs("", fp); xmlencode(fp, branchname, strlen(branchname)); - fputs("", fp); + fputs("", fp); if (ci->author) printtimeshort(fp, &(ci->author->when)); fputs("", fp); @@ -963,10 +957,6 @@ int main(int argc, char *argv[]) { git_object *obj = NULL; - git_branch_iterator *it = NULL; - git_branch_t branch; - git_reference *ref = NULL; - const char *branchname = NULL; const git_error *e = NULL; FILE *fp, *fpread; char path[PATH_MAX], *p; @@ -1028,31 +1018,15 @@ main(int argc, char *argv[]) git_object_free(obj); /* log for HEAD */ - fp = efopen("log.html", "w"); + mkdir("log", 0755); + fp = efopen("log/HEAD.html", "w"); + relpath = "../"; writeheader(fp); + relpath = ""; writelog(fp, "HEAD"); writefooter(fp); fclose(fp); - /* log for local branches */ - if (git_branch_iterator_new(&it, repo, GIT_BRANCH_LOCAL)) - err(1, "git_branch_iterator_new"); - - while (!git_branch_next(&ref, &branch, it)) { - if (git_branch_name(&branchname, ref)) - continue; - - snprintf(path, sizeof(path), "log-%s.html", branchname); - - fp = efopen(path, "w"); - writeheader(fp); - writelog(fp, branchname); - writefooter(fp); - fclose(fp); - } - git_reference_free(ref); - git_branch_iterator_free(it); - /* files for HEAD */ fp = efopen("files.html", "w"); writeheader(fp); -- libgit2 1.1.1