Skip to contentSkip to conversation

gitweb: blame: Print just a single new line char per table row

PATCH In review Luben Tuikov 6 participants 14 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gitweb: blame: Print just a single new line char per table row

This makes cut-and-paste from blame legible, else after pasting it is broken into too many lines.

---
 gitweb/gitweb.perl |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +4 -4
index cba0840..451bf5d 100644
@@ -2509,7 +2509,7 @@ HTML
 			$current_color = ++$current_color % $num_colors;
 			$print_c8 = 1;
 		}
-		print "<tr class=\"$rev_color[$current_color]\">\n";
+		print "<tr class=\"$rev_color[$current_color]\">";
 		print "<td class=\"sha1\"";
 		if ($print_c8 == 1) {
 			print " title=\"$author, $date\"";
@@ -2519,10 +2519,10 @@ HTML
 			print $cgi->a({-href => href(action=>"commit", hash=>$full_rev, file_name=>$file_name)},
 				      esc_html($rev));
 		}
-		print "</td>\n";
+		print "</td>";
 		print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
-		      esc_html($lineno) . "</a></td>\n";
-		print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
+		      esc_html($lineno) . "</a></td>";
+		print "<td class=\"pre\">" . esc_html($data) . "</td>";
 		print "</tr>\n";
 	}
 	print "</table>\n";
Signature · 1 line
1.4.2.3.g7d77
#1 lore raw
Quoted 4 lines · Luben Tuikov

This makes cut-and-paste from blame legible, else after pasting it is broken into too many lines.

I have to say the browser is seriously broken if whitespaces between <tr> and <td>, </td> and next <td>, </td> and </tr> makes a difference to its behaviour. Aren't there a way to tell the browser to cut "visually"? E.g. "The area I want to cut is from this data column, and lines from here to there. I do not want the leftmost two columns (commit-8 and lineno)".

I do not mind applying this, but that is only because it does not make its source any less readable. It does make things harder to debug if somebody is debugging its output by reading the generated raw HTML, so it is not like there is no downside.

You might want to run links (or lynx) in screen ;-). Screen supports left- (or right-, or both-sides) bounded cut which I find extremely useful.

#2 lore raw
Quoted 4 lines · --- Junio C Hamano

I have to say the browser is seriously broken if whitespaces between <tr> and <td>, </td> and next <td>, </td> and </tr> makes a difference to its behaviour. Aren't there a way to tell the browser to cut "visually"? E.g. "The area I want to cut is

I'm not sure, I'm using latest Firefox.

Quoted 7 lines

from this data column, and lines from here to there. I do not want the leftmost two columns (commit-8 and lineno)".

I do not mind applying this, but that is only because it does not make its source any less readable. It does make things harder to debug if somebody is debugging its output by reading the generated raw HTML, so it is not like there is no downside.

If you think that this could be a problem or affects negatively, please don't apply. cut-paste-edit is a small price to pay as opposed to messing up the code and output.

Quoted 3 lines

You might want to run links (or lynx) in screen ;-). Screen supports left- (or right-, or both-sides) bounded cut which I find extremely useful.

Ok, I'll try that.

Luben

#3 lore raw

perhaps time to remove git_blame from gitweb, and git-annotate?

It's been a while since we lost git_blame from %actions list. I am wondering maybe it's time to remove it, after 1.4.3 happens.

While I was looking at it, I noticed that it would make git-cvsserver the last in-tree user of git-annotate. As I understand it, "git-blame -c" should produce compatible output to the command, so it might also be a good time to consider removal of git-annotate as well while updating git-cvsserver to use git-blame instead of it.

Do people have reason to favor annotate over blame? To keep existing people's scripts working I think we should add a small amount of code to blame.c to default to compatibility mode when the command is called as git-annotate at least for a while, but other than that I do not see much issue against scheduling for annotate's removal.

I am not going to do anything about this right now (the "master" branch is in freeze-and-stabilize phase), but if people have issues I overlooked, raise hands now please?

