add diffstat - stagit-gopher - A git gopher frontend. (mirror)
git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
Log
Files
Refs
Tags
README
LICENSE
---
commit beb7a3b29dd88515a3bcb294a4e58907b0406355
parent a95a439aaa7d048c25e988b0d9770f5040f0a17f
Author: Hiltjo Posthuma 
Date:   Mon,  7 Dec 2015 14:26:35 +0100

add diffstat

Diffstat:
  M urmoms.c                            |      31 ++++++++++++++++++++++++-------

1 file changed, 24 insertions(+), 7 deletions(-)
---
diff --git 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("
", fp); + fprintf(fp, "Diffstat:\n"); + fputs(diffstatsbuf.ptr, fp); + } + git_diff_stats_free(diffstats); + } + fputs("
", 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