stagit

[fork] HTML git frontend
git clone https://hhvn.uk/stagit
git clone git://hhvn.uk/stagit
Log | Files | Refs | README | LICENSE

commit 64384ce6b3c12e34d134bdcc0d1cf95bc2a0c635
parent 7046dc44d406c7e24393a4279fea4eacc78c5d96
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  3 Sep 2023 08:31:55 +0100

Move go/clone urls into structs. Dynamic alloc for clones

Diffstat:
Mstagit.c | 48++++++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 22 deletions(-)

diff --git a/stagit.c b/stagit.c @@ -65,10 +65,14 @@ static const char *repodir; static char *name = ""; static char *strippedname = ""; static char description[255]; -static char *cloneurls[16]; -static int cloneurlsi = 0; -static char *gomodurl = NULL; -static int isgomod = 0; +static struct { + char **urls; + int i; +} clone = {0}; +static struct { + char *url; + int is; +} gomod = {0}; static char *submodules; static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" }; static char *license; @@ -520,11 +524,13 @@ writeheader(FILE *fp, const char *title) "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n" "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n", fp); - go = isgomod && gomodurl && cloneurlsi && strcmp(title, "Log") == 0; + go = gomod.is && clone.i && strcmp(title, "Log") == 0; + + printf("go: %d | clone.i: %d | gomod.is: %d | gomod.url: %s | title: %s\n", go, clone.i, gomod.is, gomod.url, title); - if (go) - fprintf(fp, "<meta name=\"go-import\" content=\"%s git %s\">\n", - gomodurl, cloneurls[0]); + if (go) fprintf(fp, "<meta name=\"go-import\"" + "content=\"%s git %s\">\n", + gomod.url, clone.urls[0]); fputs("<title>", fp); xmlencode(fp, title, strlen(title)); @@ -551,11 +557,10 @@ writeheader(FILE *fp, const char *title) xmlencode(fp, description, strlen(description)); fputs("</span></td></tr>", fp); - for (i = 0; i < cloneurlsi; i++) - writeurl(fp, "git clone", cloneurls[i]); + for (i = 0; i < clone.i; i++) + writeurl(fp, "git clone", clone.urls[i]); - if (go) - writeurl(fp, "go get", gomodurl); + if (go) writeurl(fp, "go get", gomod.url); fputs("<tr><td></td><td>\n", fp); fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath); @@ -1260,18 +1265,17 @@ main(int argc, char *argv[]) } else if (argv[i][1] == 'g') { if (i + 1 >= argc) usage(argv[0]); - - i++; - if (cloneurlsi == LEN(cloneurls)) - fprintf(stderr, "ignoring excess git clone URL\n"); - else - cloneurls[cloneurlsi++] = argv[i]; + if ((clone.urls = realloc(clone.urls, ++clone.i * + sizeof(clone.urls))) == NULL) + err(1, "realloc"); + clone.urls[clone.i - 1] = argv[++i]; } else if (argv[i][1] == 'G') { - if (i + 1 >= argc) + if (i + 1 >= argc || gomod.url) usage(argv[0]); - gomodurl = argv[++i]; + gomod.url = argv[++i]; } } + if (!repodir) usage(argv[0]); @@ -1353,8 +1357,8 @@ main(int argc, char *argv[]) if (gitfileexists(repo, "HEAD:.gitmodules")) submodules = ".gitmodules"; - /* check for go.mod file */ - isgomod = gitfileexists(repo, "HEAD:go.mod"); + /* check for gomod.mod file */ + gomod.is = gomod.url && gitfileexists(repo, "HEAD:go.mod"); /* log for HEAD */ fp = efopen("log.html", "w");