* [PATCH] gitweb: Use git-show-ref instead of git-peek-remote
@ 2006-11-24 22:01 Jakub Narebski
2006-11-24 22:20 ` Junio C Hamano
0 siblings, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2006-11-24 22:01 UTC (permalink / raw)
To: git; +Cc: Jakub Narebski
Use "git show-ref --dereference" instead of "git peek-remote ." in
git_get_references. git-show-ref is faster than git-peek-remote; even
faster is reading info/refs file (if it exists), but the information
in info/refs can be stale.
git-show-ref is available since v1.4.4; the output format is slightly
different than git-peek-remote output format.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
gitweb/gitweb.perl | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f06cd3e..290751f 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1154,14 +1154,15 @@ sub git_get_last_activity {
sub git_get_references {
my $type = shift || "";
my %refs;
- # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
- # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
- open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
+ # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
+ # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
+ open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
+ ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
or return;
while (my $line = <$fd>) {
chomp $line;
- if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
+ if ($line =~ m/^([0-9a-fA-F]{40}) refs\/($type\/?[^\^]+)/) {
if (defined $refs{$1}) {
push @{$refs{$1}}, $2;
} else {
--
1.4.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-24 22:01 [PATCH] gitweb: Use git-show-ref instead of git-peek-remote Jakub Narebski
@ 2006-11-24 22:20 ` Junio C Hamano
2006-11-24 22:35 ` Jakub Narebski
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Junio C Hamano @ 2006-11-24 22:20 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Jakub Narebski <jnareb@gmail.com> writes:
> Use "git show-ref --dereference" instead of "git peek-remote ." in
> git_get_references. git-show-ref is faster than git-peek-remote; even
> faster is reading info/refs file (if it exists), but the information
> in info/refs can be stale.
More importantly, it is for dumb protocol transports, not for gitweb.
You forgot to mention that you fixed the last place that
directly used "$GIT" to invoke the command, bypassing sub
git_cmd. That is a consistency clean-up worth mentioning.
> git-show-ref is available since v1.4.4; the output format is slightly
> different than git-peek-remote output format.
> - if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
> + if ($line =~ m/^([0-9a-fA-F]{40}) refs\/($type\/?[^\^]+)/) {
I would rather do:
m|^([0-9a-f]{40})\srefs/($type/?[^^]+)|
which would catch both space and tab.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-24 22:20 ` Junio C Hamano
@ 2006-11-24 22:35 ` Jakub Narebski
2006-11-25 10:18 ` [PATCH (amend)] " Jakub Narebski
2006-11-25 10:32 ` [PATCH (take 3)] " Jakub Narebski
2 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-11-24 22:35 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>
>> Use "git show-ref --dereference" instead of "git peek-remote ." in
It should be
Use "git show-ref --dereference" instead of "git peek-remote <project>"
>> git_get_references. git-show-ref is faster than git-peek-remote; even
>> faster is reading info/refs file (if it exists), but the information
>> in info/refs can be stale.
>
> More importantly, it is for dumb protocol transports, not for gitweb.
Yes, but if it is there, why not make use of it? Especially that it
is used only (I think) for refs markers, and not for anything important.
On the other side a bit of performance here doesn't matter much.
> You forgot to mention that you fixed the last place that
> directly used "$GIT" to invoke the command, bypassing sub
> git_cmd. That is a consistency clean-up worth mentioning.
This is not fix, this is change of style. The style was to use
git peek-remote $projectroot/$project
instead of equivalent
git --git-dir=$projectroot/$project peek-remote .
We don't have this choice with git-show-ref.
On the other hand that makes all command invocation (except the one
used for getting git core version) pass through git_cmd() subroutine.
>> git-show-ref is available since v1.4.4; the output format is slightly
>> different than git-peek-remote output format.
>
>> - if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
>> + if ($line =~ m/^([0-9a-fA-F]{40}) refs\/($type\/?[^\^]+)/) {
>
> I would rather do:
>
> m|^([0-9a-f]{40})\srefs/($type/?[^^]+)|
>
> which would catch both space and tab.
Feel free to do that (one nitpick: is [^^] more readable than [^\^]?).
Should I resend the patch?
--
Jakub Narebski
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH (amend)] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-24 22:20 ` Junio C Hamano
2006-11-24 22:35 ` Jakub Narebski
@ 2006-11-25 10:18 ` Jakub Narebski
2006-11-25 10:24 ` Jakub Narebski
2006-11-25 10:32 ` [PATCH (take 3)] " Jakub Narebski
2 siblings, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2006-11-25 10:18 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Jakub Narebski
Use "git show-ref --dereference" instead of "git peek-remote
$projectroot/project" in git_get_references. git-show-ref is faster
than git-peek-remote (40ms vs 56ms user+sys for git.git repository);
even faster is reading info/refs file (if it exists), but the
information in info/refs can be stale; that and the fact that
info/refs is meant for dumb protocol transports, not for gitweb.
git-show-ref is available since v1.4.4; the output format is slightly
different than git-peek-remote output format.
While at it make git_get_references return hash in list context,
and reference to hash (as it used to do) in scalar and void contexts.
Additionally this change makes all git commands invocations (except
the one used to get version of git core tools) go through git_cmd()
subroutine.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>
>> Use "git show-ref --dereference" instead of "git peek-remote ." in
>> git_get_references. git-show-ref is faster than git-peek-remote; even
>> faster is reading info/refs file (if it exists), but the information
>> in info/refs can be stale.
>
> More importantly, it is for dumb protocol transports, not for gitweb.
Mentioned in commit message.
> You forgot to mention that you fixed the last place that
> directly used "$GIT" to invoke the command, bypassing sub
> git_cmd. That is a consistency clean-up worth mentioning.
This is not fix, this is change of style. The style was to use
git peek-remote $projectroot/$project
instead of equivalent
git --git-dir=$projectroot/$project peek-remote .
We don't have this choice with git-show-ref.
On the other hand that makes all command invocation (except the one
used for getting git core version) pass through git_cmd() subroutine.
So yes, it is consistency clean-up.
>> git-show-ref is available since v1.4.4; the output format is slightly
>> different than git-peek-remote output format.
>
>> - if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
>> + if ($line =~ m/^([0-9a-fA-F]{40}) refs\/($type\/?[^\^]+)/) {
>
> I would rather do:
>
> m|^([0-9a-f]{40})\srefs/($type/?[^^]+)|
>
> which would catch both space and tab.
This addresses those concerns.
gitweb/gitweb.perl | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f06cd3e..2ebd9d7 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1154,14 +1154,15 @@ sub git_get_last_activity {
sub git_get_references {
my $type = shift || "";
my %refs;
- # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
- # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
- open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
+ # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
+ # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
+ open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
+ ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
or return;
while (my $line = <$fd>) {
chomp $line;
- if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
+ if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
if (defined $refs{$1}) {
push @{$refs{$1}}, $2;
} else {
@@ -1170,7 +1171,7 @@ sub git_get_references {
}
}
close $fd or return;
- return \%refs;
+ return wantarray ? %refs : \%refs;
}
sub git_get_rev_name_tags {
@@ -1293,8 +1294,9 @@ sub parse_commit {
$co{'author'} = $1;
$co{'author_epoch'} = $2;
$co{'author_tz'} = $3;
- if ($co{'author'} =~ m/^([^<]+) </) {
- $co{'author_name'} = $1;
+ if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
+ $co{'author_name'} = $1;
+ $co{'author_email'} = $2;
} else {
$co{'author_name'} = $co{'author'};
}
@@ -1303,7 +1305,12 @@ sub parse_commit {
$co{'committer_epoch'} = $2;
$co{'committer_tz'} = $3;
$co{'committer_name'} = $co{'committer'};
- $co{'committer_name'} =~ s/ <.*//;
+ if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
+ $co{'committer_name'} = $1;
+ $co{'committer_email'} = $2;
+ } else {
+ $co{'committer_name'} = $co{'committer'};
+ }
}
}
if (!defined $co{'tree'}) {
--
1.4.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH (amend)] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-25 10:18 ` [PATCH (amend)] " Jakub Narebski
@ 2006-11-25 10:24 ` Jakub Narebski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-11-25 10:24 UTC (permalink / raw)
To: git
Jakub Narebski wrote:
Ooops. This is a part of next patch to send. Please delete this two chunks.
Sorry for the mistake.
> @@ -1293,8 +1294,9 @@ sub parse_commit {
> $co{'author'} = $1;
> $co{'author_epoch'} = $2;
> $co{'author_tz'} = $3;
> - if ($co{'author'} =~ m/^([^<]+) </) {
> - $co{'author_name'} = $1;
> + if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
> + $co{'author_name'} = $1;
> + $co{'author_email'} = $2;
> } else {
> $co{'author_name'} = $co{'author'};
> }
> @@ -1303,7 +1305,12 @@ sub parse_commit {
> $co{'committer_epoch'} = $2;
> $co{'committer_tz'} = $3;
> $co{'committer_name'} = $co{'committer'};
> - $co{'committer_name'} =~ s/ <.*//;
> + if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
> + $co{'committer_name'} = $1;
> + $co{'committer_email'} = $2;
> + } else {
> + $co{'committer_name'} = $co{'committer'};
> + }
> }
> }
> if (!defined $co{'tree'}) {
--
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-24 22:20 ` Junio C Hamano
2006-11-24 22:35 ` Jakub Narebski
2006-11-25 10:18 ` [PATCH (amend)] " Jakub Narebski
@ 2006-11-25 10:32 ` Jakub Narebski
2006-11-25 10:42 ` Junio C Hamano
2 siblings, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2006-11-25 10:32 UTC (permalink / raw)
To: git, Junio C Hamano; +Cc: Jakub Narebski
Use "git show-ref --dereference" instead of "git peek-remote
$projectroot/project" in git_get_references. git-show-ref is faster
than git-peek-remote (40ms vs 56ms user+sys for git.git repository);
even faster is reading info/refs file (if it exists), but the
information in info/refs can be stale; that and the fact that
info/refs is meant for dumb protocol transports, not for gitweb.
git-show-ref is available since v1.4.4; the output format is slightly
different than git-peek-remote output format.
While at it make git_get_references return hash in list context,
and reference to hash (as it used to do) in scalar and void contexts.
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This is the final version.
Once again, I'm extremly sorry for the confusion with the previous
version...
gitweb/gitweb.perl | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f06cd3e..1cded75 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1154,14 +1154,15 @@ sub git_get_last_activity {
sub git_get_references {
my $type = shift || "";
my %refs;
- # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
- # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
- open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
+ # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
+ # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
+ open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
+ ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
or return;
while (my $line = <$fd>) {
chomp $line;
- if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
+ if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
if (defined $refs{$1}) {
push @{$refs{$1}}, $2;
} else {
@@ -1170,7 +1171,7 @@ sub git_get_references {
}
}
close $fd or return;
- return \%refs;
+ return wantarray ? %refs : \%refs;
}
sub git_get_rev_name_tags {
--
1.4.4.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-25 10:32 ` [PATCH (take 3)] " Jakub Narebski
@ 2006-11-25 10:42 ` Junio C Hamano
2006-11-25 11:08 ` Jakub Narebski
0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2006-11-25 10:42 UTC (permalink / raw)
To: Jakub Narebski; +Cc: git
Jakub Narebski <jnareb@gmail.com> writes:
> While at it make git_get_references return hash in list context,
> and reference to hash (as it used to do) in scalar and void contexts.
Why did you have to add this? Generally, context sensitive
returns make the program much harder to maintain, because it
forces the call sites to be extremely careful to choose between
"my ($foo) = func()" vs "my $foo = func()", and people who later
call the function inevitably make mistakes.
So unless there is a compelling reason, I'd rather not see more
"wantarray" in the program.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote
2006-11-25 10:42 ` Junio C Hamano
@ 2006-11-25 11:08 ` Jakub Narebski
0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2006-11-25 11:08 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>
>> While at it make git_get_references return hash in list context,
>> and reference to hash (as it used to do) in scalar and void contexts.
>
> Why did you have to add this? Generally, context sensitive
> returns make the program much harder to maintain, because it
> forces the call sites to be extremely careful to choose between
> "my ($foo) = func()" vs "my $foo = func()", and people who later
> call the function inevitably make mistakes.
>
> So unless there is a compelling reason, I'd rather not see more
> "wantarray" in the program.
O.K. I have browsed through gitweb, and I see that we almost always
want the hashref, not hash (for passing further).
--
Jakub Narebski
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-11-25 11:06 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-24 22:01 [PATCH] gitweb: Use git-show-ref instead of git-peek-remote Jakub Narebski
2006-11-24 22:20 ` Junio C Hamano
2006-11-24 22:35 ` Jakub Narebski
2006-11-25 10:18 ` [PATCH (amend)] " Jakub Narebski
2006-11-25 10:24 ` Jakub Narebski
2006-11-25 10:32 ` [PATCH (take 3)] " Jakub Narebski
2006-11-25 10:42 ` Junio C Hamano
2006-11-25 11:08 ` Jakub Narebski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).