stagit

Personal fork of stagit.
git clone git://git.samirparikh.com/stagit
Log | Files | Refs | README | LICENSE

commit d833220215f924e6b165a949640af450975fb3af
parent ecd0f6fb42cc6ca1ed4d9756a1e1cd4f04f8df0a
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Thu, 10 Sep 2020 17:42:18 +0200

Improve directory navigation UX

Current directory path is now shown and navigation to parent directory
has been added. The style for directory entries has changed to
diferentiate from files.

Diffstat:
Mstagit.c | 38+++++++++++++++++++++++++++++++++++---
Mstyle.css | 5+++++
2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/stagit.c b/stagit.c @@ -1020,15 +1020,41 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) git_off_t filesize; FILE *fp_subtree; const char *entryname, *oldrelpath; - char filepath[PATH_MAX], rawpath[PATH_MAX], entrypath[PATH_MAX], tmp[PATH_MAX]; + char filepath[PATH_MAX], rawpath[PATH_MAX], entrypath[PATH_MAX], tmp[PATH_MAX], tmp2[PATH_MAX]; + char* parent; size_t count, i; int lc, r, rf, ret; + if (strlen(path) > 0) { + fputs("<h2>Directory: ", fp); + xmlencode(fp, path, strlen(path)); + fputs("</h2>\n", fp); + } + fputs("<table id=\"files\"><thead>\n<tr>" "<td><b>Mode</b></td><td><b>Name</b></td>" "<td class=\"num\" align=\"right\"><b>Size</b></td>" "</tr>\n</thead><tbody>\n", fp); + if (strlen(path) > 0) { + if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp)) + errx(1, "path truncated: '%s'", path); + parent = strrchr(tmp, '/'); + if (parent == NULL) + parent = "files"; + else { + *parent = '\0'; + parent = strrchr(tmp, '/'); + if (parent == NULL) + parent = tmp; + else + ++parent; + } + fputs("<tr><td>d---------</td><td><a class=\"dir\" href=\"../", fp); + xmlencode(fp, parent, strlen(parent)); + fputs(".html\">..</a></td><td class=\"num\" align=\"right\"></td></tr>\n", fp); + } + count = git_tree_entrycount(tree); for (i = 0; i < count; i++) { if (!(entry = git_tree_entry_byindex(tree, i)) || @@ -1063,7 +1089,10 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) oldrelpath = relpath; relpath = tmp; fp_subtree = efopen(filepath, "w"); - writeheader(fp_subtree, "Files"); + strlcpy(tmp2, "Files - ", sizeof(tmp2)); + if (strlcat(tmp2, entrypath, sizeof(tmp2)) >= sizeof(tmp2)) + errx(1, "path truncated: '%s'", tmp2); + writeheader(fp_subtree, tmp2); /* NOTE: recurses */ ret = writefilestree(fp_subtree, (git_tree *)obj, entrypath); @@ -1081,7 +1110,10 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) fputs("<tr><td>", fp); fputs(filemode(git_tree_entry_filemode(entry)), fp); - fprintf(fp, "</td><td><a href=\"%s", relpath); + fputs("</td><td><a ", fp); + if (git_object_type(obj) == GIT_OBJ_TREE) + fputs("class=\"dir\" ", fp); + fprintf(fp, "href=\"%s", relpath); xmlencode(fp, filepath, strlen(filepath)); fputs("\">", fp); xmlencode(fp, entryname, strlen(entryname)); diff --git a/style.css b/style.css @@ -65,6 +65,11 @@ a { margin: 0; } +#files .dir { + font-weight: bold; + text-decoration: none; +} + .url { font-family: monospace; }