Skip to content

Commit 117a93d

Browse files
Rene ScharfeSam Ravnborg
authored andcommitted
kbuild: Use git in scripts/setlocalversion
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> Acked-by: Ryan Anderson <ryan@michonline.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 253dfa6 commit 117a93d

1 file changed

Lines changed: 17 additions & 51 deletions

File tree

‎scripts/setlocalversion‎

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,22 @@
1-
#!/usr/bin/perl
2-
# Copyright 2004 - Ryan Anderson <ryan@michonline.com> GPL v2
1+
#!/bin/sh
2+
# Print additional version information for non-release trees.
33

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);
4+
usage() {
5+
echo "Usage: $0 [srctree]" >&2
6+
exit 1
147
}
158

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);
9+
cd "${1:-.}" || usage
3810

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-
}
11+
# Check for git and a git repo.
12+
if head=`git rev-parse --verify HEAD 2>/dev/null`; then
13+
# Do we have an untagged version?
14+
if [ "`git name-rev --tags HEAD`" = "HEAD undefined" ]; then
15+
printf '%s%s' -g `echo "$head" | cut -c1-8`
16+
fi
5517

56-
printf "-%s\n", join("-",@LOCALVERSIONS) if (scalar @LOCALVERSIONS > 0);
18+
# Are there uncommitted changes?
19+
if git diff-files | read dummy; then
20+
printf '%s' -git_dirty
21+
fi
22+
fi

0 commit comments

Comments
 (0)