stagit

my fork of stagit that runs this site
git clone git://git.jakekoroman.com/stagit
Log | Files | Refs | README | LICENSE

commit d77d972007d6f996ab4667b9dbbd1e241304c61e
parent 23fdbb0c8cd8f875e678c17ef79919a22d704c7a
Author: Eivind Uggedal <eivind@uggedal.com>
Date:   Thu, 10 Dec 2015 18:13:08 +0000

file page improvements

- header with filename and size
- handle binary files
- small style changes

Diffstat:
Murmoms.c | 36+++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/urmoms.c b/urmoms.c @@ -529,31 +529,37 @@ writeatom(FILE *fp) } int -writeblob(const char *path) +writeblob(git_index_entry *entry) { - char htmlpath[PATH_MAX]; - char refpath[PATH_MAX]; + char fpath[PATH_MAX]; + char ref[PATH_MAX]; git_object *obj = NULL; FILE *fp; - snprintf(htmlpath, sizeof(htmlpath), "file/%s.html", path); - snprintf(refpath, sizeof(refpath), "HEAD:%s", path); + snprintf(fpath, sizeof(fpath), "file/%s.html", entry->path); + snprintf(ref, sizeof(ref), "HEAD:%s", entry->path); - if (git_revparse_single(&obj, repo, refpath)) - return 1; /* TODO: handle error */ + if (git_revparse_single(&obj, repo, ref)) + return 1; - mkdirp(dirname(htmlpath)); + if (mkdirp(dirname(fpath))) + return 1; relpath = "../"; /* TODO: dynamic relpath based on number of /'s */ - fp = efopen(htmlpath, "w+b"); + fp = efopen(fpath, "w+b"); writeheader(fp); - fputs("<pre>\n", fp); - writeblobhtml(fp, (git_blob *)obj); - if (ferror(fp)) - err(1, "fwrite"); + fprintf(fp, "<p>%s (%" PRIu64 "b)</p><hr/>", entry->path, entry->file_size); + if (git_blob_is_binary((git_blob *)obj)) { + fprintf(fp, "<p>Binary file</p>\n"); + } else { + fputs("<pre>\n", fp); + writeblobhtml(fp, (git_blob *)obj); + if (ferror(fp)) + err(1, "fwrite"); + fputs("</pre>\n", fp); + } git_object_free(obj); - fputs("</pre>\n", fp); writefooter(fp); fclose(fp); @@ -589,7 +595,7 @@ writefiles(FILE *fp) fprintf(fp, "%" PRIu64, entry->file_size); fputs("</td></tr>\n", fp); - writeblob(entry->path); + writeblob(entry); } fputs("</tbody></table>", fp);