#4 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

Dear diary, on Thu, Oct 05, 2006 at 10:13:15AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 2 lines

It's been a while since we lost git_blame from %actions list. I am wondering maybe it's time to remove it, after 1.4.3 happens.

I will not mourn git-annotate disappearance (perhaps it could stay an alias to git-blame -c; I don't like this UI-wise but we already do this kind of thing with git-log / git-whatchanged). I still like gitweb blame better than blame2 but I'll just patch blame to look like blame2 (or better) and be happy with that.

Signature · 5 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
#5 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

Quoted 10 lines · --- Petr Baudis

Dear diary, on Thu, Oct 05, 2006 at 10:13:15AM CEST, I got a letter where Junio C Hamano <[email protected]> said that...

Quoted 2 lines

It's been a while since we lost git_blame from %actions list. I am wondering maybe it's time to remove it, after 1.4.3 happens.

I will not mourn git-annotate disappearance (perhaps it could stay an alias to git-blame -c; I don't like this UI-wise but we already do this kind of thing with git-log / git-whatchanged). I still like gitweb blame better than blame2 but I'll just patch blame to look like blame2 (or better) and be happy with that.

That's exactly what I don't want to happen. blame2 is much less bloated than blame both in code and in visual appearance and in using git. And this was the whole point: quick, short, fast and straight to the point.

I'd like to keep the blame interface as simple as possible, more window estate given to the code lines, and as little as possible to the commit id: a clickable commit-8 and now we also have clickable line_no to show us the state of the file, is more than enough.

So far, blame2 has been by far the better "annotate" (as it is called in the other SCMs) interface I've seen in four other SCMs (some proprietary). Let's keep it like this.

When data-mining code, what I'm interested in is: where did this line of code come from (commit-8), is it a part of a larger chunk (zebra coloring) and how it relates to the surrounding code. Blame2 is more than efficient at this.

Luben

Quoted 8 lines
Signature · 6 lines
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
#6 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

(Trimmed cc list to people caring about gitweb.)

Dear diary, on Fri, Oct 06, 2006 at 08:55:29PM CEST, I got a letter where Luben Tuikov <[email protected]> said that...

Quoted 17 lines
Quoted 5 lines · --- Petr Baudis

I will not mourn git-annotate disappearance (perhaps it could stay an alias to git-blame -c; I don't like this UI-wise but we already do this kind of thing with git-log / git-whatchanged). I still like gitweb blame better than blame2 but I'll just patch blame to look like blame2 (or better) and be happy with that.

That's exactly what I don't want to happen. blame2 is much less bloated than blame both in code and in visual appearance and in using git. And this was the whole point: quick, short, fast and straight to the point.

I'd like to keep the blame interface as simple as possible, more window estate given to the code lines, and as little as possible to the commit id: a clickable commit-8 and now we also have clickable line_no to show us the state of the file, is more than enough.

Quoted 8 lines

So far, blame2 has been by far the better "annotate" (as it is called in the other SCMs) interface I've seen in four other SCMs (some proprietary). Let's keep it like this.

When data-mining code, what I'm interested in is: where did this line of code come from (commit-8), is it a part of a larger chunk (zebra coloring) and how it relates to the surrounding code. Blame2 is more than efficient at this.

And _I_ like to have some general idea about who and when touched given line of code, without having to click on a bunch of commit ids or spend a minute hovering over them patiently. ;-)

If you really feel strongly about it, we should be able to make the individual columns hideable at view time, e.g. by a tiny bit of javascript just changing the display CSS property, which would be really comfortable. My idea about the output would be cg-log -s format, which is still reasonably tense. OTOH, there's still some space to burn in the Line column.

There should be no additional load caused by this since we already extract this information anyway - we show it as a tooltip.

Signature · 5 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
#7 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

Quoted 25 lines · --- Petr Baudis

(Trimmed cc list to people caring about gitweb.)

Dear diary, on Fri, Oct 06, 2006 at 08:55:29PM CEST, I got a letter where Luben Tuikov <[email protected]> said that...

Quoted 21 lines
Quoted 5 lines · --- Petr Baudis

I will not mourn git-annotate disappearance (perhaps it could stay an alias to git-blame -c; I don't like this UI-wise but we already do this kind of thing with git-log / git-whatchanged). I still like gitweb blame better than blame2 but I'll just patch blame to look like blame2 (or better) and be happy with that.

That's exactly what I don't want to happen. blame2 is much less bloated than blame both in code and in visual appearance and in using git. And this was the whole point: quick, short, fast and straight to the point.

I'd like to keep the blame interface as simple as possible, more window estate given to the code lines, and as little as possible to the commit id: a clickable commit-8 and now we also have clickable line_no to show us the state of the file, is more than enough.

So far, blame2 has been by far the better "annotate" (as it is called in the other SCMs) interface I've seen in four other SCMs (some proprietary). Let's keep it like this.

Quoted 8 lines
Quoted 4 lines

When data-mining code, what I'm interested in is: where did this line of code come from (commit-8), is it a part of a larger chunk (zebra coloring) and how it relates to the surrounding code. Blame2 is more than efficient at this.

And _I_ like to have some general idea about who and when touched given line of code, without having to click on a bunch of commit ids or spend a minute hovering over them patiently. ;-)

Well understood.

Although, when I'm chasing after a problem, I care much about tracing back through the commit history as opposed to who did what and when, not until I've nailed the regressive commit (is when I care who/what/when/how).

Quoted 6 lines

If you really feel strongly about it, we should be able to make the individual columns hideable at view time, e.g. by a tiny bit of javascript just changing the display CSS property, which would be really comfortable. My idea about the output would be cg-log -s format, which is still reasonably tense. OTOH, there's still some space to burn in the Line column.

Point taken.

Now since I don't want to turn blame2 into a circus, and since the whole point of blame2 (over blame) was to stay away from it being a circus, and to be fast and to the point, can we just keep git_blame() around which gives you this extra information right in the main screen?

Luben
P.S. The alternative is to create a next git_blame{N+1}() each time git_blameN() becomes git_blame{N-1}().

#8 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

In reply to Junio C Hamano

Hi,

Quoted 6 lines · Junio C Hamano

Do people have reason to favor annotate over blame? To keep existing people's scripts working I think we should add a small amount of code to blame.c to default to compatibility mode when the command is called as git-annotate at least for a while, but other than that I do not see much issue against scheduling for annotate's removal.

+1. Although I would leave git-annotate in git, if only to meet expectations of new git users.

Ciao,
Dscho

#9 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

Quoted 11 lines · --- Johannes Schindelin

Hi,

Quoted 6 lines · Junio C Hamano

Do people have reason to favor annotate over blame? To keep existing people's scripts working I think we should add a small amount of code to blame.c to default to compatibility mode when the command is called as git-annotate at least for a while, but other than that I do not see much issue against scheduling for annotate's removal.

Quoted 2 lines

+1. Although I would leave git-annotate in git, if only to meet expectations of new git users.

I agree with Junio's assessment of the situation.

Luben

#10 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

Quoted 7 lines · Luben Tuikov
Quoted 7 lines
Quoted 6 lines

Do people have reason to favor annotate over blame? To keep existing people's scripts working I think we should add a small amount of code to blame.c to default to compatibility mode when the command is called as git-annotate at least for a while, but other than that I do not see much issue against scheduling for annotate's removal.

Quoted 5 lines
Quoted 2 lines

+1. Although I would leave git-annotate in git, if only to meet expectations of new git users.

I agree with Junio's assessment of the situation.

+1 -- I need to test that the switch to git-blame for git-cvsserver works well for Eclipse end users. Will try and fit that next week somehow ;-)

martin

Signature · 6 lines
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224                              MOB: +64(21)364-017
      Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------
#11 lore raw

PATCH 1/1 Remove git-annotate.perl and create a builtin-alias for git-blame

In reply to Junio C Hamano

---

I've clearly been too busy to actually fix this, and blame works, so, let's create an internal alias and delete annotate.

(The tests still pass, for whatever that's worth.)

---
 Makefile           |    3 +-
 builtin-annotate.c |   25 ++
 builtin.h          |    1 +
 git-annotate.perl  |  708 ----------------------------------------------------
 git.c              |    1 +
 5 files changed, 29 insertions(+), 709 deletions(-)
Makefile +2 -1
index 2c7c338..7e62e76 100644
@@ -173,7 +173,7 @@ SCRIPT_SH = \
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
 	git-shortlog.perl git-rerere.perl \
-	git-annotate.perl git-cvsserver.perl \
+	git-cvsserver.perl \
 	git-svnimport.perl git-cvsexportcommit.perl \
 	git-send-email.perl git-svn.perl
 
@@ -265,6 +265,7 @@ LIB_OBJS = \
 
 BUILTIN_OBJS = \
 	builtin-add.o \
+	builtin-annotate.o \
 	builtin-apply.o \
 	builtin-archive.o \
 	builtin-cat-file.o \
builtin-annotate.c new file +25 -0
new file mode 100644
index 0000000..2655e60
@@ -0,0 +1,25 @@
+/*
+ * "git annotate" builtin alias
+ *
+ * Copyright (C) 2006 Ryan Anderson
+ */
+#include "git-compat-util.h"
+#include "exec_cmd.h"
+
+int cmd_annotate(int argc, const char **argv, const char *prefix)
+{
+	const char **nargv;
+	int i;
+	nargv = xmalloc(sizeof(char *) * (argc + 2));
+	
+	nargv[0] = "blame";
+	nargv[1] = "-c";
+	
+	for (i = 1; i < argc; i++) {
+		nargv[i+1] = argv[i];
+	}
+	nargv[argc + 1] = NULL;
+
+	return execv_git_cmd(nargv);
+}
+	
builtin.h +1 -0
index f9fa9ff..2c5d900 100644
@@ -13,6 +13,7 @@ extern void stripspace(FILE *in, FILE *o
 extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
 
 extern int cmd_add(int argc, const char **argv, const char *prefix);
+extern int cmd_annotate(int argc, const char **argv, const char *prefix);
 extern int cmd_apply(int argc, const char **argv, const char *prefix);
 extern int cmd_archive(int argc, const char **argv, const char *prefix);
 extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
git-annotate.perl deleted +0 -708

708 lines not on this page · raw message

git.c +1 -0
index d7103a4..b32ee0f 100644
@@ -219,6 +219,7 @@ static void handle_internal_command(int 
 		int option;
 	} commands[] = {
 		{ "add", cmd_add, RUN_SETUP },
+		{ "annotate", cmd_annotate, },
 		{ "apply", cmd_apply },
 		{ "archive", cmd_archive },
 		{ "cat-file", cmd_cat_file, RUN_SETUP },
Signature · 1 line
1.4.2.3.gbf37d
#12 lore raw

Re: perhaps time to remove git_blame from gitweb, and git-annotate?

In reply to Junio C Hamano
Quoted 2 lines · Junio C Hamano

It's been a while since we lost git_blame from %actions list. I am wondering maybe it's time to remove it, after 1.4.3 happens.

I certainly have no objection. In fact, I sent a patch a moment ago. (I didn't keep the cc: on it, I figured there was too high a chance of mishap when pasting the cc: list.)

I forgot to mentio it in the email, but I have the change pullable from:
http://h4x0r5.com/~ryan/git/ryan.git/ del-annotate
(and gitwebed from http://h4x0r5.com/~ryan/gitweb.cgi )

Signature · 2 lines
Ryan Anderson
  sometimes Pug Majere
#13 lore raw

Obituary for git-annotate

Quoted 7 lines · Ryan Anderson
Quoted 2 lines · Junio C Hamano

It's been a while since we lost git_blame from %actions list. I am wondering maybe it's time to remove it, after 1.4.3 happens.

I certainly have no objection. In fact, I sent a patch a moment ago. (I didn't keep the cc: on it, I figured there was too high a chance of mishap when pasting the cc: list.)

So it's finally settled between annotate and blame. It is kind of sad to see one of them had to go while these stem from slightly different algorithm sketches [*1*]. But for 8 months of its existence, it served us well as the git-cvsserver backend. May it rest in peace.

Having said that, there are a few things in git-blame that interested people may want to further look into.

Annotation by git-blame is done by "passing the blame to parents" principle. You start from the final form of the blob, and compare it with its counterpart in the parent version (rename detection is used to pick which file in the parent version to compare against). The lines the commit inherited from its parent are not responsibility of the child so the algorithm passes blame on them to the parent. The lines the commit changed from the parent are blamed on the child.

When this is done, the parent "temporarily" takes responsibility for those lines that child did not change -- it just becomes "suspect" for those lines when we compare parent and child. And then the algorithm goes further down the ancestry to give the parent the chance to exonerate itself by passing blames for the lines it is suspect for, by passing the blame to its parent.

When sifting the lines into "inherited" and "our responsibility", internally git-blame runs "diff", which expresses the changes as "these lines are deleted and these are inserted by the child". Lines outside are clearly inherited from the parent.

This has an interesting effect on blame output.

Suppose the original file had two groups of lines; group A followed by group B. A commit changes the file so that it has group B followed by group A. What git-blame sees as diff between the two is either:

    -A
     B
    +A 

or

    +B
     A
    -B    

In either case, it would end up giving blame to the child for one group (the first diff blames the child for A lines) and pass the blame for the other one to the parent.

If we used something other than "diff" (Delete Insert File vs File ;-)), that expresses changes as "these are moved from there, these are inserted anew" (call that "miff"), then we should be able to assign blame more accurately. The above example case would be expressed as "group A came from the top part of the parent, group B came from the bottom part of the parent". Passing of the blame based on that expression would blame the child for neither group of lines.

Further, if we use "ciff" that expresses changes as "these are copied from there, these are inserted anew", we can do a lot more interesting thing. We can track code movement across files, and that is not limited to renames.

For example, suppose that the parent had files F1 and F2 and the child moved a function and copy-and-pasted a comment block from F1 to F2, and we are annotating lines in F2.

The current git-blame sees that the function and comment block appeared from nowhere into F2 and blames the child for them. However, when annotating F2, we could:

- use concatenation of all files in the parent that was modified between parent and child (or just "all files in the parent" -- the difference is exactly like plain -C vs -C --find-copies-harder) as the source image;

- use lines of F2 in the child as the destination image;

- run "ciff" algorithm to see where each line of F2 in the child came from (either copied from existing file somewhere in the parent, or inserted anew by the child).

This would find that the function and the comment block were copied from F1 in the parent.

An interesting property of this is that when the parent passes down the blame for the function the child moved in the above example further to its parent, we do not necessarily have to run "ciff" algorithm on file F1 as the whole. We only need to give the function (i.e. the lines the parent is still suspect for) [*2*]. So this makes destination image fed to "ciff" smaller as more lines are blamed on children while digging deeper, which may compensate for the need to feed not just that file but other files for copy detection on the source image side.

[*1*]

I think annotate follows this sketch
http://thread.gmane.org/gmane.comp.version-control.git/14819/focus=14867

while blame follows this sketch
http://thread.gmane.org/gmane.comp.version-control.git/5453/focus=5483

[*2*]

we may need to use a handful surrounding context lines for better identification of copy source by the "ciff" algorithm but that is a minor implementation detail.