git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [ANNOUNCE] tig-0.14

From
Jeff King <peff@peff.net>
Date
Feb 7, 2009, 11:26 UTC
Message-ID
<20090207112613.GA18079@coredump.intra.peff.net>
In-Reply-To
<7vprhuzoxm.fsf@gitster.siamese.dyndns.org>
On Fri, Feb 06, 2009 at 11:28:05PM -0800, Junio C Hamano wrote:
Show 13 quoted lines
> It has been quite a while since I did the "show previous" feature of
> "git-blame --porcelain" that has been forever queued in 'next'; if I
> remember correctly, it implemented (2).
> 
> The reason why it never graduated from 'next' is exactly this issue.  By
> definition, there is no "previous" line number (if there were such a thing
> that says "This line was at line N in the parent of the blamed commit",
> then the commit wouldn't have taken the blame but would have passed it
> down to the parent), and we need to come up with a reasonable heuristics.
> 
> So perhaps this discussion would motivate somebody to finish that part
> off, and tig and other Porcelains can just read the necessary line number
> from the git-blame output.

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:
Previous: Jonas FonsecaNext: Jonas Fonseca
Message 20 of 69 in “[ANNOUNCE] tig-0.14”
  1. Jonas FonsecaFeb 5, 2009
  2. bill lamFeb 6, 2009
  3. Jonas FonsecaFeb 6, 2009
  4. Sitaram ChamartyFeb 6, 2009
  5. Jonas FonsecaFeb 8, 2009
  6. showing SHA1 of parent commit in tig [was Re: [ANNOUNCE] tig-0.14Sitaram Chamarty, Feb 11, 2009
  7. Jonas FonsecaFeb 12, 2009
  8. Sitaram ChamartyFeb 12, 2009
  9. Jeff KingFeb 6, 2009
  10. Jonas FonsecaFeb 6, 2009
  11. Jakub NarebskiFeb 6, 2009
  12. Jonas FonsecaFeb 8, 2009
  13. Jeff KingFeb 7, 2009
  14. Junio C HamanoFeb 7, 2009
  15. david@lang.hmFeb 7, 2009
  16. Jonas FonsecaFeb 8, 2009
  17. Jonas FonsecaFeb 8, 2009
  18. Jeff KingFeb 8, 2009
  19. Jonas FonsecaFeb 8, 2009
  20. Jeff KingFeb 7, 2009
  21. Jonas FonsecaFeb 8, 2009
  22. Jeff KingFeb 8, 2009
  23. Jonas FonsecaFeb 8, 2009
  24. Mikael MagnussonFeb 7, 2009
  25. Peter BaumannFeb 9, 2009
  26. Jeff KingFeb 9, 2009
  27. Peter BaumannFeb 9, 2009
  28. Jonas FonsecaFeb 10, 2009
  29. Jari AaltoFeb 10, 2009
  30. Ted PavlicFeb 10, 2009
  31. Jonas FonsecaFeb 10, 2009
  32. Brian GernhardtFeb 10, 2009
  33. Stefan KarpinskiFeb 10, 2009
  34. Jonas FonsecaFeb 10, 2009
  35. Brian GernhardtFeb 10, 2009
  36. Jonas FonsecaFeb 10, 2009
  37. Brian GernhardtFeb 10, 2009
  38. Ted PavlicFeb 11, 2009
  39. Jonas FonsecaFeb 12, 2009
  40. Ted PavlicFeb 11, 2009
  41. Ted PavlicFeb 20, 2009
  42. Jonas FonsecaFeb 20, 2009
  43. Ted PavlicFeb 20, 2009
  44. Jonas FonsecaFeb 20, 2009
  45. Jonas FonsecaFeb 25, 2009
  46. Ted PavlicFeb 11, 2009
  47. Ted PavlicFeb 11, 2009
  48. Ted PavlicFeb 11, 2009
  49. Jonas FonsecaFeb 12, 2009
  50. Tilo SchwarzFeb 12, 2009
  51. Jonas FonsecaFeb 12, 2009
  52. Tilo SchwarzFeb 12, 2009
  53. Jonas FonsecaFeb 15, 2009
  54. Sitaram ChamartyFeb 16, 2009
  55. Jonas FonsecaFeb 16, 2009
  56. Sitaram ChamartyFeb 16, 2009
  57. Thomas AdamFeb 16, 2009
  58. Jonas FonsecaFeb 16, 2009
  59. Marco CostalbaFeb 17, 2009
  60. Tilo SchwarzFeb 16, 2009
  61. Jonas FonsecaFeb 20, 2009
  62. Tilo SchwarzFeb 21, 2009
  63. Jonas FonsecaFeb 21, 2009
  64. Tilo SchwarzFeb 21, 2009
  65. Tilo SchwarzFeb 16, 2009
  66. bill lamFeb 13, 2009
  67. Jonas FonsecaFeb 13, 2009
  68. bill lamFeb 14, 2009
  69. Jonas FonsecaFeb 15, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.