From afe8e82a06ad7470cbefa811c434c4f0400a70d0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 27 Apr 2020 23:29:21 +0200 Subject: [PATCH] Compute line number before diff application in diff_get_lineno --- include/tig/diff.h | 2 +- src/diff.c | 16 ++++++++-------- src/stage.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/tig/diff.h b/include/tig/diff.h index f7cb97507..4e8730880 100644 --- a/include/tig/diff.h +++ b/include/tig/diff.h @@ -40,7 +40,7 @@ void diff_restore_line(struct view *view, struct diff_state *state); enum status_code diff_init_highlight(struct view *view, struct diff_state *state); bool diff_done_highlight(struct diff_state *state); -unsigned int diff_get_lineno(struct view *view, struct line *line); +unsigned int diff_get_lineno(struct view *view, struct line *line, bool old); const char *diff_get_pathname(struct view *view, struct line *line); extern struct view diff_view; diff --git a/src/diff.c b/src/diff.c index e38162c12..211ca8943 100644 --- a/src/diff.c +++ b/src/diff.c @@ -451,7 +451,7 @@ diff_save_line(struct view *view, struct diff_state *state, enum open_flags flag if (file) { state->file = get_path(file); - state->lineno = diff_get_lineno(view, line); + state->lineno = diff_get_lineno(view, line, false); state->pos = view->pos; } } @@ -479,7 +479,7 @@ diff_restore_line(struct view *view, struct diff_state *state) return; while ((line = find_next_line_by_type(view, line, LINE_DIFF_CHUNK))) { - unsigned int lineno = diff_get_lineno(view, line); + unsigned int lineno = diff_get_lineno(view, line, false); for (line++; view_has_line(view, line) && line->type != LINE_DIFF_CHUNK; line++) { if (lineno == state->lineno) { @@ -605,7 +605,7 @@ diff_blame_line(const char *ref, const char *file, unsigned long lineno, } unsigned int -diff_get_lineno(struct view *view, struct line *line) +diff_get_lineno(struct view *view, struct line *line, bool old) { const struct line *header, *chunk; unsigned int lineno; @@ -625,11 +625,11 @@ diff_get_lineno(struct view *view, struct line *line) if (!parse_chunk_header(&chunk_header, box_text(chunk))) return 0; - lineno = chunk_header.new.position; + lineno = old ? chunk_header.old.position : chunk_header.new.position; for (chunk++; chunk < line; chunk++) - if (chunk->type != LINE_DIFF_DEL && - chunk->type != LINE_DIFF_DEL2) + if (old ? chunk->type != LINE_DIFF_ADD && chunk->type != LINE_DIFF_ADD2 + : chunk->type != LINE_DIFF_DEL && chunk->type != LINE_DIFF_DEL2) lineno++; return lineno; @@ -761,7 +761,7 @@ diff_common_edit(struct view *view, enum request request, struct line *line) lineno = view->env->lineno; } else { file = diff_get_pathname(view, line); - lineno = diff_get_lineno(view, line); + lineno = diff_get_lineno(view, line, false); } if (!file) { @@ -827,7 +827,7 @@ diff_common_select(struct view *view, struct line *line, const char *changes_msg if (changes_msg) string_format(view->ref, "%s to '%s'", changes_msg, file); string_format(view->env->file, "%s", file); - view->env->lineno = view->env->goto_lineno = diff_get_lineno(view, line); + view->env->lineno = view->env->goto_lineno = diff_get_lineno(view, line, false); view->env->blob[0] = 0; } else { string_ncopy(view->ref, view->ops->id, strlen(view->ops->id)); diff --git a/src/stage.c b/src/stage.c index 565c946a0..6623cc36b 100644 --- a/src/stage.c +++ b/src/stage.c @@ -420,7 +420,7 @@ stage_request(struct view *view, enum request request, struct line *line) if (stage_line_type == LINE_STAT_UNTRACKED) { open_editor(stage_status.new.name, (line - view->line) + 1); } else { - open_editor(stage_status.new.name, diff_get_lineno(view, line)); + open_editor(stage_status.new.name, diff_get_lineno(view, line, false)); } break; @@ -445,7 +445,7 @@ stage_request(struct view *view, enum request request, struct line *line) } view->env->ref[0] = 0; - view->env->goto_lineno = diff_get_lineno(view, line); + view->env->goto_lineno = diff_get_lineno(view, line, false); if (view->env->goto_lineno > 0) view->env->goto_lineno--; return request;