stagit

add diffstat

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 94ed934 parent: 69650ca
1 files changed, 24 insertions(+), 7 deletions(-)
Murmoms.c+24-7
M · urmoms.c +24, -7
 1@@ -186,16 +186,19 @@ printshowfile(git_commit *commit)
 2 	git_tree *commit_tree = NULL, *parent_tree = NULL;
 3 	git_patch *patch = NULL;
 4 	git_diff *diff = NULL;
 5+	git_buf diffstatsbuf;
 6+	git_diff_stats *diffstats = NULL;
 7 	size_t i, j, k, ndeltas, nhunks = 0, nhunklines = 0;
 8 	char buf[GIT_OID_HEXSZ + 1], path[PATH_MAX];
 9 	FILE *fp;
10 	int error;
11 
12 	git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
13-
14 	snprintf(path, sizeof(path), "commit/%s.html", buf);
15 	fp = efopen(path, "w+b");
16 
17+	memset(&diffstatsbuf, 0, sizeof(diffstatsbuf));
18+
19 	writeheader(fp);
20 	printcommit(fp, commit);
21 
22@@ -205,16 +208,25 @@ printshowfile(git_commit *commit)
23 
24 	error = git_commit_tree(&commit_tree, commit);
25 	if (error)
26-		return;
27+		goto err;
28 	error = git_commit_tree(&parent_tree, parent);
29 	if (error)
30-		return;
31-
32+		goto err;
33 	error = git_diff_tree_to_tree(&diff, repo, commit_tree, parent_tree, NULL);
34 	if (error)
35-		return;
36-
37-	/* TODO: diff stat (files list and insertions/deletions) */
38+		goto err;
39+
40+	/* diff stat */
41+	if (!git_diff_get_stats(&diffstats, diff)) {
42+		if (!git_diff_stats_to_buf(&diffstatsbuf, diffstats,
43+			GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT | GIT_DIFF_STATS_NUMBER | GIT_DIFF_STATS_INCLUDE_SUMMARY, 80)) {
44+			fputs("<hr/>", fp);
45+			fprintf(fp, "Diffstat:\n");
46+			fputs(diffstatsbuf.ptr, fp);
47+		}
48+		git_diff_stats_free(diffstats);
49+	}
50+	fputs("<hr/>", fp);
51 
52 	ndeltas = git_diff_num_deltas(diff);
53 	for (i = 0; i < ndeltas; i++) {
54@@ -262,6 +274,11 @@ printshowfile(git_commit *commit)
55 
56 	writefooter(fp);
57 	fclose(fp);
58+	return;
59+
60+err:
61+	git_buf_free(&diffstatsbuf);
62+	fclose(fp);
63 }
64 
65 int