commit d880df3be9d9e399ac9291be87a9ebedebb3e595 (patch)
parent 1b6a24c893866a604d9b7bc425f9b23706f39912
Author: alex <alex@garbash.com>
Date: Fri, 24 Sep 2021 20:04:14 -0400
stagit-index: Add -r flag to preserve repo paths
I want subdirectories in my stagit installation:
user1/repoa
user2/repob
user2/repoc
...
However, the current implementation truncates the links in the index
to be the basename of the repo.
This patch adds a new flag, -r, which prints the repodir's as they were
passed on the commandline instead of the basenames to the index.
Diffstat:
2 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/stagit-index.1 b/stagit-index.1
@@ -6,6 +6,7 @@
.Nd static git index page generator
.Sh SYNOPSIS
.Nm
+.Op Fl r
.Op Ar repodir...
.Sh DESCRIPTION
.Nm
@@ -15,7 +16,11 @@ The repos in the index are in the same order as the arguments
.Ar repodir
specified.
.Pp
-The basename of the directory is used as the repository name.
+The basename of the directory is used as the repository name
+unless
+.Fl r
+is given,
+in which case the full path is used to allow subdirectories in the index.
The suffix ".git" is removed from the basename, this suffix is commonly used
for "bare" repos.
.Pp
diff --git a/stagit-index.c b/stagit-index.c
@@ -13,7 +13,7 @@ static git_repository *repo;
static const char *relpath = "";
static char description[255] = "Repositories";
-static char *name = "";
+static const char *name = "";
static char owner[255];
void
@@ -145,9 +145,22 @@ main(int argc, char *argv[])
char path[PATH_MAX], repodirabs[PATH_MAX + 1];
const char *repodir;
int i, ret = 0;
+ int rflag = 0;
+ char opt;
+
+ while ((opt = getopt(argc, argv, "r")) != -1) {
+ switch (opt) {
+ case 'r':
+ rflag = 1;
+ break;
+ default:
+ fprintf(stderr, "%s [-r] repodir...\n", argv[0]);
+ return 1;
+ }
+ }
- if (argc < 2) {
- fprintf(stderr, "%s [repodir...]\n", argv[0]);
+ if (optind >= argc) {
+ fprintf(stderr, "%s [-r] repodir...\n", argv[0]);
return 1;
}
@@ -160,11 +173,8 @@ main(int argc, char *argv[])
writeheader(stdout);
- for (i = 1; i < argc; i++) {
+ for (i = optind; i < argc; i++) {
repodir = argv[i];
- if (!realpath(repodir, repodirabs))
- err(1, "realpath");
-
if (git_repository_open_ext(&repo, repodir,
GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) {
fprintf(stderr, "%s: cannot open repository\n", argv[0]);
@@ -172,11 +182,19 @@ main(int argc, char *argv[])
continue;
}
- /* use directory name as name */
- if ((name = strrchr(repodirabs, '/')))
- name++;
- else
- name = "";
+ if (rflag) {
+ /* use full path as name */
+ name = repodir;
+ } else {
+ /* use directory name as name */
+ if (!realpath(repodir, repodirabs))
+ err(1, "realpath");
+
+ if ((name = strrchr(repodirabs, '/')))
+ name++;
+ else
+ name = "";
+ }
/* read description or .git/description */
joinpath(path, sizeof(path), repodir, "description");