3
# $HeadURL: http://svn.collab.net/repos/svn/branches/1.2.x/contrib/client-side/svn_all_diffs.pl $
4
# $LastChangedDate: 2004-09-22 12:20:49 -0400 (Wed, 22 Sep 2004) $
5
# $LastChangedBy: blair $
6
# $LastChangedRevision: 11065 $
10
use Getopt::Long 2.25;
12
# Process the command line options.
14
# Print the log message along with the modifications made in a
15
# particular revision.
16
my $opt_print_log_message;
18
GetOptions('log' => \$opt_print_log_message)
21
&usage("$0: too many arguments") if @ARGV > 1;
23
# If there is no file or directory specified on the command line, use
24
# the current working directory as a default path.
25
my $file_or_dir = @ARGV ? shift : '.';
27
unless (-e $file_or_dir)
29
die "$0: file or directory `$file_or_dir' does not exist.\n";
32
# Get the entire log for this file or directory. Parse the log into
33
# two separate lists. The first is a list of the revision numbers
34
# when this file or directory was modified. The second is a hash of
35
# log messages for each revision.
40
foreach my $log_line (read_from_process('svn', 'log', $file_or_dir))
42
# Ignore any of the lines containing only -'s.
43
next if $log_line =~ /^-+$/;
45
if (my ($r) = $log_line =~ /^r(\d+)/)
47
$current_revision = $r;
48
$log_messages{$current_revision} = "";
52
if (defined $current_revision)
54
$log_messages{$current_revision} .= "$log_line\n";
60
while (@revisions > 1)
62
my $new_rev = shift @revisions;
63
my $old_rev = $revisions[0];
65
&print_revision($new_rev);
67
my @diff = read_from_process('svn', 'diff',
68
"-r$old_rev:$new_rev", $file_or_dir);
70
if ($opt_print_log_message)
72
print $log_messages{$new_rev};
74
print join("\n", @diff, "\n");
77
# Print the log message for the last revision. There is no diff for
78
# this revision, because according to svn log, the file or directory
79
# did not exist previously.
81
my $last_revision = shift @revisions;
82
if ($opt_print_log_message)
84
&print_revision($last_revision);
85
print $log_messages{$last_revision};
94
die "usage: $0 [file_or_dir]\n";
101
print "\n\n\nRevision $revision\n";
104
# Start a child process safely without using /bin/sh.
105
sub safe_read_from_pipe
109
croak "$0: safe_read_from_pipe passed no arguments.\n";
111
print "Running @_\n";
112
my $pid = open(SAFE_READ, '-|');
113
unless (defined $pid)
115
die "$0: cannot fork: $!\n";
119
open(STDERR, ">&STDOUT")
120
or die "$0: cannot dup STDOUT: $!\n";
122
or die "$0: cannot exec `@_': $!\n";
132
my $exit = $result >> 8;
133
my $signal = $result & 127;
134
my $cd = $result & 128 ? "with core dump" : "";
137
warn "$0: pipe from `@_' failed $cd: exit=$exit signal=$signal\n";
141
return ($result, @output);
149
# Use safe_read_from_pipe to start a child process safely and exit the
150
# script if the child failed for whatever reason.
151
sub read_from_process
155
croak "$0: read_from_process passed no arguments.\n";
157
my ($status, @output) = &safe_read_from_pipe(@_);
160
die "$0: @_ failed with this output:\n", join("\n", @output), "\n";