{"thread":{"id":"43075","subject":"Re: [PATCH] gitweb: Use git-show-ref instead of git-peek-remote","startedAt":"2006-11-24T22:01:22Z","lastAt":"2006-11-25T11:08:00Z","messageCount":8,"participants":["Junio C Hamano","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"295318","messageId":"11644056823095-git-send-email-jnareb@gmail.com","threadId":"43075","inReplyTo":null,"subject":"[PATCH] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-24T22:01:22Z","receivedAt":"2006-11-24T22:01:22Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Use \"git show-ref --dereference\" instead of \"git peek-remote .\" in\ngit_get_references. git-show-ref is faster than git-peek-remote; even\nfaster is reading info/refs file (if it exists), but the information\nin info/refs can be stale.\n\ngit-show-ref is available since v1.4.4; the output format is slightly\ndifferent than git-peek-remote output format.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\n gitweb/gitweb.perl |    9 +++++----\n 1 files changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f06cd3e..290751f 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1154,14 +1154,15 @@ sub git_get_last_activity {\n sub git_get_references {\n \tmy $type = shift || \"\";\n \tmy %refs;\n-\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c\trefs/tags/v2.6.11\n-\t# c39ae07f393806ccf406ef966e9a15afc43cc36a\trefs/tags/v2.6.11^{}\n-\topen my $fd, \"-|\", $GIT, \"peek-remote\", \"$projectroot/$project/\"\n+\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11\n+\t# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}\n+\topen my $fd, \"-|\", git_cmd(), \"show-ref\", \"--dereference\",\n+\t\t($type ? (\"--\", \"refs/$type\") : ()) # use -- <pattern> if $type\n \t\tor return;\n \n \twhile (my $line = <$fd>) {\n \t\tchomp $line;\n-\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n+\t\tif ($line =~ m/^([0-9a-fA-F]{40}) refs\\/($type\\/?[^\\^]+)/) {\n \t\t\tif (defined $refs{$1}) {\n \t\t\t\tpush @{$refs{$1}}, $2;\n \t\t\t} else {\n-- \n1.4.4.1\n"},{"id":"293812","messageId":"7vhcwoa3mx.fsf@assigned-by-dhcp.cox.net","threadId":"43075","inReplyTo":"11644056823095-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-24T22:20:06Z","receivedAt":"2006-11-24T22:20:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> Use \"git show-ref --dereference\" instead of \"git peek-remote .\" in\n> git_get_references. git-show-ref is faster than git-peek-remote; even\n> faster is reading info/refs file (if it exists), but the information\n> in info/refs can be stale.\n\nMore importantly, it is for dumb protocol transports, not for gitweb.\n\nYou forgot to mention that you fixed the last place that\ndirectly used \"$GIT\" to invoke the command, bypassing sub\ngit_cmd.  That is a consistency clean-up worth mentioning.\n\n> git-show-ref is available since v1.4.4; the output format is slightly\n> different than git-peek-remote output format.\n\n> -\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n> +\t\tif ($line =~ m/^([0-9a-fA-F]{40}) refs\\/($type\\/?[^\\^]+)/) {\n\nI would rather do:\n\n\tm|^([0-9a-f]{40})\\srefs/($type/?[^^]+)|\n\nwhich would catch both space and tab.\n"},{"id":"294623","messageId":"200611242335.15964.jnareb@gmail.com","threadId":"43075","inReplyTo":"7vhcwoa3mx.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-24T22:35:15Z","receivedAt":"2006-11-24T22:35:15Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n\n> Jakub Narebski <jnareb@gmail.com> writes:\n> \n>> Use \"git show-ref --dereference\" instead of \"git peek-remote .\" in\n\nIt should be \n   Use \"git show-ref --dereference\" instead of \"git peek-remote <project>\"\n\n>> git_get_references. git-show-ref is faster than git-peek-remote; even\n>> faster is reading info/refs file (if it exists), but the information\n>> in info/refs can be stale.\n> \n> More importantly, it is for dumb protocol transports, not for gitweb.\n\nYes, but if it is there, why not make use of it? Especially that it\nis used only (I think) for refs markers, and not for anything important.\nOn the other side a bit of performance here doesn't matter much.\n\n> You forgot to mention that you fixed the last place that\n> directly used \"$GIT\" to invoke the command, bypassing sub\n> git_cmd.  That is a consistency clean-up worth mentioning.\n\nThis is not fix, this is change of style. The style was to use\n  git peek-remote $projectroot/$project\ninstead of equivalent\n  git --git-dir=$projectroot/$project peek-remote .\n\nWe don't have this choice with git-show-ref.\n\nOn the other hand that makes all command invocation (except the one\nused for getting git core version) pass through git_cmd() subroutine.\n\n>> git-show-ref is available since v1.4.4; the output format is slightly\n>> different than git-peek-remote output format.\n> \n>> -\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n>> +\t\tif ($line =~ m/^([0-9a-fA-F]{40}) refs\\/($type\\/?[^\\^]+)/) {\n> \n> I would rather do:\n> \n> \tm|^([0-9a-f]{40})\\srefs/($type/?[^^]+)|\n> \n> which would catch both space and tab.\n\nFeel free to do that (one nitpick: is [^^] more readable than [^\\^]?).\n\nShould I resend the patch?\n-- \nJakub Narebski\n"},{"id":"297228","messageId":"11644499234152-git-send-email-jnareb@gmail.com","threadId":"43075","inReplyTo":"7vhcwoa3mx.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH (amend)] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-25T10:18:43Z","receivedAt":"2006-11-25T10:18:43Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Use \"git show-ref --dereference\" instead of \"git peek-remote\n$projectroot/project\" in git_get_references. git-show-ref is faster\nthan git-peek-remote (40ms vs 56ms user+sys for git.git repository);\neven faster is reading info/refs file (if it exists), but the\ninformation in info/refs can be stale; that and the fact that\ninfo/refs is meant for dumb protocol transports, not for gitweb.\n\ngit-show-ref is available since v1.4.4; the output format is slightly\ndifferent than git-peek-remote output format.\n\nWhile at it make git_get_references return hash in list context,\nand reference to hash (as it used to do) in scalar and void contexts.\n\nAdditionally this change makes all git commands invocations (except\nthe one used to get version of git core tools) go through git_cmd()\nsubroutine.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nJunio C Hamano wrote:\n\n> Jakub Narebski <jnareb@gmail.com> writes:\n> \n>> Use \"git show-ref --dereference\" instead of \"git peek-remote .\" in\n>> git_get_references. git-show-ref is faster than git-peek-remote; even\n>> faster is reading info/refs file (if it exists), but the information\n>> in info/refs can be stale.\n> \n> More importantly, it is for dumb protocol transports, not for gitweb.\n\nMentioned in commit message.\n\n> You forgot to mention that you fixed the last place that\n> directly used \"$GIT\" to invoke the command, bypassing sub\n> git_cmd.  That is a consistency clean-up worth mentioning.\n\nThis is not fix, this is change of style. The style was to use\n  git peek-remote $projectroot/$project\ninstead of equivalent\n  git --git-dir=$projectroot/$project peek-remote .\n\nWe don't have this choice with git-show-ref.\n\nOn the other hand that makes all command invocation (except the one\nused for getting git core version) pass through git_cmd() subroutine.\nSo yes, it is consistency clean-up.\n\n>> git-show-ref is available since v1.4.4; the output format is slightly\n>> different than git-peek-remote output format.\n> \n>> -\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n>> +\t\tif ($line =~ m/^([0-9a-fA-F]{40}) refs\\/($type\\/?[^\\^]+)/) {\n> \n> I would rather do:\n> \n> \tm|^([0-9a-f]{40})\\srefs/($type/?[^^]+)|\n> \n> which would catch both space and tab.\n\nThis addresses those concerns.\n\n gitweb/gitweb.perl |   23 +++++++++++++++--------\n 1 files changed, 15 insertions(+), 8 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f06cd3e..2ebd9d7 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1154,14 +1154,15 @@ sub git_get_last_activity {\n sub git_get_references {\n \tmy $type = shift || \"\";\n \tmy %refs;\n-\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c\trefs/tags/v2.6.11\n-\t# c39ae07f393806ccf406ef966e9a15afc43cc36a\trefs/tags/v2.6.11^{}\n-\topen my $fd, \"-|\", $GIT, \"peek-remote\", \"$projectroot/$project/\"\n+\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11\n+\t# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}\n+\topen my $fd, \"-|\", git_cmd(), \"show-ref\", \"--dereference\",\n+\t\t($type ? (\"--\", \"refs/$type\") : ()) # use -- <pattern> if $type\n \t\tor return;\n \n \twhile (my $line = <$fd>) {\n \t\tchomp $line;\n-\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n+\t\tif ($line =~ m!^([0-9a-fA-F]{40})\\srefs/($type/?[^^]+)!) {\n \t\t\tif (defined $refs{$1}) {\n \t\t\t\tpush @{$refs{$1}}, $2;\n \t\t\t} else {\n@@ -1170,7 +1171,7 @@ sub git_get_references {\n \t\t}\n \t}\n \tclose $fd or return;\n-\treturn \\%refs;\n+\treturn wantarray ? %refs : \\%refs;\n }\n \n sub git_get_rev_name_tags {\n@@ -1293,8 +1294,9 @@ sub parse_commit {\n \t\t\t$co{'author'} = $1;\n \t\t\t$co{'author_epoch'} = $2;\n \t\t\t$co{'author_tz'} = $3;\n-\t\t\tif ($co{'author'} =~ m/^([^<]+) </) {\n-\t\t\t\t$co{'author_name'} = $1;\n+\t\t\tif ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {\n+\t\t\t\t$co{'author_name'}  = $1;\n+\t\t\t\t$co{'author_email'} = $2;\n \t\t\t} else {\n \t\t\t\t$co{'author_name'} = $co{'author'};\n \t\t\t}\n@@ -1303,7 +1305,12 @@ sub parse_commit {\n \t\t\t$co{'committer_epoch'} = $2;\n \t\t\t$co{'committer_tz'} = $3;\n \t\t\t$co{'committer_name'} = $co{'committer'};\n-\t\t\t$co{'committer_name'} =~ s/ <.*//;\n+\t\t\tif ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {\n+\t\t\t\t$co{'committer_name'}  = $1;\n+\t\t\t\t$co{'committer_email'} = $2;\n+\t\t\t} else {\n+\t\t\t\t$co{'committer_name'} = $co{'committer'};\n+\t\t\t}\n \t\t}\n \t}\n \tif (!defined $co{'tree'}) {\n-- \n1.4.4.1\n"},{"id":"296029","messageId":"ek95ik$2f3$1@sea.gmane.org","threadId":"43075","inReplyTo":"11644499234152-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH (amend)] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-25T10:24:58Z","receivedAt":"2006-11-25T10:24:58Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jakub Narebski wrote:\n\nOoops. This is a part of next patch to send. Please delete this two chunks.\nSorry for the mistake.\n\n\n> @@ -1293,8 +1294,9 @@ sub parse_commit {\n>                       $co{'author'} = $1;\n>                       $co{'author_epoch'} = $2;\n>                       $co{'author_tz'} = $3;\n> -                     if ($co{'author'} =~ m/^([^<]+) </) {\n> -                             $co{'author_name'} = $1;\n> +                     if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {\n> +                             $co{'author_name'}  = $1;\n> +                             $co{'author_email'} = $2;\n>                       } else {\n>                               $co{'author_name'} = $co{'author'};\n>                       }\n> @@ -1303,7 +1305,12 @@ sub parse_commit {\n>                       $co{'committer_epoch'} = $2;\n>                       $co{'committer_tz'} = $3;\n>                       $co{'committer_name'} = $co{'committer'};\n> -                     $co{'committer_name'} =~ s/ <.*//;\n> +                     if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {\n> +                             $co{'committer_name'}  = $1;\n> +                             $co{'committer_email'} = $2;\n> +                     } else {\n> +                             $co{'committer_name'} = $co{'committer'};\n> +                     }\n>               }\n>       }\n>       if (!defined $co{'tree'}) {\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"296736","messageId":"11644507284105-git-send-email-jnareb@gmail.com","threadId":"43075","inReplyTo":"7vhcwoa3mx.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-25T10:32:08Z","receivedAt":"2006-11-25T10:32:08Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Use \"git show-ref --dereference\" instead of \"git peek-remote\n$projectroot/project\" in git_get_references. git-show-ref is faster\nthan git-peek-remote (40ms vs 56ms user+sys for git.git repository);\neven faster is reading info/refs file (if it exists), but the\ninformation in info/refs can be stale; that and the fact that\ninfo/refs is meant for dumb protocol transports, not for gitweb.\n\ngit-show-ref is available since v1.4.4; the output format is slightly\ndifferent than git-peek-remote output format.\n\nWhile at it make git_get_references return hash in list context,\nand reference to hash (as it used to do) in scalar and void contexts.\n\nSigned-off-by: Jakub Narebski <jnareb@gmail.com>\n---\nThis is the final version.\n\nOnce again, I'm extremly sorry for the confusion with the previous\nversion...\n\n gitweb/gitweb.perl |   11 ++++++-----\n 1 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex f06cd3e..1cded75 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -1154,14 +1154,15 @@ sub git_get_last_activity {\n sub git_get_references {\n \tmy $type = shift || \"\";\n \tmy %refs;\n-\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c\trefs/tags/v2.6.11\n-\t# c39ae07f393806ccf406ef966e9a15afc43cc36a\trefs/tags/v2.6.11^{}\n-\topen my $fd, \"-|\", $GIT, \"peek-remote\", \"$projectroot/$project/\"\n+\t# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11\n+\t# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}\n+\topen my $fd, \"-|\", git_cmd(), \"show-ref\", \"--dereference\",\n+\t\t($type ? (\"--\", \"refs/$type\") : ()) # use -- <pattern> if $type\n \t\tor return;\n \n \twhile (my $line = <$fd>) {\n \t\tchomp $line;\n-\t\tif ($line =~ m/^([0-9a-fA-F]{40})\\trefs\\/($type\\/?[^\\^]+)/) {\n+\t\tif ($line =~ m!^([0-9a-fA-F]{40})\\srefs/($type/?[^^]+)!) {\n \t\t\tif (defined $refs{$1}) {\n \t\t\t\tpush @{$refs{$1}}, $2;\n \t\t\t} else {\n@@ -1170,7 +1171,7 @@ sub git_get_references {\n \t\t}\n \t}\n \tclose $fd or return;\n-\treturn \\%refs;\n+\treturn wantarray ? %refs : \\%refs;\n }\n \n sub git_get_rev_name_tags {\n-- \n1.4.4.1\n"},{"id":"297653","messageId":"7v7ixj3izw.fsf@assigned-by-dhcp.cox.net","threadId":"43075","inReplyTo":"11644507284105-git-send-email-jnareb@gmail.com","subject":"Re: [PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-25T10:42:27Z","receivedAt":"2006-11-25T10:42:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n\n> While at it make git_get_references return hash in list context,\n> and reference to hash (as it used to do) in scalar and void contexts.\n\nWhy did you have to add this?  Generally, context sensitive\nreturns make the program much harder to maintain, because it\nforces the call sites to be extremely careful to choose between\n\"my ($foo) = func()\" vs \"my $foo = func()\", and people who later\ncall the function inevitably make mistakes.\n\nSo unless there is a compelling reason, I'd rather not see more\n\"wantarray\" in the program.\n"},{"id":"298112","messageId":"200611251208.01047.jnareb@gmail.com","threadId":"43075","inReplyTo":"7v7ixj3izw.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-25T11:08:00Z","receivedAt":"2006-11-25T11:08:00Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Junio C Hamano wrote:\n> Jakub Narebski <jnareb@gmail.com> writes:\n> \n>> While at it make git_get_references return hash in list context,\n>> and reference to hash (as it used to do) in scalar and void contexts.\n> \n> Why did you have to add this?  Generally, context sensitive\n> returns make the program much harder to maintain, because it\n> forces the call sites to be extremely careful to choose between\n> \"my ($foo) = func()\" vs \"my $foo = func()\", and people who later\n> call the function inevitably make mistakes.\n> \n> So unless there is a compelling reason, I'd rather not see more\n> \"wantarray\" in the program.\n\nO.K. I have browsed through gitweb, and I see that we almost always\nwant the hashref, not hash (for passing further).\n\n-- \nJakub Narebski\n"}]}