stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
84bb2212e86c54f67dc18cf803bd2ac6edf24804
parent
8c45dfc58edc069a3787224f522c7f62da501a80
Author
Hiltjo Posthuma <hiltjo@codemadness.org>
Date
2018-11-11 17:23
detect more names for README and LICENSE

- for license: LICENSE, LICENSE.md, COPYING.
- for readme: README, README.md.

Diffstat

M stagit.c 46 ++++++++++++++++++++++++++++++----------------

1 files changed, 30 insertions, 16 deletions


diff --git a/stagit.c b/stagit.c

@@ -56,12 +56,16 @@ static char *name = "";
   56    56 static char *strippedname = "";
   57    57 static char description[255];
   58    58 static char cloneurl[1024];
   59    -1 static int haslicense, hasreadme, hassubmodules;
   -1    59 static char *submodules;
   -1    60 static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" };
   -1    61 static char *license;
   -1    62 static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" };
   -1    63 static char *readme;
   60    64 static long long nlogcommits = -1; /* < 0 indicates not used */
   61    65 
   62    66 /* cache */
   63    67 static git_oid lastoid;
   64    -1 static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
   -1    68 static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */
   65    69 static FILE *rcachefp, *wcachefp;
   66    70 static const char *cachefile;
   67    71 
@@ -366,12 +370,15 @@ writeheader(FILE *fp, const char *title)
  366   370 	fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
  367   371 	fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
  368   372 	fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
  369    -1 	if (hassubmodules)
  370    -1 		fprintf(fp, " | <a href=\"%sfile/.gitmodules.html\">Submodules</a>", relpath);
  371    -1 	if (hasreadme)
  372    -1 		fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
  373    -1 	if (haslicense)
  374    -1 		fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
   -1   373 	if (submodules)
   -1   374 		fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>",
   -1   375 		        relpath, submodules);
   -1   376 	if (readme)
   -1   377 		fprintf(fp, " | <a href=\"%sfile/%s.html\">README</a>",
   -1   378 		        relpath, readme);
   -1   379 	if (license)
   -1   380 		fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>",
   -1   381 		        relpath, license);
  375   382 	fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
  376   383 }
  377   384 
@@ -1124,17 +1131,24 @@ main(int argc, char *argv[])
 1124  1131 	}
 1125  1132 
 1126  1133 	/* check LICENSE */
 1127    -1 	haslicense = (!git_revparse_single(&obj, repo, "HEAD:LICENSE") &&
 1128    -1 		git_object_type(obj) == GIT_OBJ_BLOB);
 1129    -1 	git_object_free(obj);
   -1  1134 	for (i = 0; i < sizeof(licensefiles) / sizeof(*licensefiles) && !license; i++) {
   -1  1135 		if (!git_revparse_single(&obj, repo, licensefiles[i]) &&
   -1  1136 		    git_object_type(obj) == GIT_OBJ_BLOB)
   -1  1137 			license = licensefiles[i] + strlen("HEAD:");
   -1  1138 		git_object_free(obj);
   -1  1139 	}
 1130  1140 
 1131  1141 	/* check README */
 1132    -1 	hasreadme = (!git_revparse_single(&obj, repo, "HEAD:README") &&
 1133    -1 		git_object_type(obj) == GIT_OBJ_BLOB);
 1134    -1 	git_object_free(obj);
   -1  1142 	for (i = 0; i < sizeof(readmefiles) / sizeof(*readmefiles) && !readme; i++) {
   -1  1143 		if (!git_revparse_single(&obj, repo, readmefiles[i]) &&
   -1  1144 		    git_object_type(obj) == GIT_OBJ_BLOB)
   -1  1145 			readme = readmefiles[i] + strlen("HEAD:");
   -1  1146 		git_object_free(obj);
   -1  1147 	}
 1135  1148 
 1136    -1 	hassubmodules = (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
 1137    -1 		git_object_type(obj) == GIT_OBJ_BLOB);
   -1  1149 	if (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
   -1  1150 	    git_object_type(obj) == GIT_OBJ_BLOB)
   -1  1151 		submodules = ".gitmodules";
 1138  1152 	git_object_free(obj);
 1139  1153 
 1140  1154 	/* log for HEAD */