]> git.armaanb.net Git - stagit.git/commitdiff
add diffstat
authorHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 7 Dec 2015 13:26:35 +0000 (14:26 +0100)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Mon, 7 Dec 2015 13:26:35 +0000 (14:26 +0100)
urmoms.c

index cc7e400b2a8be04c53fd871ab65620e4c12a66d3..6928524f7aad371dd70e608b2540c0f00d260c1e 100644 (file)
--- a/urmoms.c
+++ b/urmoms.c
@@ -186,16 +186,19 @@ printshowfile(git_commit *commit)
        git_tree *commit_tree = NULL, *parent_tree = NULL;
        git_patch *patch = NULL;
        git_diff *diff = NULL;
+       git_buf diffstatsbuf;
+       git_diff_stats *diffstats = NULL;
        size_t i, j, k, ndeltas, nhunks = 0, nhunklines = 0;
        char buf[GIT_OID_HEXSZ + 1], path[PATH_MAX];
        FILE *fp;
        int error;
 
        git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
-
        snprintf(path, sizeof(path), "commit/%s.html", buf);
        fp = efopen(path, "w+b");
 
+       memset(&diffstatsbuf, 0, sizeof(diffstatsbuf));
+
        writeheader(fp);
        printcommit(fp, commit);
 
@@ -205,16 +208,25 @@ printshowfile(git_commit *commit)
 
        error = git_commit_tree(&commit_tree, commit);
        if (error)
-               return;
+               goto err;
        error = git_commit_tree(&parent_tree, parent);
        if (error)
-               return;
-
+               goto err;
        error = git_diff_tree_to_tree(&diff, repo, commit_tree, parent_tree, NULL);
        if (error)
-               return;
-
-       /* TODO: diff stat (files list and insertions/deletions) */
+               goto err;
+
+       /* diff stat */
+       if (!git_diff_get_stats(&diffstats, diff)) {
+               if (!git_diff_stats_to_buf(&diffstatsbuf, diffstats,
+                       GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_SHORT | GIT_DIFF_STATS_NUMBER | GIT_DIFF_STATS_INCLUDE_SUMMARY, 80)) {
+                       fputs("<hr/>", fp);
+                       fprintf(fp, "Diffstat:\n");
+                       fputs(diffstatsbuf.ptr, fp);
+               }
+               git_diff_stats_free(diffstats);
+       }
+       fputs("<hr/>", fp);
 
        ndeltas = git_diff_num_deltas(diff);
        for (i = 0; i < ndeltas; i++) {
@@ -262,6 +274,11 @@ printshowfile(git_commit *commit)
 
        writefooter(fp);
        fclose(fp);
+       return;
+
+err:
+       git_buf_free(&diffstatsbuf);
+       fclose(fp);
 }
 
 int