\n", fp); - writeblob(entry->path); + writeblob(entry); } fputs("
tfile page improvements - stagit - static git page generator
git clone git://src.adamsgaard.dk/stagit
Log
Files
Refs
README
LICENSE
---
commit d77d972007d6f996ab4667b9dbbd1e241304c61e
parent 23fdbb0c8cd8f875e678c17ef79919a22d704c7a
Author: Eivind Uggedal 
Date:   Thu, 10 Dec 2015 18:13:08 +0000

file page improvements

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

Diffstat:
  M urmoms.c                            |      36 ++++++++++++++++++-------------

1 file changed, 21 insertions(+), 15 deletions(-)
---
diff --git a/urmoms.c b/urmoms.c
t@@ -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); t@@ -589,7 +595,7 @@ writefiles(FILE *fp) fprintf(fp, "%" PRIu64, entry->file_size); fputs("
", fp);