Auto-localversion doesn't detect tags correctly
PATCH 1/1 Auto-localversion doesn't detect tags correctly
The first version of scripts/setlocalversion failed to notice tags correctly, and such would always append the -gXXXXXXXX version identifier. This converts it to use git-rev-parse and the magic notation to reduce a tag to the commit it refers to ("$tag^0").
scripts/setlocalversion +28 -3
@@ -36,13 +36,38 @@ sub do_git_checks { chomp $head; close(H); - opendir(D,".git/refs/tags") or return; + unless (opendir(D,".git/refs/tags")) { + warn "Failed to open .git/refs/tags : " . $!; + return; + } foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) { - open(F,"<.git/refs/tags/" . $tagfile) or return; + unless (open(F,"<",".git/refs/tags/" . $tagfile)) { + warn "Failed to open .git/refs/tags/$tagfile : " . $!; + return; + } my $tag = <F>; chomp $tag; close(F); - return if ($tag eq $head); + + local(*oldstderr) = *STDERR; + open(STDERR,">","/dev/null") + or die "Failed to reopen stderr: $!"; + + unless (open(P,"-|","git-rev-parse",sprintf("%s^0",$tag))) { + *STDERR = *oldstderr; + die "Failed to open pipe from git-rev-parse: $!"; + } + + *STDERR = *oldstderr; + + my $commit = <P>; + chomp $commit; + + if ($tag eq $head) { + warn "$tagfile refers to commit $head (maybe indirectly)"; + return; + } + #return if ($tag eq $head); } closedir(D);
Signature · 2 lines
Ryan Anderson sometimes Pug Majere
Hi Ryan.
Quoted 6 lines
+++ linux-git/scripts/setlocalversion 2005-09-13 04:17:28.000000000 -0400
scripts/setlocalversion +0
-1@@ -36,13 +36,38 @@ sub do_git_checks { chomp $head; close(H); - opendir(D,".git/refs/tags") or return;
scripts/setlocalversion sub do_git_checks { · line 47
Quoted 10 lines
scripts/setlocalversion +8
-1+ unless (opendir(D,".git/refs/tags")) { + warn "Failed to open .git/refs/tags : " . $!; + return; + } foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) { - open(F,"<.git/refs/tags/" . $tagfile) or return; + unless (open(F,"<",".git/refs/tags/" . $tagfile)) { + warn "Failed to open .git/refs/tags/$tagfile : " . $!; + return; + }
Can the two operations be done somehow using git commands? With the above you assume all users have default setup with git files in .git, but one may decide for:
GIT/.git
kernel/<kernelsrc-tree>
and then use:
export GIT_DIR=../GIT/.git
You need to do some sanitycheck if git is installed first. which git-rev-list or similar.
Sam
PATCH 1/1 Auto-localversion should use git commands and behaviors
Auto-localversion support should use git commands and behaviors whenever possible.
This fully switches to using git-rev-parse to dereference tags and symbolic heads (HEAD, for example), and emulates the behavior of git with respect to the use of the environment variable GIT_DIR.
scripts/setlocalversion +41 -31
@@ -23,51 +23,61 @@ my @LOCALVERSIONS = (); # currently assume that all meaningful version boundaries are marked by a tag. # We don't care what the tag is, just that something exists. -# Git/Cogito store the top-of-tree "commit" in .git/HEAD +# Git/Cogito store the top-of-tree "committish" in .git/HEAD # A list of known tags sits in .git/refs/tags/ # # The simple trick here is to just compare the two of these, and if we get a # match, return nothing, otherwise, return a subset of the SHA-1 hash in # .git/HEAD +# First, a helper routine to convert symbolic names into +# git committish values. + +sub git_rev_parse { + my ($rev) = @_; + + local(*oldstderr) = *STDERR; + open(STDERR,">","/dev/null") + or die "Failed to reopen stderr: $!"; + + unless (open(P,"-|","git-rev-parse",sprintf("%s^0",$rev))) { + *STDERR = *oldstderr; + die "Failed to open pipe from git-rev-parse: $!"; + } + + *STDERR = *oldstderr; + + my $commit = <P>; + chomp $commit; + + close(P); + + return $commit; +} + +# Next, the guts, as outlined above. +# git-rev-parse $tag^0 evaluates $tag and dereferences it until +# we get to a committish + sub do_git_checks { - open(H,"<.git/HEAD") or return; - my $head = <H>; - chomp $head; - close(H); + my $sanity_check = `which git-rev-parse`; + return unless $sanity_check =~ m/git-rev-parse/; + + my $head = git_rev_parse("HEAD"); + + my $GITDIR = exists $ENV{'GIT_DIR'} ? $ENV{'GIT_DIR'} : ".git"; - unless (opendir(D,".git/refs/tags")) { - warn "Failed to open .git/refs/tags : " . $!; + + unless (opendir(D,"$GITDIR/refs/tags")) { + warn "Failed to open $GITDIR/refs/tags : " . $!; return; } foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) { - unless (open(F,"<",".git/refs/tags/" . $tagfile)) { - warn "Failed to open .git/refs/tags/$tagfile : " . $!; - return; - } - my $tag = <F>; - chomp $tag; - close(F); - - local(*oldstderr) = *STDERR; - open(STDERR,">","/dev/null") - or die "Failed to reopen stderr: $!"; - - unless (open(P,"-|","git-rev-parse",sprintf("%s^0",$tag))) { - *STDERR = *oldstderr; - die "Failed to open pipe from git-rev-parse: $!"; - } - - *STDERR = *oldstderr; - - my $commit = <P>; - chomp $commit; + my $commit = git_rev_parse($tagfile); - if ($tag eq $head) { - warn "$tagfile refers to commit $head (maybe indirectly)"; + if ($commit eq $head) { return; } - #return if ($tag eq $head); } closedir(D);
Signature · 2 lines
Ryan Anderson sometimes Pug Majere