From d77d972007d6f996ab4667b9dbbd1e241304c61e Mon Sep 17 00:00:00 2001 From: Eivind Uggedal Date: Thu, 10 Dec 2015 18:13:08 +0000 Subject: [PATCH] file page improvements - header with filename and size - handle binary files - small style changes --- urmoms.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/urmoms.c b/urmoms.c index 71ce3a0..fa47947 100644 --- 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("
\n", fp);
-	writeblobhtml(fp, (git_blob *)obj);
-	if (ferror(fp))
-		err(1, "fwrite");
+	fprintf(fp, "

%s (%" PRIu64 "b)


", entry->path, entry->file_size); + if (git_blob_is_binary((git_blob *)obj)) { + fprintf(fp, "

Binary file

\n"); + } else { + fputs("
\n", fp);
+		writeblobhtml(fp, (git_blob *)obj);
+		if (ferror(fp))
+			err(1, "fwrite");
+		fputs("
\n", fp); + } git_object_free(obj); - fputs("
\n", fp); writefooter(fp); fclose(fp); @@ -589,7 +595,7 @@ writefiles(FILE *fp) fprintf(fp, "%" PRIu64, entry->file_size); fputs("\n", fp); - writeblob(entry->path); + writeblob(entry); } fputs("", fp);