commit fabdcdded4bc51d4305e0ed5f0eec48d5ad61fe1
parent 10e408581555dce682f96e4d2df6eeb9a071e621
Author: Pollux <pollux@pollux.codes>
Date: Fri, 11 Apr 2025 20:30:57 -0500
feat: write raw binary blobs to target file tree
Signed-off-by: Pollux <pollux@pollux.codes>
Diffstat:
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/stagit.c b/stagit.c
@@ -970,10 +970,24 @@ writemarkdownblob(FILE *fp, git_blob *blob)
return 0;
}
+void writerawblob(git_blob *blob, const char *fpath)
+{
+ FILE *fp;
+
+ fp = efopen(fpath, "w");
+
+ // TODO: Add check to file pointer
+
+ fwrite(git_blob_rawcontent(blob), git_blob_rawsize(blob), 1, fp);
+
+ fclose(fp);
+}
+
size_t
writeblob(git_object *obj, const char *fpath, const char *filename, size_t filesize)
{
char tmp[PATH_MAX] = "", *d;
+ char rawpath[PATH_MAX] = "";
const char *p;
size_t lc = 0;
FILE *fp;
@@ -998,9 +1012,11 @@ writeblob(git_object *obj, const char *fpath, const char *filename, size_t files
fprintf(fp, " (%zuB)", filesize);
fputs("</p><hr/>", fp);
- if (git_blob_is_binary((git_blob *)obj))
+ if (git_blob_is_binary((git_blob *)obj)) {
fputs("<p>Binary file.</p>\n", fp);
- else if (strlen(filename) >= 3 && !strcmp(filename + strlen(filename) - 3, ".md")) {
+ memcpy(rawpath, fpath, strlen(fpath) - 5);
+ writerawblob((git_blob *)obj, rawpath);
+ } else if (strlen(filename) >= 3 && !strcmp(filename + strlen(filename) - 3, ".md")) {
lc = writemarkdownblob(fp, (git_blob *)obj);
} else
lc = writeblobhtml(fp, (git_blob *)obj);