stagit

static git page generator (local tweaks)
git clone https://wehaveforgeathome.hates.computer/stagit.git
Log | Files | Refs | LICENSE

commit fdf30dc3830acf2728269d10a230a859eb7e6866
parent 2525ab87dc9207e6b7166536bdba6b030315c5ef
Author: Ryan Wolf <johnwayne@pseudony.ms>
Date:   Wed, 16 Apr 2025 23:37:51 -0400

require baseurl, remove relpath

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

diff --git a/stagit.c b/stagit.c @@ -59,7 +59,6 @@ struct referenceinfo { static git_repository *repo; static const char *baseurl = ""; /* base URL to make absolute RSS/Atom URI */ -static const char *relpath = ""; static const char *repodir; static char *name = ""; @@ -511,17 +510,17 @@ writeheader(FILE *fp, const char *title) if (description[0]) fputs(" - ", fp); xmlencode(fp, description, strlen(description)); - fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", relpath); + fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", baseurl); fputs("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"", fp); xmlencode(fp, name, strlen(name)); - fprintf(fp, " Atom Feed\" href=\"%satom.xml\" />\n", relpath); + fprintf(fp, " Atom Feed\" href=\"%satom.xml\" />\n", baseurl); fputs("<link rel=\"alternate\" type=\"application/atom+xml\" title=\"", fp); xmlencode(fp, name, strlen(name)); - fprintf(fp, " Atom Feed (tags)\" href=\"%stags.xml\" />\n", relpath); - fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", relpath); + fprintf(fp, " Atom Feed (tags)\" href=\"%stags.xml\" />\n", baseurl); + fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", baseurl); fputs("</head>\n<body>\n<table><tr><td>", fp); - fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>", - relpath, relpath); + fprintf(fp, "<a href=\"%s/..\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>", + baseurl, baseurl); fputs("</td><td><h1>", fp); xmlencode(fp, strippedname, strlen(strippedname)); fputs("</h1><span class=\"desc\">", fp); @@ -535,18 +534,18 @@ writeheader(FILE *fp, const char *title) fputs("</a></td></tr>", fp); } fputs("<tr><td></td><td>\n", fp); - fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath); - fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath); - fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath); + fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", baseurl); + fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", baseurl); + fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", baseurl); if (submodules) fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>", - relpath, submodules); + baseurl, submodules); if (readme) fprintf(fp, " | <a href=\"%sfile/%s.html\">README</a>", - relpath, readme); + baseurl, readme); if (license) fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>", - relpath, license); + baseurl, license); fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp); } @@ -593,11 +592,11 @@ void printcommit(FILE *fp, struct commitinfo *ci) { fprintf(fp, "<b>commit</b> <a href=\"%scommit/%s.html\">%s</a>\n", - relpath, ci->oid, ci->oid); + baseurl, ci->oid, ci->oid); if (ci->parentoid[0]) fprintf(fp, "<b>parent</b> <a href=\"%scommit/%s.html\">%s</a>\n", - relpath, ci->parentoid, ci->parentoid); + baseurl, ci->parentoid, ci->parentoid); if (ci->author) { fputs("<b>Author:</b> ", fp); @@ -697,11 +696,11 @@ printshowfile(FILE *fp, struct commitinfo *ci) for (i = 0; i < ci->ndeltas; i++) { patch = ci->deltas[i]->patch; delta = git_patch_get_delta(patch); - fprintf(fp, "<b>diff --git a/<a id=\"h%zu\" href=\"%sfile/", i, relpath); + fprintf(fp, "<b>diff --git a/<a id=\"h%zu\" href=\"%sfile/", i, baseurl); percentencode(fp, delta->old_file.path, strlen(delta->old_file.path)); fputs(".html\">", fp); xmlencode(fp, delta->old_file.path, strlen(delta->old_file.path)); - fprintf(fp, "</a> b/<a href=\"%sfile/", relpath); + fprintf(fp, "</a> b/<a href=\"%sfile/", baseurl); percentencode(fp, delta->new_file.path, strlen(delta->new_file.path)); fprintf(fp, ".html\">"); xmlencode(fp, delta->new_file.path, strlen(delta->new_file.path)); @@ -750,7 +749,7 @@ writelogline(FILE *fp, struct commitinfo *ci) printtimeshort(fp, &(ci->author->when)); fputs("</td><td>", fp); if (ci->summary) { - fprintf(fp, "<a href=\"%scommit/%s.html\">", relpath, ci->oid); + fprintf(fp, "<a href=\"%scommit/%s.html\">", baseurl, ci->oid); xmlencode(fp, ci->summary, strlen(ci->summary)); fputs("</a>", fp); } @@ -781,7 +780,6 @@ writelog(FILE *fp, const git_oid *oid) git_revwalk_push(w, oid); while (!git_revwalk_next(&id, w)) { - relpath = ""; if (cachefile && !memcmp(&id, &lastoid, sizeof(id))) break; @@ -817,7 +815,6 @@ writelog(FILE *fp, const git_oid *oid) /* check if file exists if so skip it */ if (r) { - relpath = "../"; fpfile = efopen(path, "w"); writeheader(fpfile, ci->summary); fputs("<pre>", fpfile); @@ -838,8 +835,6 @@ err: "</td></tr>\n", remcommits); } - relpath = ""; - return 0; } @@ -965,7 +960,6 @@ writeblob(git_object *obj, const char *fpath, const char *filename, size_t files if (*p == '/' && strlcat(tmp, "../", sizeof(tmp)) >= sizeof(tmp)) errx(1, "path truncated: '../%s'", tmp); } - relpath = tmp; fp = efopen(fpath, "w"); writeheader(fp, filename); @@ -983,8 +977,6 @@ writeblob(git_object *obj, const char *fpath, const char *filename, size_t files checkfileerror(fp, fpath, 'w'); fclose(fp); - relpath = ""; - return lc; } @@ -1074,7 +1066,7 @@ 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); + fprintf(fp, "</td><td><a href=\"%s", baseurl); percentencode(fp, filepath, strlen(filepath)); fputs("\">", fp); xmlencode(fp, entrypath, strlen(entrypath)); @@ -1088,7 +1080,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path) } else if (git_tree_entry_type(entry) == GIT_OBJ_COMMIT) { /* commit object in tree is a submodule */ fprintf(fp, "<tr><td>m---------</td><td><a href=\"%sfile/.gitmodules.html\">", - relpath); + baseurl); xmlencode(fp, entrypath, strlen(entrypath)); fputs("</a> @ ", fp); git_oid_tostr(oid, sizeof(oid), git_tree_entry_id(entry)); @@ -1197,7 +1189,7 @@ void usage(char *argv0) { fprintf(stderr, "usage: %s [-c cachefile | -l commits] " - "[-u baseurl] repodir\n", argv0); + "-u baseurl repodir\n", argv0); exit(1); } @@ -1239,6 +1231,8 @@ main(int argc, char *argv[]) } if (!repodir) usage(argv[0]); + if (!baseurl) + usage(argv[0]); if (!realpath(repodir, repodirabs)) err(1, "realpath"); @@ -1341,7 +1335,6 @@ main(int argc, char *argv[]) /* log for HEAD */ fp = efopen("log.html", "w"); - relpath = ""; mkdir("commit", S_IRWXU | S_IRWXG | S_IRWXO); writeheader(fp, "Log"); fputs("<table id=\"log\"><thead>\n<tr><td><b>Date</b></td>"