]> granicus.if.org Git - postgis/commitdiff
Add support for fetching SVN revision from local git-svn repository
authorSandro Santilli <strk@keybit.net>
Mon, 13 Feb 2012 09:15:23 +0000 (09:15 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 13 Feb 2012 09:15:23 +0000 (09:15 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9158 b70326c6-7e19-0410-871a-916f4a2858ee

utils/svn_repo_revision.pl

index 3eae91a87cc83172c8d4ba3a55abf06a3b15fd80..392b35f8736cd1c5f0313bc9f41e72834e567133 100755 (executable)
 
 $ENV{"LC_ALL"} = "C";
 
-use Cwd;
-my $cwd = &Cwd::cwd();
+use warnings;
+use strict;
 
-# TODO: test on old systems, I think I saw some `which`
-#       implementations returning "nothing found" or something
-#       like that, making the later if ( ! $svn_exe ) always false
-#
-my $svn_exe = `which svn`;
-
-my $svn_revision = 0;
-my $defn_string = $defn_string_start . $svn_revision;
-my $rev_file = "postgis_svn_revision.h";
+my $top_srcdir = ".";
+my $rev_file = $top_srcdir.'/postgis_svn_revision.h';
 
+my $target = 'local';
 $target = $ARGV[0] if $ARGV[0];
 
-# Don't muck with things if you can't find svn
-if ( ! $svn_exe ) {
-  if ( ! -f $rev_file ) {
-    &write_defn(0);
-    exit(0);
-  }
-  else {
-    exit(0);
+# Read the svn revision number
+my $svn_rev = &read_rev($target);
+
+# TODO: compare what's known already with what's to be written
+
+# Write it 
+&write_defn($svn_rev);
+
+
+sub read_rev {
+
+  my $target = shift;
+
+  #print STDERR "Target: $target\n";
+
+  my $svn_info;
+
+  if ( $target eq "local" ) {
+    if ( -d $top_srcdir."/.svn" ) {
+      #print STDERR "There's a ". $top_srcdir."/.svn dir\n";
+      $svn_info  = &read_rev_svn($target);
+    } elsif ( -d $top_srcdir."/.git" ) {
+      #print STDERR "There's a ". $top_srcdir."/.git dir\n";
+      $svn_info  = &read_rev_git();
+    } else {
+      print STDERR "Can't fetch local revision (neither .svn nor .git found)\n";
+      $svn_info = 0;
+    }
+  } else {
+    $svn_info  = &read_rev_svn($target);
   }
-};
 
-# Don't muck with things if you aren't in an svn repository
-if ( $target eq "local" && ! -d ".svn" ) {
-  if ( ! -f $rev_file ) {
-    &write_defn(0);
-    exit(0);
+  return $svn_info;
+
+}
+
+sub read_rev_git {
+
+  # TODO: test on old systems, I think I saw some `which`
+  #       implementations returning "nothing found" or something
+  #       like that, making the later if ( ! $svn_exe ) always false
+  #
+  my $git_exe = `which git`;
+  if ( ! $git_exe ) {
+    print STDERR "Can't fetch SVN revision: no git executable found\n";
+    return 0;
   }
-  else {
-    exit(0);
+  chop($git_exe);
+
+  my $cmd  = "${git_exe} svn info";
+  #print STDERR "cmd: ${cmd}\n";
+  my $svn_info  = `$cmd`;
+  #print STDERR "git_svn_info_output: [[[${svn_info}]]]\n";
+
+  my $rev;
+  if ( $svn_info =~ /Last Changed Rev: (\d+)/ ) {
+    $rev = $1;
+  } else {
+    print STDERR "Can't fetch SVN revision: no 'Loast Changed Rev' in `git svn info` output\n";
+    $rev = 0;
   }
-}
 
-# Read the svn revision number
-my $svn_info;
-if ( $target eq "local" ) {
-  $svn_info  = `svn info`;
-} else {
-  $svn_info  = `svn info $target`;
+  return $rev;
 }
 
-if ( $svn_info =~ /Last Changed Rev: (\d+)/ ) {
-  &write_defn($1);
-}
-else {
-  if ( ! -f $rev_file ) {
-    &write_defn(0);
-    exit(0);
+sub read_rev_svn {
+
+  my $target = shift;
+
+  # TODO: test on old systems, I think I saw some `which`
+  #       implementations returning "nothing found" or something
+  #       like that, making the later if ( ! $svn_exe ) always false
+  #
+  my $svn_exe = `which svn`;
+  if ( ! $svn_exe ) {
+    print STDERR "Can't fetch SVN revision: no svn executable found\n";
+    return 0;
+  }
+  chop($svn_exe);
+
+
+  my $svn_info;
+  if ( $target eq "local" ) {
+    $svn_info  = `${svn_exe} info`;
+  } else {
+    $svn_info  = `${svn_exe} info $target`;
   }
-  else {
-    exit(0);
+
+  my $rev;
+  if ( $svn_info =~ /Last Changed Rev: (\d+)/ ) {
+    $rev = $1;
+  } else {
+    print STDERR "Can't fetch SVN revision: no 'Loast Changed Rev' in `svn info` output\n";
+    $rev = 0;
   }
+
+  return $rev;
 }
 
 sub write_defn {