diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2018-07-06 12:36:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-06 12:36:05 +0100 |
| commit | f4633791104fa5be75115fd4c7fab0c097da345e (patch) | |
| tree | d7e9a2b6d37e5cc96232b96fdca4daa496426530 /src | |
| parent | f2a1cece3d95334d963ceffe1cd70836ae96078e (diff) | |
| parent | f9e28026753f7b6c871a160ad584b2dc2639d30f (diff) | |
| download | libgit2-f4633791104fa5be75115fd4c7fab0c097da345e.tar.gz | |
Merge pull request #4687 from tiennou/fix/4672
patch_parse: populate line numbers while parsing diffs
Diffstat (limited to 'src')
| -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++; } |
