diff options
author | Russell Belfer <rb@github.com> | 2013-07-23 03:07:56 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-07-23 03:07:56 +0400 |
commit | b4a4cf24a539ce07d86fed6835c98154fb40e723 (patch) | |
tree | 74e8807bc0993d480ed38278b4f41cfde83da641 /src/diff_patch.c | |
parent | 1cd9dc29b7105cb33959d15ab670a085f5a1445b (diff) |
Add git_diff_patch_size() API
This adds a new API to get the size in bytes of the diffs in a
git_diff_patch object.
Diffstat (limited to 'src/diff_patch.c')
-rw-r--r-- | src/diff_patch.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/diff_patch.c b/src/diff_patch.c index 1b4adac03..5febc883c 100644 --- a/src/diff_patch.c +++ b/src/diff_patch.c @@ -42,7 +42,7 @@ struct git_diff_patch { git_array_t(diff_patch_hunk) hunks; git_array_t(diff_patch_line) lines; size_t oldno, newno; - size_t content_size; + size_t content_size, context_size; git_pool flattened; }; @@ -806,6 +806,20 @@ notfound: return diff_error_outofrange(thing); } +size_t git_diff_patch_size(git_diff_patch *patch, int include_context) +{ + size_t out; + + assert(patch); + + out = patch->content_size; + + if (!include_context) + out -= patch->context_size; + + return out; +} + git_diff_list *git_diff_patch__diff(git_diff_patch *patch) { return patch->diff; @@ -934,7 +948,11 @@ static int diff_patch_line_cb( line->len = content_len; line->origin = line_origin; - patch->content_size += content_len; + patch->content_size += content_len + 1; /* +1 for line_origin */ + + if (line_origin == GIT_DIFF_LINE_CONTEXT || + line_origin == GIT_DIFF_LINE_CONTEXT_EOFNL) + patch->context_size += content_len + 1; /* do some bookkeeping so we can provide old/new line numbers */ |