* [PATCH] Calculate $commitsha1 in update() only when needed
@ 2007-12-08 5:07 Pavel Roskin
2007-12-08 8:17 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Pavel Roskin @ 2007-12-08 5:07 UTC (permalink / raw)
To: git
This suppresses unhelpful error messages from git rev-parse during
checkout if the module doesn't exist.
Signed-off-by: Pavel Roskin <proski@gnu.org>
---
git-cvsserver.perl | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index ecded3b..409b301 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -2427,9 +2427,6 @@ sub update
# first lets get the commit list
$ENV{GIT_DIR} = $self->{git_path};
- my $commitsha1 = `git rev-parse $self->{module}`;
- chomp $commitsha1;
-
my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
{
@@ -2440,8 +2437,13 @@ sub update
my $git_log;
my $lastcommit = $self->_get_prop("last_commit");
- if (defined $lastcommit && $lastcommit eq $commitsha1) { # up-to-date
- return 1;
+ if (defined $lastcommit) {
+ my $commitsha1 = `git rev-parse $self->{module}`;
+ chomp $commitsha1;
+
+ if ($lastcommit eq $commitsha1) { # up-to-date
+ return 1;
+ }
}
# Start exclusive lock here...
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Calculate $commitsha1 in update() only when needed
2007-12-08 5:07 [PATCH] Calculate $commitsha1 in update() only when needed Pavel Roskin
@ 2007-12-08 8:17 ` Junio C Hamano
2007-12-08 8:48 ` Pavel Roskin
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2007-12-08 8:17 UTC (permalink / raw)
To: Pavel Roskin; +Cc: git
Pavel Roskin <proski@gnu.org> writes:
> diff --git a/git-cvsserver.perl b/git-cvsserver.perl
> index ecded3b..409b301 100755
> --- a/git-cvsserver.perl
> +++ b/git-cvsserver.perl
> @@ -2427,9 +2427,6 @@ sub update
> # first lets get the commit list
> $ENV{GIT_DIR} = $self->{git_path};
>
> - my $commitsha1 = `git rev-parse $self->{module}`;
> - chomp $commitsha1;
> -
> my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
> unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
> {
Hmm. The first rev-parse could be squelched with 2>/dev/null and then
you can check if it does not match [a-f0-9]{40} and die early before
running "cat-file commit", can't you?
Also the regexp to check "tree" object name above seems quite wrong ;-)
If the purpose of this check is to make sure if the ref points at a
commit object, perhaps...
my $commitsha1 = `git rev-parse --verify $self->{module}^0 2>&1`;
chomp($commitsha1);
if ($commitsha1 !~ /^[0-9a-f]{40}$/) {
die "no such module $self->{module}";
}
Then the other hunk below would become unnecessary, I think.
> @@ -2440,8 +2437,13 @@ sub update
> my $git_log;
> my $lastcommit = $self->_get_prop("last_commit");
>
> - if (defined $lastcommit && $lastcommit eq $commitsha1) { # up-to-date
> - return 1;
> + if (defined $lastcommit) {
> + my $commitsha1 = `git rev-parse $self->{module}`;
> + chomp $commitsha1;
> +
> + if ($lastcommit eq $commitsha1) { # up-to-date
> + return 1;
> + }
> }
>
> # Start exclusive lock here...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Calculate $commitsha1 in update() only when needed
2007-12-08 8:17 ` Junio C Hamano
@ 2007-12-08 8:48 ` Pavel Roskin
0 siblings, 0 replies; 3+ messages in thread
From: Pavel Roskin @ 2007-12-08 8:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Quoting Junio C Hamano <gitster@pobox.com>:
> Pavel Roskin <proski@gnu.org> writes:
>
>> diff --git a/git-cvsserver.perl b/git-cvsserver.perl
>> index ecded3b..409b301 100755
>> --- a/git-cvsserver.perl
>> +++ b/git-cvsserver.perl
>> @@ -2427,9 +2427,6 @@ sub update
>> # first lets get the commit list
>> $ENV{GIT_DIR} = $self->{git_path};
>>
>> - my $commitsha1 = `git rev-parse $self->{module}`;
>> - chomp $commitsha1;
>> -
>> my $commitinfo = `git cat-file commit $self->{module} 2>&1`;
>> unless ( $commitinfo =~ /tree\s+[a-zA-Z0-9]{40}/ )
>> {
>
> Hmm. The first rev-parse could be squelched with 2>/dev/null and then
> you can check if it does not match [a-f0-9]{40} and die early before
> running "cat-file commit", can't you?
Yes, my impression is that the code in question can be improved a lot.
This is specifically the error message I'd like to see fixed in some
way, as it's confusing to beginners trying to check out the module for
the first time.
$ CVS_SERVER=/home/proski/bin/git-cvsserver cvs -d \
:fork:/home/proski/src/qgit/.git co foo
fatal: ambiguous argument 'foo': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions
Invalid module 'foo' at /home/proski/bin/git-cvsserver line 2437,
<STDIN> line 15.
cvs [checkout aborted]: end of file from server (consult above
messages if any)
It's possible that the message about "--" makes sense and it should
actually be added in some spaces.
--
Regards,
Pavel Roskin
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-12-08 8:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-08 5:07 [PATCH] Calculate $commitsha1 in update() only when needed Pavel Roskin
2007-12-08 8:17 ` Junio C Hamano
2007-12-08 8:48 ` Pavel Roskin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox