diff options
| author | Etienne Samson <samson.etienne@gmail.com> | 2018-06-18 20:37:18 +0000 |
|---|---|---|
| committer | Etienne Samson <samson.etienne@gmail.com> | 2018-06-19 00:12:58 +0200 |
| commit | f9e28026753f7b6c871a160ad584b2dc2639d30f (patch) | |
| tree | 373bde5d367b83038475efb0ee9f475b28e325cc /src/patch_parse.c | |
| parent | e212011b9872c52f6205d3a30b10f753c3108918 (diff) | |
| download | libgit2-f9e28026753f7b6c871a160ad584b2dc2639d30f.tar.gz | |
patch_parse: populate line numbers while parsing diffs
Diffstat (limited to 'src/patch_parse.c')
| -rw-r--r-- | src/patch_parse.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c index 2fd6e9766..f9dcecd1c 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -563,6 +563,8 @@ static int parse_hunk_body( char c; int origin; int prefix = 1; + int old_lineno = hunk->hunk.old_start + (hunk->hunk.old_lines - oldlines); + int new_lineno = hunk->hunk.new_start + (hunk->hunk.new_lines - newlines); if (ctx->parse_ctx.line_len == 0 || ctx->parse_ctx.line[ctx->parse_ctx.line_len - 1] != '\n') { error = git_parse_err("invalid patch instruction at line %"PRIuZ, @@ -586,11 +588,13 @@ static int parse_hunk_body( case '-': origin = GIT_DIFF_LINE_DELETION; oldlines--; + new_lineno = -1; break; case '+': origin = GIT_DIFF_LINE_ADDITION; newlines--; + old_lineno = -1; break; default: @@ -607,6 +611,9 @@ static int parse_hunk_body( line->content_len = ctx->parse_ctx.line_len - prefix; line->content_offset = ctx->parse_ctx.content_len - ctx->parse_ctx.remain_len; line->origin = origin; + line->num_lines = 1; + line->old_lineno = old_lineno; + line->new_lineno = new_lineno; hunk->line_count++; } |
