commit b627be363892c3b6d4116a4d5b14a9686c99b895
parent 3d8aaa4d4036a07e8e768b24fa23cc9cd763798a
Author: gearsix <gearsix@tuta.io>
Date: Thu, 15 Apr 2021 22:34:33 +0100
bugfixes to .git/fork support
- added relevant dir to "cannot open repo" error
Diffstat:
2 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/stagit-index.c b/stagit-index.c
@@ -75,20 +75,20 @@ writeheader(FILE *fp)
xmlencode(fp, description, strlen(description));
fprintf(fp, "</title>\n<link rel=\"icon\" type=\"image/png\" href=\"%sfavicon.png\" />\n", rootpath);
fprintf(fp, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%sstyle.css\" />\n", rootpath);
- fputs("</head></body>\n", fp);
-}
-
-void
-writebodyhead(FILE *fp) {
- fprintf(fp, "<<table>\n<tr><td id=\"logo\"><img src=\"%slogo.png\" alt=\"\" width=\"49\" height=\"50\" /></td>\n"
+ fputs("</head><body>\n", fp);
+ fprintf(fp, "<table>\n<tr><td id=\"logo\"><img src=\"%slogo.png\" alt=\"\" width=\"49\" height=\"50\" /></td>\n"
"<td><span class=\"desc\">", rootpath);
xmlencode(fp, description, strlen(description));
fputs("</span>", fp);
if (contact && strlen(contact) > -1) {
fprintf(fp, "<br/><span class=\"contact\"><b>contact:</b> %s</span>", contact);
}
- fputs("</td></tr>\n</table>\n<hr/>\n<div id=\"content\">\n"
- "<table id=\"index\"><thead>\n"
+ fputs("</td></tr>\n</table>\n<hr/>\n<div id=\"content\">\n", fp);
+}
+
+void
+writebodyhead(FILE *fp) {
+ fputs("<table class=\"index\"><thead>\n"
"<tr><td><b>Name</b></td><td><b>Description</b></td><td><b>Owner</b></td>"
"<td><b>Last commit</b></td></tr>"
"</thead><tbody>\n", fp);
@@ -158,10 +158,11 @@ writebody(FILE *fp, char *repodir, int forks) {
if (git_repository_open_ext(&repo, repodir,
GIT_REPOSITORY_OPEN_NO_SEARCH, NULL)) {
- fprintf(stderr, "%s: cannot open repository\n", binary);
+ fprintf(stderr, "%s: cannot open repository '%s'\n", binary, repodir);
return 1;
}
+ // check .git/fork
if (forks != 2) {
joinpath(path, sizeof(path), repodir, ".git/fork");
fp = fopen(path, "r");
@@ -207,13 +208,13 @@ writebody(FILE *fp, char *repodir, int forks) {
void
writebodyfoot(FILE *fp)
{
- fputs("</tbody>\n</table>\n</div>\n", fp);
+ fputs("</tbody>\n</table></details>\n", fp);
}
void
writefooter(FILE *fp)
{
- fputs("</body>\n</html>\n", fp);
+ fputs("</div>\n</body>\n</html>\n", fp);
}
int
@@ -238,17 +239,18 @@ main(int argc, char *argv[])
writeheader(stdout);
+ fputs("<details open><summary><b>orignal</b></summary>", stdout);
writebodyhead(stdout);
- for (i = 0; i < argc; i++) {
+ for (i = 1; i < argc; i++) {
ret = writebody(stdout, argv[i], 0);
if (ret != 0)
return ret;
}
writebodyfoot(stdout);
- fputs("<details><summary>forks</summary>", stdout);
+ fputs("<details open><summary><b>forks</b></summary>", stdout);
writebodyhead(stdout);
- for (i = 0; i < argc; i++) {
+ for (i = 1; i < argc; i++) {
ret = writebody(stdout, argv[i], 1);
if (ret != 0)
return ret;
diff --git a/stagit.c b/stagit.c
@@ -66,6 +66,7 @@ static const char *repodir;
static char *name = "";
static char *strippedname = "";
static char description[255];
+static char forked[255];
static char cloneurl[1024];
static char *submodules;
static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" };
@@ -491,6 +492,7 @@ writeheader(FILE *fp, const char *title)
xmlencode(fp, strippedname, strlen(strippedname));
fputs("</h1><span class=\"desc\">", fp);
xmlencode(fp, description, strlen(description));
+ fputs(forked, fp);
fputs("</span></td></tr>", fp);
if (cloneurl[0]) {
fputs("<tr class=\"url\"><td></td><td>git clone <a href=\"", fp);
@@ -875,6 +877,7 @@ writeatom(FILE *fp, int all)
xmlencode(fp, strippedname, strlen(strippedname));
fputs(", branch HEAD</title>\n<subtitle>", fp);
xmlencode(fp, description, strlen(description));
+ fputs(forked, fp);
fputs("</subtitle>\n", fp);
/* all commits or only tags? */
@@ -1160,7 +1163,7 @@ main(int argc, char *argv[])
FILE *fp, *fpread;
char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
char tmppath[64] = "cache.XXXXXXXXXXXX", buf[BUFSIZ];
- char pre[20], url[235];
+ char url[100];
size_t n;
int i, fd;
@@ -1253,20 +1256,10 @@ main(int argc, char *argv[])
if (fpread = fopen(path, "r")) {
if (fgets(url, sizeof(url), fpread)) {
if (strlen(description) == 0)
- snprintf(pre, 20, "forked from <a href=\"");
+ snprintf(forked, 127, "forked from <a href=\"%s\">%s</a>", url, url);
else
- snprintf(pre, 20, ", forked form <a href=\"");
-
- if (strlen(description) + strlen(pre) + strlen(url) < 255) {
- strncat(description, pre, strlen(pre));
- strncat(description, url, strlen(url));
- }
-
- strncat(description, "</a>", 5);
+ snprintf(forked, 127, ", forked from <a href=\"%s\">%s</a>", url, url);
}
-
- url[0] = '\0';
- pre[0] = '\0';
}
/* read url or .git/url */