]> git.armaanb.net Git - stagit.git/commitdiff
strip .git suffix from name
authorHiltjo Posthuma <hiltjo@codemadness.org>
Wed, 6 Jan 2016 19:00:38 +0000 (20:00 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Wed, 6 Jan 2016 19:06:06 +0000 (20:06 +0100)
also free stripped_name in the case of stagit-index

stagit-index.c
stagit.c

index e765732795ca879e33d37eb25ff211a968015328..3e546f8ab3c17bc34d8b9e01d1350a1e4f5f620f 100644 (file)
@@ -118,13 +118,13 @@ writeheader(FILE *fp)
 int
 writefooter(FILE *fp)
 {
-       return !fputs("</tbody></table></div></body>\n</html>", fp);
+       return !fputs("</tbody>\n</table>\n</div>\n</body>\n</html>\n", fp);
 }
 
 int
 writelog(FILE *fp)
 {
-       char *stripped_name, *p;
+       char *stripped_name = NULL, *p;
        git_commit *commit = NULL;
        const git_signature *author;
        git_revwalk *w = NULL;
@@ -144,18 +144,17 @@ writelog(FILE *fp)
 
        author = git_commit_author(commit);
 
-       fputs("<tr><td><a href=\"", fp);
-       xmlencode(fp, name, strlen(name));
-       fputs("/log.html\">", fp);
-
        /* strip .git suffix */
        if (!(stripped_name = strdup(name)))
                err(1, "strdup");
        if ((p = strrchr(stripped_name, '.')))
                if (!strcmp(p, ".git"))
                        *p = '\0';
-       xmlencode(fp, stripped_name, strlen(stripped_name));
 
+       fputs("<tr><td><a href=\"", fp);
+       xmlencode(fp, stripped_name, strlen(stripped_name));
+       fputs("/log.html\">", fp);
+       xmlencode(fp, stripped_name, strlen(stripped_name));
        fputs("</a></td><td>", fp);
        xmlencode(fp, description, strlen(description));
        fputs("</td><td>", fp);
@@ -168,6 +167,7 @@ writelog(FILE *fp)
        git_commit_free(commit);
 err:
        git_revwalk_free(w);
+       free(stripped_name);
 
        return ret;
 }
index 7cab2109cc9f1cd1fad149a09ad654e209c8f4a5..f20f22794bbe5d8d312ac969aed6e9884bfb4bd9 100644 (file)
--- a/stagit.c
+++ b/stagit.c
@@ -42,7 +42,8 @@ static git_repository *repo;
 static const char *relpath = "";
 static const char *repodir;
 
-static char name[255];
+static char *name;
+static char *stripped_name;
 static char description[255];
 static char cloneurl[1024];
 static int hasreadme, haslicense;
@@ -239,7 +240,7 @@ writeheader(FILE *fp)
                "<html dir=\"ltr\" lang=\"en\">\n<head>\n"
                "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
                "<meta http-equiv=\"Content-Language\" content=\"en\" />\n<title>", fp);
-       xmlencode(fp, name, strlen(name));
+       xmlencode(fp, stripped_name, strlen(stripped_name));
        if (description[0])
                fputs(" - ", fp);
        xmlencode(fp, description, strlen(description));
@@ -251,7 +252,7 @@ writeheader(FILE *fp)
        fprintf(fp, "<a href=\"../%s\"><img src=\"%slogo.png\" alt=\"\" width=\"32\" height=\"32\" /></a>",
                relpath, relpath);
        fputs("</td><td><h1>", fp);
-       xmlencode(fp, name, strlen(name));
+       xmlencode(fp, stripped_name, strlen(stripped_name));
        fputs("</h1><span class=\"desc\">", fp);
        xmlencode(fp, description, strlen(description));
        fputs("</span></td></tr>", fp);
@@ -553,9 +554,8 @@ writeatom(FILE *fp)
 
        fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
              "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n<title>", fp);
-       xmlencode(fp, name, strlen(name));
-       fputs(", branch master</title>\n<subtitle>", fp);
-
+       xmlencode(fp, stripped_name, strlen(stripped_name));
+       fputs(", branch HEAD</title>\n<subtitle>", fp);
        xmlencode(fp, description, strlen(description));
        fputs("</subtitle>\n", fp);
 
@@ -914,9 +914,14 @@ main(int argc, char *argv[])
        }
 
        /* use directory name as name */
-       p = xbasename(repodir);
-       snprintf(name, sizeof(name), "%s", p);
-       free(p);
+       name = xbasename(repodir);
+
+       /* strip .git suffix */
+       if (!(stripped_name = strdup(name)))
+               err(1, "strdup");
+       if ((p = strrchr(stripped_name, '.')))
+               if (!strcmp(p, ".git"))
+                       *p = '\0';
 
        /* read description or .git/description */
        snprintf(path, sizeof(path), "%s%s%s",