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

Re: [PATCH] Calculate $commitsha1 in update() only when needed

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 8, 2007, 08:17 UTC
Message-ID
<7vtzmtwqff.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20071208050745.29462.74137.stgit@dv.roinet.com>
Pavel Roskin <proski@gnu.org> writes:
Show 14 quoted lines
> 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.
Show 16 quoted lines
> @@ -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...
Previous: Pavel RoskinNext: Pavel Roskin
Message 2 of 3 in “Calculate $commitsha1 in update() only when needed”
  1. Calculate $commitsha1 in update() only when neededPavel Roskin, Dec 8, 2007
  2. Junio C HamanoDec 8, 2007
  3. Pavel RoskinDec 8, 2007

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.