linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Use git in scripts/setlocalversion
@ 2006-01-04 19:42 Rene Scharfe
  2006-01-04 22:43 ` Ryan Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Rene Scharfe @ 2006-01-04 19:42 UTC (permalink / raw)
  To: Ryan Anderson, Sam Ravnborg; +Cc: linux-kernel, Linus Torvalds

Currently scripts/setlocalversion is a Perl script that tries to figure
out the current git commit ID of a repo without using git.  It also
imports Digest::MD5 without using it and generally is too big for the
small task it does. :]  And it always reports a git ID, even when the
HEAD is tagged -- this is a bug.

This patch replaces it with a Bourne Shell script that uses git
commands to do the same.  I can't come up with a scenario where someone
would use a git repo and refuse to install git core at the same time,
so I think it's reasonable to assume git is available.

The new script also reports uncommitted changes by adding -git_dirty to
the version string.  Obviously you can't see from that _what_ has been
changed from the last commit, so it's more of a reminder that you
forgot to commit something.

The script is easily extensible: simply add a check for Mercurial (or
whatever) below the git check.

Note: the script doesn't print a newline char anymore.  That's only
because it was easier to implement it that way, not a feature (or bug).
'make kernelrelease' doesn't care.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 7c805c8..f54dac8 100644
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -1,56 +1,22 @@
-#!/usr/bin/perl
-# Copyright 2004 - Ryan Anderson <ryan@michonline.com>  GPL v2
+#!/bin/sh
+# Print additional version information for non-release trees.
 
-use strict;
-use warnings;
-use Digest::MD5;
-require 5.006;
-
-if (@ARGV != 1) {
-	print <<EOT;
-Usage: setlocalversion <srctree>
-EOT
-	exit(1);
-}
-
-my ($srctree) = @ARGV;
-chdir($srctree);
-
-my @LOCALVERSIONS = ();
-
-# We are going to use the following commands to try and determine if this
-# repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches) We
-# 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
-# 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
-
-sub do_git_checks {
-	open(H,"<.git/HEAD") or return;
-	my $head = <H>;
-	chomp $head;
-	close(H);
-
-	opendir(D,".git/refs/tags") or return;
-	foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) {
-		open(F,"<.git/refs/tags/" . $tagfile) or return;
-		my $tag = <F>;
-		chomp $tag;
-		close(F);
-		return if ($tag eq $head);
-	}
-	closedir(D);
-
-	push @LOCALVERSIONS, "g" . substr($head,0,8);
+usage() {
+	echo "Usage: $0 [srctree]" >&2
+	exit 1
 }
 
-if ( -d ".git") {
-	do_git_checks();
-}
+cd "${1:-.}" || usage
 
-printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);
+# Check for git and a git repo.
+if head=`git rev-parse --verify HEAD 2>/dev/null`; then
+	# Do we have an untagged version?
+	if  [ "`git name-rev --tags HEAD`" = "HEAD undefined" ]; then
+		printf '%s%s' -g `echo "$head" | cut -c1-8`
+	fi
+
+	# Are there uncommitted changes?
+	if git diff-files | read dummy; then
+		printf '%s' -git_dirty
+	fi
+fi

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use git in scripts/setlocalversion
  2006-01-04 19:42 [PATCH] Use git in scripts/setlocalversion Rene Scharfe
@ 2006-01-04 22:43 ` Ryan Anderson
  2006-01-06 19:47 ` Sam Ravnborg
  2006-01-09  3:47 ` [PATCH] Use git in scripts/setlocalversion Coywolf Qi Hunt
  2 siblings, 0 replies; 7+ messages in thread
From: Ryan Anderson @ 2006-01-04 22:43 UTC (permalink / raw)
  To: Rene Scharfe; +Cc: Sam Ravnborg, linux-kernel, Linus Torvalds

[-- Attachment #1: Type: text/plain, Size: 1648 bytes --]

Rene Scharfe wrote:
> Currently scripts/setlocalversion is a Perl script that tries to figure
> out the current git commit ID of a repo without using git.  It also
> imports Digest::MD5 without using it and generally is too big for the
> small task it does. :]  And it always reports a git ID, even when the
> HEAD is tagged -- this is a bug.

Yes.  I'm pretty sure I sent Sam a patch for that at one point ages ago,
but I've been distracted and haven't updated it recently.

I think using git-name-rev --tags as this change does is a lot simpler
than what I was trying to do.

