aboutsummaryrefslogtreecommitdiffstats
path: root/stagit.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <[email protected]>2018-11-11 18:23:28 +0100
committerHiltjo Posthuma <[email protected]>2018-11-11 19:12:55 +0100
commit84bb2212e86c54f67dc18cf803bd2ac6edf24804 (patch)
treed370cec9faa1d3236c09334df373b56e197b21ca /stagit.c
parent8c45dfc58edc069a3787224f522c7f62da501a80 (diff)
downloadstagit-84bb2212e86c54f67dc18cf803bd2ac6edf24804.tar.gz
stagit-84bb2212e86c54f67dc18cf803bd2ac6edf24804.zip
detect more names for README and LICENSE
- for license: LICENSE, LICENSE.md, COPYING. - for readme: README, README.md.
Diffstat (limited to 'stagit.c')
-rw-r--r--stagit.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/stagit.c b/stagit.c
index 90fd7d1..f43801d 100644
--- a/stagit.c
+++ b/stagit.c
@@ -56,12 +56,16 @@ static char *name = "";
static char *strippedname = "";
static char description[255];
static char cloneurl[1024];
-static int haslicense, hasreadme, hassubmodules;
+static char *submodules;
+static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" };
+static char *license;
+static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" };
+static char *readme;
static long long nlogcommits = -1; /* < 0 indicates not used */
/* cache */
static git_oid lastoid;
-static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
+static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */
static FILE *rcachefp, *wcachefp;
static const char *cachefile;
@@ -366,12 +370,15 @@ writeheader(FILE *fp, const char *title)
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 (hassubmodules)
- fprintf(fp, " | <a href=\"%sfile/.gitmodules.html\">Submodules</a>", relpath);
- if (hasreadme)
- fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
- if (haslicense)
- fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</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);
fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
}
@@ -1124,17 +1131,24 @@ main(int argc, char *argv[])
}
/* check LICENSE */
- haslicense = (!git_revparse_single(&obj, repo, "HEAD:LICENSE") &&
- git_object_type(obj) == GIT_OBJ_BLOB);
- git_object_free(obj);
+ for (i = 0; i < sizeof(licensefiles) / sizeof(*licensefiles) && !license; i++) {
+ if (!git_revparse_single(&obj, repo, licensefiles[i]) &&
+ git_object_type(obj) == GIT_OBJ_BLOB)
+ license = licensefiles[i] + strlen("HEAD:");
+ git_object_free(obj);
+ }
/* check README */
- hasreadme = (!git_revparse_single(&obj, repo, "HEAD:README") &&
- git_object_type(obj) == GIT_OBJ_BLOB);
- git_object_free(obj);
+ for (i = 0; i < sizeof(readmefiles) / sizeof(*readmefiles) && !readme; i++) {
+ if (!git_revparse_single(&obj, repo, readmefiles[i]) &&
+ git_object_type(obj) == GIT_OBJ_BLOB)
+ readme = readmefiles[i] + strlen("HEAD:");
+ git_object_free(obj);
+ }
- hassubmodules = (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
- git_object_type(obj) == GIT_OBJ_BLOB);
+ if (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
+ git_object_type(obj) == GIT_OBJ_BLOB)
+ submodules = ".gitmodules";
git_object_free(obj);
/* log for HEAD */