stagit

make printshowfile more generic and like other functions

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 3abcea0 parent: b4ce68e
2 files changed, 16 insertions(+), 15 deletions(-)
MTODO+2-0
Mstagit.c+14-15
M · TODO +2, -0
1@@ -1,3 +1,5 @@
2+check path truncation? snprintf(), strlcpy.
3+
4 performance:
5 - optimize git_diff_get_stats.
6 - speed up generating files.
M · stagit.c +14, -15
 1@@ -340,7 +340,7 @@ printcommit(FILE *fp, struct commitinfo *ci)
 2 }
 3 
 4 void
 5-printshowfile(struct commitinfo *ci)
 6+printshowfile(FILE *fp, struct commitinfo *ci)
 7 {
 8 	const git_diff_delta *delta;
 9 	const git_diff_hunk *hunk;
10@@ -348,18 +348,8 @@ printshowfile(struct commitinfo *ci)
11 	git_patch *patch;
12 	git_buf statsbuf;
13 	size_t ndeltas, nhunks, nhunklines;
14-	FILE *fp;
15 	size_t i, j, k;
16-	char path[PATH_MAX];
17 
18-	snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
19-	/* check if file exists if so skip it */
20-	if (!access(path, F_OK))
21-		return;
22-
23-	fp = efopen(path, "w");
24-	writeheader(fp);
25-	fputs("<pre>", fp);
26 	printcommit(fp, ci);
27 
28 	memset(&statsbuf, 0, sizeof(statsbuf));
29@@ -424,9 +414,6 @@ printshowfile(struct commitinfo *ci)
30 	}
31 	git_buf_free(&statsbuf);
32 
33-	fputs("</pre>\n", fp);
34-	writefooter(fp);
35-	fclose(fp);
36 	return;
37 }
38 
39@@ -437,6 +424,8 @@ writelog(FILE *fp, const git_oid *oid)
40 	git_revwalk *w = NULL;
41 	git_oid id;
42 	size_t len;
43+	char path[PATH_MAX];
44+	FILE *fpfile;
45 
46 	git_revwalk_new(&w, repo);
47 	git_revwalk_push(w, oid);
48@@ -479,8 +468,18 @@ writelog(FILE *fp, const git_oid *oid)
49 		fputs("</td></tr>\n", fp);
50 
51 		relpath = "../";
52-		printshowfile(ci);
53 
54+		snprintf(path, sizeof(path), "commit/%s.html", ci->oid);
55+		/* check if file exists if so skip it */
56+		if (access(path, F_OK)) {
57+			fpfile = efopen(path, "w");
58+			writeheader(fpfile);
59+			fputs("<pre>", fpfile);
60+			printshowfile(fpfile, ci);
61+			fputs("</pre>\n", fpfile);
62+			writefooter(fpfile);
63+			fclose(fpfile);
64+		}
65 		commitinfo_free(ci);
66 	}
67 	fputs("</tbody></table>", fp);