mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Anderson <ryan@michonline.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] Auto-localversion should use git commands and behaviors
Date: Mon, 26 Sep 2005 02:43:03 -0400	[thread overview]
Message-ID: <20050926064302.GA23034@mythryan2.michonline.com> (raw)
In-Reply-To: <20050914044623.GA8099@mars.ravnborg.org>

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.

Signed-off-by: Ryan Anderson <ryan@michonline.com>

Index: linux-git/scripts/setlocalversion
===================================================================
--- linux-git.orig/scripts/setlocalversion	2005-09-25 15:00:49.000000000 -0400
+++ linux-git/scripts/setlocalversion	2005-09-26 02:36:33.000000000 -0400
@@ -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);
 

-- 

Ryan Anderson
  sometimes Pug Majere

      reply	other threads:[~2005-09-26  6:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13  8:20 [PATCH] Auto-localversion doesn't detect tags correctly Ryan Anderson
2005-09-14  4:46 ` Sam Ravnborg
2005-09-26  6:43   ` Ryan Anderson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050926064302.GA23034@mythryan2.michonline.com \
    --to=ryan@michonline.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®