| Date: Sun, 3 Jan 2016 21:06:03 +0100
add refs page (branches and tags)
quite some code is added, this will be cleaned up in a following code iteration.
- make sure to free some more allocated git objects.
- use fputs() asmuch as possible instead of fprintf().
- code cleanup
Diffstat:
M TODO | 1 +
M stagit.c | 282 +++++++++++++++++++++++++++----
2 files changed, 251 insertions(+), 32 deletions(-)
--- |
| t@@ -264,7 +264,8 @@ writeheader(FILE *fp)
}
fputs(" | \n", fp);
fprintf(fp, "Log | ", relpath);
- fprintf(fp, "Files", relpath);
+ fprintf(fp, "Files | ", relpath);
+ fprintf(fp, "Refs", relpath);
if (hasreadme)
fprintf(fp, " | README", relpath);
if (haslicense)
t@@ -283,7 +284,7 @@ writefooter(FILE *fp)
void
writeblobhtml(FILE *fp, const git_blob *blob)
{
- off_t i = 0;
+ off_t i;
size_t n = 1;
char *nfmt = "%d\n";
const char *s = git_blob_rawcontent(blob);
t@@ -293,12 +294,11 @@ writeblobhtml(FILE *fp, const git_blob *blob)
if (len) {
fprintf(fp, nfmt, n, n, n);
- while (i < len - 1) {
+ for (i = 0; i < len - 1; i++) {
if (s[i] == '\n') {
n++;
fprintf(fp, nfmt, n, n, n);
}
- i++;
}
}
t@@ -319,7 +319,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
#if 0
if ((count = (int)git_commit_parentcount(commit)) > 1) {
- fprintf(fp, "Merge:");
+ fputs("Merge:", fp);
for (i = 0; i < count; i++) {
git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
fprintf(fp, " %s",
t@@ -329,9 +329,9 @@ printcommit(FILE *fp, struct commitinfo *ci)
}
#endif
if (ci->author) {
- fprintf(fp, "Author: ");
+ fputs("Author: ", fp);
xmlencode(fp, ci->author->name, strlen(ci->author->name));
- fprintf(fp, " <author->email, strlen(ci->author->email));
fputs("\">", fp);
xmlencode(fp, ci->author->email, strlen(ci->author->email));
t@@ -377,7 +377,7 @@ printshowfile(struct commitinfo *ci)
if (!git_diff_stats_to_buf(&statsbuf, ci->stats,
GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT, 80)) {
if (statsbuf.ptr && statsbuf.ptr[0]) {
- fprintf(fp, "Diffstat:\n");
+ fputs("Diffstat:\n", fp);
fputs(statsbuf.ptr, fp);
}
}
t@@ -431,24 +431,30 @@ printshowfile(struct commitinfo *ci)
}
git_buf_free(&statsbuf);
- fputs( "\n", fp);
+ fputs("\n", fp);
writefooter(fp);
fclose(fp);
return;
}
-void
-writelog(FILE *fp)
+int
+writelog(FILE *fp, const char *branch)
{
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_head(w);
+ git_revwalk_push(w, oid);
git_revwalk_sorting(w, GIT_SORT_TIME);
git_revwalk_simplify_first_parent(w);
t@@ -491,10 +497,14 @@ writelog(FILE *fp)
commitinfo_free(ci);
}
- fprintf(fp, " | |