]> git.armaanb.net Git - stagit.git/commitdiff
make printshowfile more generic and like other functions
authorHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 23 Feb 2016 19:37:17 +0000 (20:37 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Tue, 23 Feb 2016 19:37:17 +0000 (20:37 +0100)
TODO
stagit.c

diff --git a/TODO b/TODO
index a8cde7aea86cfc9bc7f9200d23a291c5ccd5d8ce..5e017df950fe98c6b835865e2cbdfc2b1db7c19c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+check path truncation? snprintf(), strlcpy.
+
 performance:
 - optimize git_diff_get_stats.
 - speed up generating files.
index 4d967e9908932262718a9aef794e842f71c4e7b8..fd9e9379bfe67f88afdcabe3df1568f8fefe47d5 100644 (file)
--- a/stagit.c
+++ b/stagit.c
@@ -340,7 +340,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
 }
 
 void
-printshowfile(struct commitinfo *ci)
+printshowfile(FILE *fp, struct commitinfo *ci)
 {
        const git_diff_delta *delta;
        const git_diff_hunk *hunk;
@@ -348,18 +348,8 @@ printshowfile(struct commitinfo *ci)
        git_patch *patch;
        git_buf statsbuf;
        size_t ndeltas, nhunks, nhunklines;
-       FILE *fp;
        size_t i, j, k;
-       char path[PATH_MAX];
 
-       snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
-       /* check if file exists if so skip it */
-       if (!access(path, F_OK))
-               return;
-
-       fp = efopen(path, "w");
-       writeheader(fp);
-       fputs("<pre>", fp);
        printcommit(fp, ci);
 
        memset(&statsbuf, 0, sizeof(statsbuf));
@@ -424,9 +414,6 @@ printshowfile(struct commitinfo *ci)
        }
        git_buf_free(&statsbuf);
 
-       fputs("</pre>\n", fp);
-       writefooter(fp);
-       fclose(fp);
        return;
 }
 
@@ -437,6 +424,8 @@ writelog(FILE *fp, const git_oid *oid)
        git_revwalk *w = NULL;
        git_oid id;
        size_t len;
+       char path[PATH_MAX];
+       FILE *fpfile;
 
        git_revwalk_new(&w, repo);
        git_revwalk_push(w, oid);
@@ -479,8 +468,18 @@ writelog(FILE *fp, const git_oid *oid)
                fputs("</td></tr>\n", fp);
 
                relpath = "../";
-               printshowfile(ci);
 
+               snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
+               /* check if file exists if so skip it */
+               if (access(path, F_OK)) {
+                       fpfile = efopen(path, "w");
+                       writeheader(fpfile);
+                       fputs("<pre>", fpfile);
+                       printshowfile(fpfile, ci);
+                       fputs("</pre>\n", fpfile);
+                       writefooter(fpfile);
+                       fclose(fpfile);
+               }
                commitinfo_free(ci);
        }
        fputs("</tbody></table>", fp);