detect more names for README and LICENSE
- for license: LICENSE, LICENSE.md, COPYING. - for readme: README, README.md.
1 files changed, 30 insertions(+), 16 deletions(-) | |||
---|---|---|---|
M | stagit.c | +30 | -16 |
1@@ -56,12 +56,16 @@ static char *name = "";
2 static char *strippedname = "";
3 static char description[255];
4 static char cloneurl[1024];
5-static int haslicense, hasreadme, hassubmodules;
6+static char *submodules;
7+static char *licensefiles[] = { "HEAD:LICENSE", "HEAD:LICENSE.md", "HEAD:COPYING" };
8+static char *license;
9+static char *readmefiles[] = { "HEAD:README", "HEAD:README.md" };
10+static char *readme;
11 static long long nlogcommits = -1; /* < 0 indicates not used */
12
13 /* cache */
14 static git_oid lastoid;
15-static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + nul byte */
16+static char lastoidstr[GIT_OID_HEXSZ + 2]; /* id + newline + NUL byte */
17 static FILE *rcachefp, *wcachefp;
18 static const char *cachefile;
19
20@@ -366,12 +370,15 @@ writeheader(FILE *fp, const char *title)
21 fprintf(fp, "<a href=\"%slog.html\">Log</a> | ", relpath);
22 fprintf(fp, "<a href=\"%sfiles.html\">Files</a> | ", relpath);
23 fprintf(fp, "<a href=\"%srefs.html\">Refs</a>", relpath);
24- if (hassubmodules)
25- fprintf(fp, " | <a href=\"%sfile/.gitmodules.html\">Submodules</a>", relpath);
26- if (hasreadme)
27- fprintf(fp, " | <a href=\"%sfile/README.html\">README</a>", relpath);
28- if (haslicense)
29- fprintf(fp, " | <a href=\"%sfile/LICENSE.html\">LICENSE</a>", relpath);
30+ if (submodules)
31+ fprintf(fp, " | <a href=\"%sfile/%s.html\">Submodules</a>",
32+ relpath, submodules);
33+ if (readme)
34+ fprintf(fp, " | <a href=\"%sfile/%s.html\">README</a>",
35+ relpath, readme);
36+ if (license)
37+ fprintf(fp, " | <a href=\"%sfile/%s.html\">LICENSE</a>",
38+ relpath, license);
39 fputs("</td></tr></table>\n<hr/>\n<div id=\"content\">\n", fp);
40 }
41
42@@ -1124,17 +1131,24 @@ main(int argc, char *argv[])
43 }
44
45 /* check LICENSE */
46- haslicense = (!git_revparse_single(&obj, repo, "HEAD:LICENSE") &&
47- git_object_type(obj) == GIT_OBJ_BLOB);
48- git_object_free(obj);
49+ for (i = 0; i < sizeof(licensefiles) / sizeof(*licensefiles) && !license; i++) {
50+ if (!git_revparse_single(&obj, repo, licensefiles[i]) &&
51+ git_object_type(obj) == GIT_OBJ_BLOB)
52+ license = licensefiles[i] + strlen("HEAD:");
53+ git_object_free(obj);
54+ }
55
56 /* check README */
57- hasreadme = (!git_revparse_single(&obj, repo, "HEAD:README") &&
58- git_object_type(obj) == GIT_OBJ_BLOB);
59- git_object_free(obj);
60+ for (i = 0; i < sizeof(readmefiles) / sizeof(*readmefiles) && !readme; i++) {
61+ if (!git_revparse_single(&obj, repo, readmefiles[i]) &&
62+ git_object_type(obj) == GIT_OBJ_BLOB)
63+ readme = readmefiles[i] + strlen("HEAD:");
64+ git_object_free(obj);
65+ }
66
67- hassubmodules = (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
68- git_object_type(obj) == GIT_OBJ_BLOB);
69+ if (!git_revparse_single(&obj, repo, "HEAD:.gitmodules") &&
70+ git_object_type(obj) == GIT_OBJ_BLOB)
71+ submodules = ".gitmodules";
72 git_object_free(obj);
73
74 /* log for HEAD */