commit 67bf696ef2fee96e92c30d28635343536baa51cf
parent 102253bdf0bd9573ed2489c6d9ae2a2202015af9
Author: awy <awy@awy.one>
Date: Fri, 10 Apr 2026 22:49:34 +0300
clickable parent path
Diffstat:
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/stagit.c b/stagit.c
@@ -990,9 +990,9 @@ writeblobraw(const git_blob *blob, const char *fpath, const char *filename, git_
}
size_t
-writeblob(git_object *obj, const char *fpath, const char *rpath, const char *filename, size_t filesize)
+writeblob(git_object *obj, const char *fpath, const char *rpath, const char *filename, const char *path, size_t filesize)
{
- char tmp[PATH_MAX] = "";
+ char tmp[PATH_MAX] = "", *file_parent;
const char *p, *oldrelpath;
int lc = 0;
FILE *fp;
@@ -1002,6 +1002,7 @@ writeblob(git_object *obj, const char *fpath, const char *rpath, const char *fil
if (strlcpy(tmp, fpath, sizeof(tmp)) >= sizeof(tmp))
errx(1, "path truncated: '%s'", fpath);
+ file_parent = strrchr(tmp, '/');
for (p = fpath, tmp[0] = '\0'; *p; p++) {
if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp))
errx(1, "path truncated: '../%s'", tmp);
@@ -1010,9 +1011,26 @@ writeblob(git_object *obj, const char *fpath, const char *rpath, const char *fil
oldrelpath = relpath;
relpath = tmp;
+ if (file_parent == NULL)
+ file_parent = "files";
+ else {
+ *file_parent = '\0';
+ file_parent = strrchr(tmp, '/');
+ if (file_parent == NULL)
+ file_parent = tmp;
+ else
+ ++file_parent;
+ }
+
fp = efopen(fpath, "w");
writeheader(fp, filename);
fputs("<p> ", fp);
+ fputs("<div><a id=\"file-parent-path\" href=\"", fp);
+ xmlencode(fp, relpath + 3, strlen(relpath) - 3);
+ xmlencode(fp, path, strlen(path));
+ fputs(".html\">", fp);
+ xmlencode(fp, path, strlen(path));
+ fprintf(fp, "</a>%s", strlen(path) == 0 ? "" : "/");
xmlencode(fp, filename, strlen(filename));
fprintf(fp, " (%zuB)", filesize);
fprintf(fp, " - <a href=\"%s%s\">raw</a></p><hr/>", relpath, rpath);
@@ -1224,7 +1242,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
case GIT_OBJ_BLOB:
is_obj_tree = 0;
filesize = git_blob_rawsize((git_blob *)obj);
- lc = writeblob(obj, filepath, rawpath, entryname, filesize);
+ lc = writeblob(obj, filepath, rawpath, entryname, path, filesize);
writeblobraw((git_blob *)obj, rawpath, entryname, filesize);
break;
case GIT_OBJ_TREE: