Code

Use file and line number information when loading blame for commit
authorJonas Fonseca <fonseca@diku.dk>
Sat, 7 Feb 2009 13:57:58 +0000 (14:57 +0100)
committerJonas Fonseca <fonseca@diku.dk>
Sat, 7 Feb 2009 20:27:05 +0000 (21:27 +0100)
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>

NEWS
tig.c

diff --git a/NEWS b/NEWS
index 0e829203bad868c0eee0837e35bbd88a50d61e80..e2009df130e1c3149023902f529a4697cbda7fb5 100644 (file)
--- 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 0aaf2f555417f1a67cd77ffd6114821e479fe259..fb6231f256fbbfbcbb1545dc7caaa6d0a69dd3c1 100644 (file)
--- 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;