diff --git a/stagit.c b/stagit.c index ab62c8f..3f1594d 100644 --- a/stagit.c +++ b/stagit.c @@ -329,12 +329,11 @@ printcommit(FILE *fp, struct commitinfo *ci) printtime(fp, &(ci->author->when)); fputc('\n', fp); } - fputc('\n', fp); - - if (ci->msg) + if (ci->msg) { + fputc('\n', fp); xmlencode(fp, ci->msg, strlen(ci->msg)); - - fputc('\n', fp); + fputc('\n', fp); + } } void @@ -357,19 +356,18 @@ printshowfile(struct commitinfo *ci) fp = efopen(path, "w"); writeheader(fp); - fputs("
\n", fp); + fputs("", fp); printcommit(fp, ci); memset(&statsbuf, 0, sizeof(statsbuf)); /* diff stat */ - if (ci->stats) { - if (!git_diff_stats_to_buf(&statsbuf, ci->stats, - GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) { - if (statsbuf.ptr && statsbuf.ptr[0]) { - fputs("Diffstat:\n", fp); - fputs(statsbuf.ptr, fp); - } + if (ci->stats && + !git_diff_stats_to_buf(&statsbuf, ci->stats, + GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) { + if (statsbuf.ptr && statsbuf.ptr[0]) { + fputs("Diffstat:\n", fp); + xmlencode(fp, statsbuf.ptr, strlen(statsbuf.ptr)); } } @@ -430,21 +428,13 @@ printshowfile(struct commitinfo *ci) } int -writelog(FILE *fp, const char *branch) +writelog(FILE *fp, const git_oid *oid) { struct commitinfo *ci; - const git_oid *oid; git_revwalk *w = NULL; - git_object *obj = NULL; git_oid id; size_t len; - mkdir("commit", 0755); - - if (git_revparse_single(&obj, repo, branch)) - return -1; - oid = git_object_id(obj); - git_revwalk_new(&w, repo); git_revwalk_push(w, oid); git_revwalk_sorting(w, GIT_SORT_TIME); @@ -493,7 +483,6 @@ writelog(FILE *fp, const char *branch) fputs("", fp); git_revwalk_free(w); - git_object_free(obj); relpath = ""; @@ -579,14 +568,13 @@ writeatom(FILE *fp) } int -writeblob(git_object *obj, const char *filename, git_off_t filesize) +writeblob(git_object *obj, const char *fpath, const char *filename, git_off_t filesize) { - char fpath[PATH_MAX]; char tmp[PATH_MAX] = ""; - char *d, *p; + char *d; + const char *p; FILE *fp; - snprintf(fpath, sizeof(fpath), "file/%s.html", filename); d = xdirname(fpath); if (mkdirp(d)) { free(d); @@ -698,35 +686,32 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path) git_object_free(obj); continue; } - if (path[0]) { - snprintf(filepath, sizeof(filepath), "%s/%s", + if (path[0]) + snprintf(filepath, sizeof(filepath), "file/%s/%s.html", path, filename); - filename = filepath; - } + else + snprintf(filepath, sizeof(filepath), "file/%s.html", + filename); filesize = git_blob_rawsize((git_blob *)obj); fputs("\n", fp); - writeblob(obj, filename, filesize); + writeblob(obj, filepath, filename, filesize); } return 0; } int -writefiles(FILE *fp, const char *branch) +writefiles(FILE *fp, const git_oid *id, const char *branch) { - const git_oid *id; git_tree *tree = NULL; - git_object *obj = NULL; git_commit *commit = NULL; int ret = -1; @@ -734,9 +719,6 @@ writefiles(FILE *fp, const char *branch) " ", fp); - fprintf(fp, "%s", filemode(git_tree_entry_filemode(entry))); - fprintf(fp, " ", fp); + fputs(filemode(git_tree_entry_filemode(entry)), fp); + fprintf(fp, " ", relpath, filepath); xmlencode(fp, filename, strlen(filename)); fputs(" ", fp); fprintf(fp, "%ju", (uintmax_t)filesize); fputs(" Mode Name Size " "\n\n", fp); - if (git_revparse_single(&obj, repo, branch)) - goto err; - id = git_object_id(obj); if (git_commit_lookup(&commit, repo, id) || git_commit_tree(&tree, commit)) goto err; @@ -745,7 +727,6 @@ writefiles(FILE *fp, const char *branch) err: fputs("", fp); - git_object_free(obj); git_commit_free(commit); git_tree_free(tree); @@ -778,7 +759,7 @@ writerefs(FILE *fp) git_reference *dref = NULL, *r, *ref = NULL; git_reference_iterator *it = NULL; git_reference **refs = NULL; - size_t count, i, j, len, refcount = 0; + size_t count, i, j, refcount = 0; const char *cols[] = { "Branch", "Tag" }; /* first column title */ const char *titles[] = { "Branches", "Tags" }; const char *ids[] = { "branches", "tags" }; @@ -827,9 +808,7 @@ writerefs(FILE *fp) /* print header if it has an entry (first). */ if (++count == 1) { fprintf(fp, "%s
%s | " - "Age | Commit message | " - "Author | Files | + | " - "- | Age | Author | \n\n\n", titles[j], ids[j], cols[j]); } @@ -842,28 +821,8 @@ writerefs(FILE *fp) if (ci->author) printtimeshort(fp, &(ci->author->when)); fputs("", fp); - if (ci->summary) { - if (j) - fprintf(fp, "", - relpath, ci->oid); - if ((len = strlen(ci->summary)) > summarylen) { - xmlencode(fp, ci->summary, summarylen - 1); - fputs("…", fp); - } else { - xmlencode(fp, ci->summary, len); - } - if (j) - fputs("", fp); - } - fputs(" | ", fp); if (ci->author) xmlencode(fp, ci->author->name, strlen(ci->author->name)); - fputs(" | ", fp); - fprintf(fp, "%zu", ci->filecount); - fputs(" | ", fp); - fprintf(fp, "+%zu", ci->addcount); - fputs(" | ", fp); - fprintf(fp, "-%zu", ci->delcount); fputs(" | \n", fp); relpath = "../"; @@ -876,7 +835,7 @@ writerefs(FILE *fp) } /* table footer */ if (count) - fputs("