From: Jonas Fonseca Date: Sat, 7 Feb 2009 13:57:58 +0000 (+0100) Subject: Use file and line number information when loading blame for commit X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ba7c7d30bbed330fe7e9ceb4dc9c65a22dc8d6dc;p=tig.git Use file and line number information when loading blame for commit This was developed in parallel and is very similar to patch posted by Jeff King, however, with different goals in mind. Message-Id: <20090207112613.GA18079@coredump.intra.peff.net> --- diff --git a/NEWS b/NEWS index 0e82920..e2009df 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,11 @@ Improvements: - Colors for 256-capable terminals can be specified as colorN. - Entering a number in the prompt will jump to that line number. +Bug fixes: + + - Blame view: use line number information when loading blame for + specific commit. + tig-0.14 -------- diff --git a/tig.c b/tig.c index 0aaf2f5..fb6231f 100644 --- a/tig.c +++ b/tig.c @@ -4177,6 +4177,7 @@ struct blame_commit { struct blame { struct blame_commit *commit; + unsigned long lineno; char text[1]; }; @@ -4240,14 +4241,16 @@ parse_blame_commit(struct view *view, const char *text, int *blamed) { struct blame_commit *commit; struct blame *blame; - const char *pos = text + SIZEOF_REV - 1; + const char *pos = text + SIZEOF_REV - 2; + size_t orig_lineno = 0; size_t lineno; size_t group; - if (strlen(text) <= SIZEOF_REV || *pos != ' ') + if (strlen(text) <= SIZEOF_REV || pos[1] != ' ') return NULL; - if (!parse_number(&pos, &lineno, 1, view->lines) || + if (!parse_number(&pos, &orig_lineno, 1, 9999999) || + !parse_number(&pos, &lineno, 1, view->lines) || !parse_number(&pos, &group, 1, view->lines - lineno + 1)) return NULL; @@ -4261,6 +4264,7 @@ parse_blame_commit(struct view *view, const char *text, int *blamed) blame = line->data; blame->commit = commit; + blame->lineno = orig_lineno + group - 1; line->dirty = 1; } @@ -4419,6 +4423,9 @@ blame_request(struct view *view, enum request request, struct line *line) case REQ_VIEW_BLAME: if (check_blame_commit(blame)) { string_copy(opt_ref, blame->commit->id); + string_copy(opt_file, blame->commit->filename); + if (blame->lineno) + view->lineno = blame->lineno; open_view(view, REQ_VIEW_BLAME, OPEN_REFRESH); } break;