Re: [ANNOUNCE] tig-0.14

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeff King
Date: Saturday, February 7, 2009 - 4:26 am

On Fri, Feb 06, 2009 at 11:28:05PM -0800, Junio C Hamano wrote:


Do we actually have heuristics that are better than "this was the line
in the original source file?" (i.e., (2) as I described). Because we
already have that in the first number that comes from "blame
--incremental". So perhaps we should start using it and see how well it
works in practice (because like all heuristics, getting a good one is
likely to be a lot of guess and check on what works in practice).

Of course I say "we" and I mean "Jonas". ;) I worked up a small tig
patch below which seems to work, but:

  1. the "jump to this new line number on refresh" code is very hack-ish
     (read: it is now broken for every view except blame), and I'm not
     sure of the most tig-ish way of fixing it

  2. I'm very unsure of the line number parsing. The parse_number
     function confusingly parses " 123 456" as "456". So perhaps there
     is some invariant of the parsing strategy that I don't understand
     (like our pointer is supposed to be at the last character of the
     previous token and _not_ on the space). So the parsing in
     parse_blame_commit is a bit hack-ish.

  3. Nothing in tig records the file that the source line came from. So
     we could be jumping to an arbitrary line number that really came
     from some other file.

Anyway, here it is.

---
diff --git a/tig.c b/tig.c
index 97794b0..faec056 100644
--- a/tig.c
+++ b/tig.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <fcntl.h>
+#include <limits.h>
 
 #include <regex.h>
 
@@ -2574,7 +2575,7 @@ reset_view(struct view *view)
 
 	view->p_offset = view->offset;
 	view->p_yoffset = view->yoffset;
-	view->p_lineno = view->lineno;
+	/* view->p_lineno = view->lineno; */
 
 	view->line = NULL;
 	view->offset = 0;
@@ -4180,6 +4181,7 @@ struct blame_commit {
 
 struct blame {
 	struct blame_commit *commit;
+	int lineno;
 	char text[1];
 };
 
@@ -4243,14 +4245,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 lineno;
 	size_t group;
+	size_t orig_lineno;
 
-	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, INT_MAX) ||
+	    !parse_number(&pos, &lineno, 1, view->lines) ||
 	    !parse_number(&pos, &group, 1, view->lines - lineno + 1))
 		return NULL;
 
@@ -4264,6 +4268,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;
 	}
 
@@ -4425,8 +4430,10 @@ blame_request(struct view *view, enum request request, struct line *line)
 
 	case REQ_PARENT:
 		if (check_blame_commit(blame) &&
-		    select_commit_parent(blame->commit->id, opt_ref))
+		    select_commit_parent(blame->commit->id, opt_ref)) {
+			view->p_lineno = blame->lineno;
 			open_view(view, REQ_VIEW_BLAME, OPEN_REFRESH);
+		}
 		break;
 
 	case REQ_ENTER:
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[ANNOUNCE] tig-0.14, Jonas Fonseca, (Thu Feb 5, 1:44 pm)
Re: [ANNOUNCE] tig-0.14, bill lam, (Fri Feb 6, 3:49 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 6, 7:29 am)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Fri Feb 6, 12:15 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 6, 3:10 pm)
Re: [ANNOUNCE] tig-0.14, Jakub Narebski, (Fri Feb 6, 3:53 pm)
Re: [ANNOUNCE] tig-0.14, Mikael Magnusson, (Fri Feb 6, 7:48 pm)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Sat Feb 7, 12:10 am)
Re: [ANNOUNCE] tig-0.14, Junio C Hamano, (Sat Feb 7, 12:28 am)
Re: [ANNOUNCE] tig-0.14, david, (Sat Feb 7, 1:55 am)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Sat Feb 7, 4:26 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 3:13 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 3:31 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 3:47 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 3:55 am)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Sun Feb 8, 4:00 am)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Sun Feb 8, 4:06 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 4:49 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 8, 4:52 am)
Re: [ANNOUNCE] tig-0.14, Peter Baumann, (Mon Feb 9, 3:07 pm)
Re: [ANNOUNCE] tig-0.14, Jeff King, (Mon Feb 9, 3:22 pm)
Re: [ANNOUNCE] tig-0.14, Peter Baumann, (Mon Feb 9, 3:30 pm)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Tue Feb 10, 6:29 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Tue Feb 10, 11:29 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Tue Feb 10, 11:42 am)
Re: [ANNOUNCE] tig-0.14, Brian Gernhardt, (Tue Feb 10, 12:07 pm)
Re: [ANNOUNCE] tig-0.14, Stefan Karpinski, (Tue Feb 10, 12:29 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Tue Feb 10, 1:41 pm)
Re: [ANNOUNCE] tig-0.14, Brian Gernhardt, (Tue Feb 10, 1:49 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Tue Feb 10, 2:13 pm)
Re: [ANNOUNCE] tig-0.14, Brian Gernhardt, (Tue Feb 10, 2:18 pm)
Re: [ANNOUNCE] tig-0.14, Jari Aalto, (Tue Feb 10, 2:23 pm)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Wed Feb 11, 7:03 am)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Wed Feb 11, 7:06 am)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Wed Feb 11, 7:12 am)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Wed Feb 11, 7:19 am)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Wed Feb 11, 10:47 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Wed Feb 11, 6:08 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Wed Feb 11, 6:30 pm)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Thu Feb 12, 2:48 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Thu Feb 12, 3:24 pm)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Thu Feb 12, 4:14 pm)
Re: [ANNOUNCE] tig-0.14, bill lam, (Thu Feb 12, 7:31 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 13, 4:57 pm)
Re: [ANNOUNCE] tig-0.14, bill lam, (Fri Feb 13, 8:31 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 15, 4:22 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sun Feb 15, 4:47 pm)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Mon Feb 16, 2:12 pm)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Mon Feb 16, 2:55 pm)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Fri Feb 20, 10:24 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 20, 11:34 am)
Re: [ANNOUNCE] tig-0.14, Ted Pavlic, (Fri Feb 20, 1:36 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 20, 4:31 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Fri Feb 20, 4:35 pm)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Sat Feb 21, 10:35 am)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Sat Feb 21, 10:41 am)
Re: [ANNOUNCE] tig-0.14, Tilo Schwarz, (Sat Feb 21, 1:18 pm)
Re: [ANNOUNCE] tig-0.14, Jonas Fonseca, (Wed Feb 25, 2:54 pm)