So, Sam, if you'd prefer this version, feel free, or let me know and
I'll resend the one or two patches I have hanging around to you.

> This patch replaces it with a Bourne Shell script that uses git
> commands to do the same.  I can't come up with a scenario where someone
> would use a git repo and refuse to install git core at the same time,
> so I think it's reasonable to assume git is available.
> 
> The new script also reports uncommitted changes by adding -git_dirty to
> the version string.  Obviously you can't see from that _what_ has been
> changed from the last commit, so it's more of a reminder that you
> forgot to commit something.

And this is a decent feature, too. I like it.

The only reservation I have about converting from Perl to Bourne shell
is that if adding support for, say, Mercurial (or maybe CVS, etc) wants
to mangle it somehow, via say MD5, that becomes a little bit more
difficult to do, or at worst, introduces an additional dependency on
something like md5sum.

So, I like it:

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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use git in scripts/setlocalversion
  2006-01-04 19:42 [PATCH] Use git in scripts/setlocalversion Rene Scharfe
  2006-01-04 22:43 ` Ryan Anderson
@ 2006-01-06 19:47 ` Sam Ravnborg
  2006-01-08  9:35   ` [PATCH] setlocalversion: Change -git_dirty to just -dirty Ryan Anderson
  2006-01-09  3:47 ` [PATCH] Use git in scripts/setlocalversion Coywolf Qi Hunt
  2 siblings, 1 reply; 7+ messages in thread
From: Sam Ravnborg @ 2006-01-06 19:47 UTC (permalink / raw)
  To: Rene Scharfe; +Cc: Ryan Anderson, linux-kernel, Linus Torvalds

On Wed, Jan 04, 2006 at 08:42:03PM +0100, Rene Scharfe wrote:
> Currently scripts/setlocalversion is a Perl script that tries to figure
> out the current git commit ID of a repo without using git.  It also
> imports Digest::MD5 without using it and generally is too big for the
> small task it does. :]  And it always reports a git ID, even when the
> HEAD is tagged -- this is a bug.
> 
> This patch replaces it with a Bourne Shell script that uses git
> commands to do the same.  I can't come up with a scenario where someone
> would use a git repo and refuse to install git core at the same time,
> so I think it's reasonable to assume git is available.
> 
> The new script also reports uncommitted changes by adding -git_dirty to
> the version string.  Obviously you can't see from that _what_ has been
> changed from the last commit, so it's more of a reminder that you
> forgot to commit something.
> 
> The script is easily extensible: simply add a check for Mercurial (or
> whatever) below the git check.
> 
> Note: the script doesn't print a newline char anymore.  That's only
> because it was easier to implement it that way, not a feature (or bug).
> 'make kernelrelease' doesn't care.
> 
> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>

Thanks Rene.
Applied with an:
Acked-by: Ryan Anderson <ryan@michonline.com>

	Sam

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] setlocalversion: Change -git_dirty to just -dirty
  2006-01-06 19:47 ` Sam Ravnborg
@ 2006-01-08  9:35   ` Ryan Anderson
  2006-01-08 17:45     ` Sam Ravnborg
  0 siblings, 1 reply; 7+ messages in thread
From: Ryan Anderson @ 2006-01-08  9:35 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Rene Scharfe, linux-kernel, Linus Torvalds


When building Debian packages directly from the git tree, the appended
"git_dirty" is a problem due to the underscore.  In order to cause the
least problems, change that just to "dirty".

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

--- linux-git.orig/scripts/setlocalversion	2006-01-07 01:48:21.000000000 -0500
+++ linux-git/scripts/setlocalversion	2006-01-08 04:32:49.000000000 -0500
@@ -17,6 +17,6 @@ if head=`git rev-parse --verify HEAD 2>/
 
 	# Are there uncommitted changes?
 	if git diff-files | read dummy; then
-		printf '%s' -git_dirty
+		printf '%s' -dirty
 	fi
 fi


-- 

Ryan Anderson
  sometimes Pug Majere

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] setlocalversion: Change -git_dirty to just -dirty
  2006-01-08  9:35   ` [PATCH] setlocalversion: Change -git_dirty to just -dirty Ryan Anderson
@ 2006-01-08 17:45     ` Sam Ravnborg
  0 siblings, 0 replies; 7+ messages in thread
From: Sam Ravnborg @ 2006-01-08 17:45 UTC (permalink / raw)
  To: Ryan Anderson; +Cc: Rene Scharfe, linux-kernel, Linus Torvalds

