From d833220215f924e6b165a949640af450975fb3af Mon Sep 17 00:00:00 2001 From: Oscar Benedito Date: Thu, 10 Sep 2020 17:42:18 +0200 Subject: 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. --- stagit.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'stagit.c') diff --git a/stagit.c b/stagit.c index f33431d..bcd5002 100644 --- 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("

Directory: ", fp); + xmlencode(fp, path, strlen(path)); + fputs("

\n", fp); + } + fputs("\n" "" "" "\n\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("\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("
ModeNameSize
d---------..
", fp); fputs(filemode(git_tree_entry_filemode(entry)), fp); - fprintf(fp, "", fp); xmlencode(fp, entryname, strlen(entryname)); -- cgit v1.2.3