Warning, /sdk/kde-dev-scripts/svnlastchange is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env perl
0002 #
0003 # This file is Copyright (C) 2005 Thiago Macieira <thiago@kde.org>
0004 #
0005 # This program is free software; you can redistribute it and/or modify
0006 # it under the terms of the GNU General Public License as published by
0007 # the Free Software Foundation; version 2 of the License as published
0008 # by the Free Software Foundation.
0009 #
0010 # This program is distributed in the hope that it will be useful,
0011 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0013 # GNU General Public License for more details.
0014 #
0015 # You should have received a copy of the GNU General Public License
0016 # along with this program; if not, write to the Free Software Foundation, Inc.,
0017 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018
0019 # =====================================================================
0020 # This is a replacement for the old svnlastchange script, with a bit
0021 # more of functionality.
0022 #
0023 # The old one was:
0024 # svn log -r COMMITTED "$*"
0025 # svn diff -r PREV:COMMITTED "$*" || \
0026 # echo >&2 "Error retrieving diff: the file was probably added in the last revision"
0027 #
0028 # =====================================================================
0029
0030 # Turn on warnings the best way depending on the Perl version.
0031 BEGIN {
0032 if ( $] >= 5.006_000)
0033 { require warnings; import warnings; }
0034 else
0035 { $^W = 1; }
0036 }
0037 use strict;
0038
0039 my $want_whitespace = 0;
0040
0041 sub showdiff($@) #depends on global var $want_whitespace
0042 {
0043 my ($revisions) = shift(@_);
0044 my (@files) = @_;
0045 if ($want_whitespace) {
0046 system('svn', 'diff',
0047 # This is for people who set a diff-cmd to exclude whitespace; when forwardporting we need the indentation to be preserved
0048 '--diff-cmd=diff',
0049 '-r', $revisions, @files);
0050 } else {
0051 # By default, use plain svn diff; whitespace depends on user configuration
0052 system('svn', 'diff', '-r', $revisions, @files);
0053 }
0054 }
0055
0056 #
0057 # Read the parameters
0058 #
0059 my @files;
0060 my $rev;
0061 my $special = 0;
0062 my $onlyrev = 0;
0063 my $onlylog = 0;
0064 while (@ARGV)
0065 {
0066 my $arg = shift @ARGV;
0067 if ($arg eq '-h')
0068 {
0069 &usage;
0070 exit 0;
0071 }
0072 elsif ($arg =~ /^-r(.*)$/)
0073 {
0074 $rev = $1;
0075 if (length($1) == 0)
0076 {
0077 $rev = shift @ARGV;
0078 }
0079 $special = 1 if ($rev =~ /^-/);
0080 }
0081 elsif ($arg eq '-R')
0082 {
0083 $onlyrev = 1;
0084 $special = 1;
0085 $rev = -1 unless $rev;
0086 }
0087 elsif ($arg eq '-l')
0088 {
0089 $onlylog = 1;
0090 }
0091 elsif ($arg eq '-ws')
0092 {
0093 $want_whitespace = 1;
0094 }
0095 else
0096 {
0097 push(@files, $arg);
0098 }
0099 }
0100 @files = ('.') unless @files;
0101
0102 if (!$special)
0103 {
0104 my $prev;
0105 if ($rev)
0106 {
0107 $prev = $rev - 1;
0108 }
0109 else
0110 {
0111 $rev = 'COMMITTED';
0112 $prev = 'PREV';
0113 }
0114
0115 system('svn', 'log', '-r', $rev, @files);
0116 &showdiff("$prev:$rev", @files) unless $onlylog;
0117 exit $?;
0118 }
0119
0120 #
0121 # Special operation
0122 # Retrieve the full log in order to find the right version
0123 #
0124 foreach my $file (@files)
0125 {
0126 my $pid = open(LOG, '-|');
0127 die "svnlastchange: cannot fork: $!\n" unless (defined $pid);
0128 unless ($pid)
0129 {
0130 open(STDERR, ">&STDOUT")
0131 or die "svnlastchange: cannot dup STDOUT: $!\n";
0132 exec('svn', 'log', $file)
0133 or die "svnlastchange: cannot exec svn: $!\n";
0134 }
0135
0136 my $is_header = 0;
0137 while (<LOG>)
0138 {
0139 s/[\r\n]+$//;
0140
0141 if ($is_header && /^r(\d+) \| /)
0142 {
0143 $rev = $rev + 1;
0144 if ($rev == 0)
0145 {
0146 if ($onlyrev)
0147 {
0148 print "$1\n";
0149 }
0150 else
0151 {
0152 system('svn', 'log', '-r', $1, $file);
0153 &showdiff( ($1 - 1) . ":$1", $file) unless $onlylog;
0154 }
0155 last;
0156 }
0157 }
0158
0159 if ($_ eq '------------------------------------------------------------------------')
0160 {
0161 $is_header = 1;
0162 }
0163 else
0164 {
0165 $is_header = 0;
0166 }
0167 }
0168 close(LOG);
0169 exit $? if $?;
0170 }
0171
0172 sub usage
0173 {
0174 print "svnlastchange [-hlR] [-r rev] [filename...]\n";
0175 print "\n";
0176 print "Where:\n";
0177 print " -h shows this help screen\n";
0178 print " -l shows the commit log only\n";
0179 print " -R prints the revision number only (to be used with -r)\n";
0180 print " -r rev shows the commit log for revision 'rev'\n";
0181 print " if rev is negative, the 'rev'nth revision before the current\n";
0182 print " one is shown\n";
0183 print "\n";
0184 print "Examples:\n";
0185 print " svnlastchange . shows the last change to the current directory\n";
0186 print " svnlastchange -r -2 shows the change before the last\n";
0187 print " svnlastchange -R -r -1 shows the last change's revision\n";
0188
0189 exit 0;
0190 }
0191
0192