summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buffer.h7
-rw-r--r--src/diff_output.c34
2 files changed, 40 insertions, 1 deletions
diff --git a/src/buffer.h b/src/buffer.h
index 4efd240b5..6e73895b4 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -134,6 +134,13 @@ GIT_INLINE(ssize_t) git_buf_rfind(git_buf *buf, char ch)
return idx;
}
+GIT_INLINE(ssize_t) git_buf_find(git_buf *buf, char ch)
+{
+ size_t idx = 0;
+ while (idx < buf->size && buf->ptr[idx] != ch) idx++;
+ return (idx == buf->size) ? -1 : (ssize_t)idx;
+}
+
/* Remove whitespace from the end of the buffer */
void git_buf_rtrim(git_buf *buf);
diff --git a/src/diff_output.c b/src/diff_output.c
index 8a7a7a2a1..4f1064b7f 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -1501,6 +1501,39 @@ size_t git_diff_patch_num_hunks(git_diff_patch *patch)
return patch->hunks_size;
}
+int git_diff_patch_line_stats(
+ size_t *total_ctxt,
+ size_t *total_adds,
+ size_t *total_dels,
+ const git_diff_patch *patch)
+{
+ size_t totals[3], idx;
+
+ memset(totals, 0, sizeof(totals));
+
+ for (idx = 0; idx < patch->lines_size; ++idx) {
+ switch (patch->lines[idx].origin) {
+ case GIT_DIFF_LINE_CONTEXT: totals[0]++; break;
+ case GIT_DIFF_LINE_ADDITION: totals[1]++; break;
+ case GIT_DIFF_LINE_DELETION: totals[2]++; break;
+ default:
+ /* diff --stat and --numstat don't count EOFNL marks because
+ * they will always be paired with a ADDITION or DELETION line.
+ */
+ break;
+ }
+ }
+
+ if (total_ctxt)
+ *total_ctxt = totals[0];
+ if (total_adds)
+ *total_adds = totals[1];
+ if (total_dels)
+ *total_dels = totals[2];
+
+ return 0;
+}
+
int git_diff_patch_get_hunk(
const git_diff_range **range,
const char **header,
@@ -1706,4 +1739,3 @@ int git_diff__paired_foreach(
return 0;
}
-