On Sun, Jan 08, 2006 at 04:35:36AM -0500, Ryan Anderson wrote:
> 
> When building Debian packages directly from the git tree, the appended
> "git_dirty" is a problem due to the underscore.  In order to cause the
> least problems, change that just to "dirty".
> 
> Signed-off-by: Ryan Anderson <ryan@michonline.com>
Applied,

	Sam

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use git in scripts/setlocalversion
  2006-01-04 19:42 [PATCH] Use git in scripts/setlocalversion Rene Scharfe
  2006-01-04 22:43 ` Ryan Anderson
  2006-01-06 19:47 ` Sam Ravnborg
@ 2006-01-09  3:47 ` Coywolf Qi Hunt
  2006-01-09  5:58   ` Sam Ravnborg
  2 siblings, 1 reply; 7+ messages in thread
From: Coywolf Qi Hunt @ 2006-01-09  3:47 UTC (permalink / raw)
  To: Rene Scharfe; +Cc: Ryan Anderson, Sam Ravnborg, linux-kernel, Linus Torvalds

2006/1/5, Rene Scharfe <rene.scharfe@lsrfire.ath.cx>:
> Currently scripts/setlocalversion is a Perl script that tries to figure
> out the current git commit ID of a repo without using git.  It also
> imports Digest::MD5 without using it and generally is too big for the
> small task it does. :]  And it always reports a git ID, even when the
> HEAD is tagged -- this is a bug.
>
> This patch replaces it with a Bourne Shell script that uses git
> commands to do the same.  I can't come up with a scenario where someone
> would use a git repo and refuse to install git core at the same time,
> so I think it's reasonable to assume git is available.
>
> The new script also reports uncommitted changes by adding -git_dirty to
> the version string.  Obviously you can't see from that _what_ has been
> changed from the last commit, so it's more of a reminder that you
> forgot to commit something.
>
> The script is easily extensible: simply add a check for Mercurial (or
> whatever) below the git check.
>
> Note: the script doesn't print a newline char anymore.  That's only
> because it was easier to implement it that way, not a feature (or bug).
> 'make kernelrelease' doesn't care.
>
> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
>
> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index 7c805c8..f54dac8 100644
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -1,56 +1,22 @@
> -#!/usr/bin/perl
> -# Copyright 2004 - Ryan Anderson <ryan@michonline.com>  GPL v2
> +#!/bin/sh

You didn't update the caller in the top Makefile, but that's ok.
--
Coywolf Qi Hunt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use git in scripts/setlocalversion
  2006-01-09  3:47 ` [PATCH] Use git in scripts/setlocalversion Coywolf Qi Hunt
@ 2006-01-09  5:58   ` Sam Ravnborg
  0 siblings, 0 replies; 7+ messages in thread
From: Sam Ravnborg @ 2006-01-09  5:58 UTC (permalink / raw)
  To: Coywolf Qi Hunt; +Cc: Rene Scharfe, Ryan Anderson, linux-kernel, Linus Torvalds

On Mon, Jan 09, 2006 at 11:47:12AM +0800, Coywolf Qi Hunt wrote:
> 2006/1/5, Rene Scharfe <rene.scharfe@lsrfire.ath.cx>:
> > Currently scripts/setlocalversion is a Perl script that tries to figure
> > out the current git commit ID of a repo without using git.  It also
> > imports Digest::MD5 without using it and generally is too big for the
> > small task it does. :]  And it always reports a git ID, even when the
> > HEAD is tagged -- this is a bug.
> >
> > This patch replaces it with a Bourne Shell script that uses git
> > commands to do the same.  I can't come up with a scenario where someone
> > would use a git repo and refuse to install git core at the same time,
> > so I think it's reasonable to assume git is available.
 
> You didn't update the caller in the top Makefile, but that's ok.

It's fixed in my tree.

	Sam

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-01-09  5:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-04 19:42 [PATCH] Use git in scripts/setlocalversion Rene Scharfe
2006-01-04 22:43 ` Ryan Anderson
2006-01-06 19:47 ` Sam Ravnborg
2006-01-08  9:35   ` [PATCH] setlocalversion: Change -git_dirty to just -dirty Ryan Anderson
2006-01-08 17:45     ` Sam Ravnborg
2006-01-09  3:47 ` [PATCH] Use git in scripts/setlocalversion Coywolf Qi Hunt
2006-01-09  5:58   ` Sam Ravnborg

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).