Whamcloud - gitweb
LU-278 Improve regex for output of git describe
authorChristopher J. Morrone <morrone2@llnl.gov>
Thu, 5 May 2011 22:08:44 +0000 (15:08 -0700)
committerOleg Drokin <green@whamcloud.com>
Mon, 12 Dec 2011 18:35:52 +0000 (13:35 -0500)
Improve the regex in version_tag-git.pl to properly parse the output
then the current commit is tagged, and when the tag names are longer
than just the digits used in the upstream version tags.

Addition from Ned:

Trim trailing newline from git describe output in the
case where the current commit is tagged.

Change-Id: I0a6a1b54f9e2dbd381a6d00f9dcf47d9b8b66616
Signed-off-by: Christopher J. Morrone <morrone2@llnl.gov>
Reviewed-on: http://review.whamcloud.com/509
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Brian J. Murrell <brian@whamcloud.com>
Reviewed-by: Christopher J. Morrone <chris.morrone.llnl@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/scripts/version_tag-git.pl

index 4912de8..1f0dbf4 100644 (file)
@@ -30,10 +30,28 @@ sub get_tag()
 
 }
 
 
 }
 
+# "git describe" will just return a tag name if the current commit is
+# tagged.  Otherwise, the output will look something like this:
+#
+#     <tag name>-<commits beyong tag>-g<hash>
+#
+# Examples:
+#     2.0.59-1-g4c20b1f
+#     2.0.59-1somecompany-1-g4c20b1f
+#     foobar-15-g2e937ca
+#
 my $desc=`git describe --tags`;
 my $desc=`git describe --tags`;
-$desc =~ /([^-]+)(?:-(.+)-(.+))?\n/;
-$tag = $1;
-$fcoms = $2;
-$hash = $3;
+if ($desc =~ /(.+?)(?:-(\d)+-g([0-9a-f]+))\n?/) {
+    # tag with describe info added
+    $tag = $1;
+    $fcoms = $2;
+    $hash = $3;
+} else {
+    # plain tag
+    $tag = $desc;
+    chomp $tag;
+    $fcoms = 0;
+    $hash = "";
+}
 
 1;
 
 1;