diff options
author | Ryan Anderson <ryan@michonline.com> | 2005-07-31 04:57:49 -0400 |
---|---|---|
committer | Sam Ravnborg <sam@mars.(none)> | 2005-08-10 15:11:23 -0400 |
commit | aaebf4332018980fef4e601d1b5a6e52dd9e9ae4 (patch) | |
tree | 394ff78f08be95894fe941c752632dcb2e0a0ebf /scripts | |
parent | dbec486632d2303f5c0e75af7a8473fa4c4a145a (diff) |
[PATCH] kbuild: automatically append a short string to the version based upon the git commit
If CONFIG_AUTO_LOCALVERSION is set, the user is using a git-based tree, and the
current HEAD is not referred to by any tags in .git/refs/tags/, append -g and
the first 8 characters of the commit to the version string. This makes it
easier to use git-bisect, and/or to do a daily build, without trampling on your
older, working builds, or accidentally setting up conflicting sets of modules.
Signed-off-by: Ryan Anderson <ryan@michonline.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/setlocalversion | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/setlocalversion b/scripts/setlocalversion new file mode 100644 index 000000000000..7c805c8fccd2 --- /dev/null +++ b/scripts/setlocalversion | |||
@@ -0,0 +1,56 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # Copyright 2004 - Ryan Anderson <ryan@michonline.com> GPL v2 | ||
3 | |||
4 | use strict; | ||
5 | use warnings; | ||
6 | use Digest::MD5; | ||
7 | require 5.006; | ||
8 | |||
9 | if (@ARGV != 1) { | ||
10 | print <<EOT; | ||
11 | Usage: setlocalversion <srctree> | ||
12 | EOT | ||
13 | exit(1); | ||
14 | } | ||
15 | |||
16 | my ($srctree) = @ARGV; | ||
17 | chdir($srctree); | ||
18 | |||
19 | my @LOCALVERSIONS = (); | ||
20 | |||
21 | # We are going to use the following commands to try and determine if this | ||
22 | # repository is at a Version boundary (i.e, 2.6.10 vs 2.6.10 + some patches) We | ||
23 | # currently assume that all meaningful version boundaries are marked by a tag. | ||
24 | # We don't care what the tag is, just that something exists. | ||
25 | |||
26 | # Git/Cogito store the top-of-tree "commit" in .git/HEAD | ||
27 | # A list of known tags sits in .git/refs/tags/ | ||
28 | # | ||
29 | # The simple trick here is to just compare the two of these, and if we get a | ||
30 | # match, return nothing, otherwise, return a subset of the SHA-1 hash in | ||
31 | # .git/HEAD | ||
32 | |||
33 | sub do_git_checks { | ||
34 | open(H,"<.git/HEAD") or return; | ||
35 | my $head = <H>; | ||
36 | chomp $head; | ||
37 | close(H); | ||
38 | |||
39 | opendir(D,".git/refs/tags") or return; | ||
40 | foreach my $tagfile (grep !/^\.{1,2}$/, readdir(D)) { | ||
41 | open(F,"<.git/refs/tags/" . $tagfile) or return; | ||
42 | my $tag = <F>; | ||
43 | chomp $tag; | ||
44 | close(F); | ||
45 | return if ($tag eq $head); | ||
46 | } | ||
47 | closedir(D); | ||
48 | |||
49 | push @LOCALVERSIONS, "g" . substr($head,0,8); | ||
50 | } | ||
51 | |||
52 | if ( -d ".git") { | ||
53 | do_git_checks(); | ||
54 | } | ||
55 | |||
56 | printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0); | ||