Author: paul
Date: 2006-09-23 05:48:41 +0200 (Sat, 23 Sep 2006)
New Revision: 3439
Log:
Remove use of Unix programs from Perl script
Modified:
trunk/tools/get-svn-revision.pl
Modified: trunk/tools/get-svn-revision.pl
===================================================================
--- trunk/tools/get-svn-revision.pl 2006-09-22 20:04:49 UTC (rev 3438)
+++ trunk/tools/get-svn-revision.pl 2006-09-23 03:48:41 UTC (rev 3439)
Changed blocks: 1, Lines Added: 106, Lines Deleted: 44; 6669 bytes
@@ -17,98 +17,160 @@
# - Enable script to get remote (parent) repository revision, too
# (use -R option). Default behavior is to get local revision, as
# before (use no option or -L option).
-# 2006-09-20
-# - Port /bin/sh version to Perl.
+# 2006-09-22
+# - Port /bin/sh version to Perl, avoiding use of Unix programs to enable
+# use on Windows.
use strict;
my $debug = 1;
+# Run a command, first first line that matches the given pattern
+# at the beginning of line, strip that pattern from the beginning
+# of theh line, return the resultl.
+
+# Example: Match "Revision: 3438" using "Revision:", return "3438"
+
+# If a second pattern is given, use it to strip additional junk
+# from the result line.
+
+sub run_cmd
+{
+my ($cmd, $pat, $pat2) = @_;
+
+ warn "Execute: $cmd, look for '$pat'\n" if $debug;
+ open (CMD, "$cmd|") or die "$0: cannot run command '$cmd':$!\n";
+ while (chomp ($_ = <CMD>))
+ {
+ last if s/^$pat\s*//;
+ }
+ close (CMD);
+ warn "Result1: $_\n" if $debug;
+ s/$pat2// if $pat2;
+ warn "Result2: $_\n" if $debug;
+ return $_;
+}
+
+
sub get_local_revision
{
-my $DEPOT;
+my $depot;
if (-d ".svn")
{
warn "This is a Subversion repository.\n" if $debug;
- system "svn info | grep '^Revision' | sed -e 's/Revision: *//'";
+ # Perform equivalent of:
+ # system "svn info | grep '^Revision' | sed -e 's/Revision: *//'";
+
+ print run_cmd ("svn info", "Revision:"), "\n";
}
else
{
warn "This is a local SVK copy of a Subversion repository.\n" if $debug;
+ # Perform equivalent of:
+ # $depot=`svk info \\
+ # | grep '^Copied From:' \\
+ # | head -n 1 \\
+ # | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
# The first 'Copied From:' line presumably is the parent in the
# SVK depot of this local copy.
- $DEPOT=`svk info \\
- | grep '^Copied From:' \\
- | head -n 1 \\
- | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
- chomp ($DEPOT);
+
+ $depot = run_cmd ("svk info", "Copied From:", ",.*");
+ warn "Repo depot is: $depot\n" if $debug;
+
# Try info for parent if there is no "Copied From: in current directory
- if ($DEPOT eq "")
+ if ($depot eq "")
{
- $DEPOT=`svk info .. \\
- | grep '^Copied From:' \\
- | head -n 1 \\
- | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
- chomp ($DEPOT);
+ # Perform equivalent of:
+ # $depot=`svk info .. \\
+ # | grep '^Copied From:' \\
+ # | head -n 1 \\
+ # | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
+
+ $depot = run_cmd ("svk info ..", "Copied From:", ",.*");
+ warn "Repo depot of '..' is: $depot\n" if $debug;
}
+
# The info for the depot includes a 'Mirrored From:' line that
# indicates parent Subversion repository and the revision last
# mirrored.
- # (If DEPOT is empty, then we are unable to tell the revision
+ # (If depot is empty, then we are unable to tell the revision
# and there is no output.)
- if ($DEPOT ne "")
+ if ($depot ne "")
{
- system "svk info /$DEPOT | grep '^Mirrored From:' | sed -e 's/.*, Rev\. *//'";
+ # Perform equivalent of:
+ # system "svk info /$depot | grep '^Mirrored From:' | sed -e 's/.*, Rev\. *//'";
+
+ $depot = run_cmd ("svk info /$depot", "Mirrored From:", ".*, Rev\\. *");
+ print "$depot\n" if $depot ne "";
}
}
}
sub get_remote_revision
{
-my $DEPOT;
-my $URL;
+my $depot;
+my $url;
if (-d ".svn")
{
warn "This is a Subversion repository.\n" if $debug;
- my $URL=`svn info | grep '^URL: ' | sed -e 's/^URL: *//'`;
- chomp ($URL);
- warn "Repo URL (from svn info): $URL\n" if $debug;
- system "svn info $URL | grep '^Revision' | sed -e 's/Revision: *//'";
+ # Perform equivalent of:
+ # $url=`svn info | grep '^URL: ' | sed -e 's/^URL: *//'`;
+
+ $url = run_cmd ("svn info", "URL:");
+ warn "Repo URL (from svn info): $url\n" if $debug;
+
+ # Perform equivalent of:
+ # system "svn info $url | grep '^Revision' | sed -e 's/Revision: *//'";
+
+ print run_cmd ("svn info $url", "Revision:"), "\n";
}
else
{
- #echo "This is a local SVK copy of a Subversion repository."
+ warn "This is a local SVK copy of a Subversion repository.\n" if $debug;
+ # Perform equivalent of:
+ # $depot=`svk info \\
+ # | grep '^Copied From:' \\
+ # | head -n 1 \\
+ # | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
# The first 'Copied From:' line presumably is the parent in the
# SVK depot of this local copy.
- $DEPOT=`svk info \\
- | grep '^Copied From:' \\
- | head -n 1 \\
- | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
- chomp ($DEPOT);
+
+ $depot = run_cmd ("svk info", "Copied From:", ",.*");
+ warn "Repo depot is: $depot\n" if $debug;
+
# Try info for parent if there is no "Copied From: in current directory
- if ($DEPOT eq "")
+ if ($depot eq "")
{
- $DEPOT=`svk info .. \\
- | grep '^Copied From:' \\
- | head -n 1 \\
- | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
- chomp ($DEPOT);
+ # Perform equivalent of:
+ # $depot=`svk info .. \\
+ # | grep '^Copied From:' \\
+ # | head -n 1 \\
+ # | sed -e 's/^Copied From: *//' -e 's/,.*//'`;
+
+ $depot = run_cmd ("svk info ..", "Copied From:", ",.*");
+ warn "Repo depot of '..' is: $depot\n" if $debug;
}
# The info for the depot includes a 'Mirrored From:' line that
# indicates parent Subversion repository and the revision last
# mirrored.
- # (If DEPOT is empty, then we are unable to tell the revision
+ # (If depot is empty, then we are unable to tell the revision
# and there is no output.)
- if ($DEPOT ne "")
+ if ($depot ne "")
{
- $URL=`svk info /$DEPOT | grep '^Mirrored From:' \\
- | sed -e 's/^Mirrored From: *//' \\
- | sed -e 's/,.*//'`;
- chomp ($URL);
- warn "Repo URL (from svk info): $URL\n" if $debug;
- system "svn info $URL | grep '^Revision' | sed -e 's/Revision: *//'";
+ # Perform equivalent of:
+ # $url=`svk info /$depot | grep '^Mirrored From:' \\
+ # | sed -e 's/^Mirrored From: *//' \\
+ # | sed -e 's/,.*//'`;
+
+ $url = run_cmd ("svk info /$depot", "Mirrored From:", ",.*");
+ warn "Depot $depot URL (from svk info): $url\n" if $debug;
+
+ # Perform equivalent of:
+ # system "svn info $url | grep '^Revision' | sed -e 's/Revision: *//'";
+
+ print run_cmd ("svn info $url", "Revision:"), "\n";
}
}
}
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r3439 - trunk/tools | paul | 23 Sep |