From: Sandro Santilli Date: Mon, 13 Feb 2012 09:15:23 +0000 (+0000) Subject: Add support for fetching SVN revision from local git-svn repository X-Git-Tag: 2.0.0alpha5~40 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2492588fafa37f74803d9449217bd010b86b82bf;p=postgis Add support for fetching SVN revision from local git-svn repository git-svn-id: http://svn.osgeo.org/postgis/trunk@9158 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/utils/svn_repo_revision.pl b/utils/svn_repo_revision.pl index 3eae91a87..392b35f87 100755 --- a/utils/svn_repo_revision.pl +++ b/utils/svn_repo_revision.pl @@ -2,62 +2,112 @@ $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 {