stagit

stagit fork
git clone git://git.mdnr.space/stagit
Log | Files | Refs | README | LICENSE

commit 4b0b6ea613c456a0fdbccfc0531f5e0bfc00964e
parent 8e4f447ebf6a06613e00cd4d82fd2e612c144eb6
Author: mdnrz <mehdeenoroozi@gmail.com>
Date:   Sun, 14 Dec 2025 18:10:39 +0330

open README as the default page

Diffstat:
Mstagit-index.c | 21+++++++++++++++++++--
Mstagit.c | 6+++---
2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/stagit-index.c b/stagit-index.c @@ -8,6 +8,8 @@ #include <git2.h> +#define LEN(s) (sizeof(s)/sizeof(*s)) + static git_repository *repo; static const char *relpath = ""; @@ -16,6 +18,9 @@ static char description[255] = "Repositories"; static char *name = ""; static char owner[255]; +static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" }; +static char *readme; + /* Handle read or write errors for a FILE * stream */ void checkfileerror(FILE *fp, const char *name, int mode) @@ -152,7 +157,8 @@ writelog(FILE *fp) fputs("<tr><td><a href=\"", fp); percentencode(fp, stripped_name, strlen(stripped_name)); - fputs("/log.html\">", fp); + if (readme) fprintf(fp, "/file/%s.html\">", readme); + else fputs("/log.html\">", fp); xmlencode(fp, stripped_name, strlen(stripped_name)); fputs("</a></td><td>", fp); xmlencode(fp, description, strlen(description)); @@ -175,9 +181,10 @@ int main(int argc, char *argv[]) { FILE *fp; + git_object *obj = NULL; char path[PATH_MAX], repodirabs[PATH_MAX + 1]; const char *repodir; - int i, ret = 0; + int i, j, ret = 0; if (argc < 2) { fprintf(stderr, "usage: %s [repodir...]\n", argv[0]); @@ -245,7 +252,17 @@ main(int argc, char *argv[]) fclose(fp); owner[strcspn(owner, "\n")] = '\0'; } + + /* check README */ + for (j = 0; j < LEN(readmefiles) && !readme; j++) { + if (!git_revparse_single(&obj, repo, readmefiles[j]) && + git_object_type(obj) == GIT_OBJ_BLOB) + readme = readmefiles[j] + strlen("HEAD:"); + git_object_free(obj); + } + writelog(stdout); + if (readme) readme = NULL; } writefooter(stdout); diff --git a/stagit.c b/stagit.c @@ -535,15 +535,15 @@ writeheader(FILE *fp, const char *title) fputs("</a></td></tr>", fp); } fputs("<tr><td></td><td>\n", fp); + if (readme) + fprintf(fp, "<a href=\"%sfile/%s.html\">README</a> | ", + relpath, readme); 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); if (submodules) fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>", relpath, submodules); - if (readme) - fprintf(fp, " | <a href=\"%sfile/%s.html\">README</a>", - relpath, readme); if (license) fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>", relpath, license);