strip .git suffix from name
also free stripped_name in the case of stagit-index
2 files changed, 21 insertions(+), 16 deletions(-) | |||
---|---|---|---|
M | stagit-index.c | +7 | -7 |
M | stagit.c | +14 | -9 |
1@@ -118,13 +118,13 @@ writeheader(FILE *fp)
2 int
3 writefooter(FILE *fp)
4 {
5- return !fputs("</tbody></table></div></body>\n</html>", fp);
6+ return !fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp);
7 }
8
9 int
10 writelog(FILE *fp)
11 {
12- char *stripped_name, *p;
13+ char *stripped_name = NULL, *p;
14 git_commit *commit = NULL;
15 const git_signature *author;
16 git_revwalk *w = NULL;
17@@ -144,18 +144,17 @@ writelog(FILE *fp)
18
19 author = git_commit_author(commit);
20
21- fputs("<tr><td><a href=\"", fp);
22- xmlencode(fp, name, strlen(name));
23- fputs("/log.html\">", fp);
24-
25 /* strip .git suffix */
26 if (!(stripped_name = strdup(name)))
27 err(1, "strdup");
28 if ((p = strrchr(stripped_name, '.')))
29 if (!strcmp(p, ".git"))
30 *p = '\0';
31- xmlencode(fp, stripped_name, strlen(stripped_name));
32
33+ fputs("<tr><td><a href=\"", fp);
34+ xmlencode(fp, stripped_name, strlen(stripped_name));
35+ fputs("/log.html\">", fp);
36+ xmlencode(fp, stripped_name, strlen(stripped_name));
37 fputs("</a></td><td>", fp);
38 xmlencode(fp, description, strlen(description));
39 fputs("</td><td>", fp);
40@@ -168,6 +167,7 @@ writelog(FILE *fp)
41 git_commit_free(commit);
42 err:
43 git_revwalk_free(w);
44+ free(stripped_name);
45
46 return ret;
47 }
M · stagit.c
+14, -9 1@@ -42,7 +42,8 @@ static git_repository *repo;
2 static const char *relpath = "";
3 static const char *repodir;
4
5-static char name[255];
6+static char *name;
7+static char *stripped_name;
8 static char description[255];
9 static char cloneurl[1024];
10 static int hasreadme, haslicense;
11@@ -239,7 +240,7 @@ writeheader(FILE *fp)
12 "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
13 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
14 "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
15- xmlencode(fp, name, strlen(name));
16+ xmlencode(fp, stripped_name, strlen(stripped_name));
17 if (description[0])
18 fputs(" - ", fp);
19 xmlencode(fp, description, strlen(description));
20@@ -251,7 +252,7 @@ writeheader(FILE *fp)
21 fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
22 relpath, relpath);
23 fputs("</td><td><h1>", fp);
24- xmlencode(fp, name, strlen(name));
25+ xmlencode(fp, stripped_name, strlen(stripped_name));
26 fputs("</h1><span class=\"desc\">", fp);
27 xmlencode(fp, description, strlen(description));
28 fputs("</span></td></tr>", fp);
29@@ -553,9 +554,8 @@ writeatom(FILE *fp)
30
31 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
32 "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
33- xmlencode(fp, name, strlen(name));
34- fputs(", branch master</title>\n<subtitle>", fp);
35-
36+ xmlencode(fp, stripped_name, strlen(stripped_name));
37+ fputs(", branch HEAD</title>\n<subtitle>", fp);
38 xmlencode(fp, description, strlen(description));
39 fputs("</subtitle>\n", fp);
40
41@@ -914,9 +914,14 @@ main(int argc, char *argv[])
42 }
43
44 /* use directory name as name */
45- p = xbasename(repodir);
46- snprintf(name, sizeof(name), "%s", p);
47- free(p);
48+ name = xbasename(repodir);
49+
50+ /* strip .git suffix */
51+ if (!(stripped_name = strdup(name)))
52+ err(1, "strdup");
53+ if ((p = strrchr(stripped_name, '.')))
54+ if (!strcmp(p, ".git"))
55+ *p = '\0';
56
57 /* read description or .git/description */
58 snprintf(path, sizeof(path), "%s%s%s",