Whamcloud - gitweb
LU-278 Improve regex for output of git describe
[fs/lustre-release.git] / lustre / scripts / version_tag-git.pl
1 my ($tag, $fcoms, $hash);
2
3 sub get_buildid()
4 {
5
6     return $main::am_buildid;
7
8 }
9
10 sub is_pristine()
11 {
12
13     if ($fcoms > 0) {
14         return 0;
15     }
16
17     my $diffcount=`git diff | wc -l`;
18     if ($diffcount > 0) {
19         return 0;
20     }
21
22     return 1;
23
24 }
25
26 sub get_tag()
27 {
28
29     return $tag;
30
31 }
32
33 # "git describe" will just return a tag name if the current commit is
34 # tagged.  Otherwise, the output will look something like this:
35 #
36 #     <tag name>-<commits beyong tag>-g<hash>
37 #
38 # Examples:
39 #     2.0.59-1-g4c20b1f
40 #     2.0.59-1somecompany-1-g4c20b1f
41 #     foobar-15-g2e937ca
42 #
43 my $desc=`git describe --tags`;
44 if ($desc =~ /(.+?)(?:-(\d)+-g([0-9a-f]+))\n?/) {
45     # tag with describe info added
46     $tag = $1;
47     $fcoms = $2;
48     $hash = $3;
49 } else {
50     # plain tag
51     $tag = $desc;
52     chomp $tag;
53     $fcoms = 0;
54     $hash = "";
55 }
56
57 1;