3 # Extract information about recent SVN commits
5 # tridge@samba.org, April 2001
6 # vance@samba.org, August 2004
16 ####################################
17 # push an entry onto the array
26 # we can assume that each entry is unique, due to the nature of svn
27 # so we don't need any of the magic required for cvs
28 if (($entry->{DATE} > time() - $days*24*60*60) &&
29 ($entry->{TREE} eq $tree)) {
31 # we put these on in reverse order so that it's in order of
33 unshift(@{$log}, $entry);
39 ####################################
40 # return an array of logfile entries given a svn log file.
41 # Only return entries newer than $days old
51 # don't know what time zone this machine is, but given the granularity
52 # of days, (intended to be about 60 days), a few hours either way makes
53 # very little difference
54 my $start_date = POSIX::strftime("%Y-%m-%d", gmtime(time() - $days*60*60*24));
56 open(FILE, "svn log --verbose --non-interactive $repo_url/$tree_dir -r HEAD:'{$start_date}' |");
57 #open(FILE, "< log.txt") or die "Could not open log: $!";
58 while (defined (my $line = <FILE>)) {
61 # separator line indicates new entry
62 if ($line =~ /^\-{5,}$/) {
63 # only add entry if one exists
65 $log = push_entry($entry, $log, $days, $tree);
73 # the first line after the separator (which sets entry to {})
75 # r15 | vance | 2004-07-31 22:24:55 -0700 (Sat, 31 Jul 2004) | 4 lines
76 if (! defined $entry->{DATE}) {
78 my ($rev, $author, $date, $lines) = split /\s+\|\s+/, $line;
79 $entry->{DATE} = str2time($date);
81 # kill the r in the revision
83 $entry->{REVISION} = $rev;
84 $entry->{AUTHOR} = $author;
85 $entry->{TREE} = $tree;
90 # read the list of changed/added/removed files
91 if ($line =~ /^Changed paths:/) {
96 if ($line =~ /^\s*$/) { last; }
98 elsif ($line =~ /\s+A (.*)/) {
100 $file =~ s#^/$tree_dir/##o;
101 if ($entry->{ADDED}) {
102 $entry->{ADDED} .= " $file";
104 $entry->{ADDED} = "$file";
108 elsif ($line =~ /\s+M (.*)/) {
110 $file =~ s#^/$tree_dir/##o;
111 if ($entry->{FILES}) {
112 $entry->{FILES} .= " $file";
114 $entry->{FILES} = "$file";
118 elsif ($line =~ /\s+R (.*)/ ||
119 $line =~ /\s+D (.*)/) {
121 $file =~ s#^/$tree_dir/##o;
122 if ($entry->{REMOVED}) {
123 $entry->{REMOVED} .= " $file";
125 $entry->{REMOVED} = "$file";
133 # add the line to the message
134 if (defined $entry->{MESSAGE}) {
135 $entry->{MESSAGE} .= $line;
138 $entry->{MESSAGE} = $line;
142 if ($entry->{DATE}) {
143 $log = push_entry($entry, $log, $days, $tree);
148 # cleanup the messages
149 for (my $line = $#{$log}; $line > 0; $line--) {
150 $entry = $log->[$line];
151 if ($entry->{MESSAGE}) {
152 while (chomp($entry->{MESSAGE})) { }
160 ######################################
162 if ($#ARGV < 4 || $ARGV[0] eq '--help' || $ARGV[0] eq '-h') {
164 Usage: svnlog.pl <REPOSITORY-URL> <TREE-DIR> <DAYS> <TREE> <DEST>
166 Extract all commits to REPOSITORY-URL/TREE-DIR in the last
167 DAYS days. Store the results in DEST, indexed under TREE,
168 in a format easily readable by the build farm web scripts.
173 my $repo_url = $ARGV[0];
174 my $tree_dir = $ARGV[1];
180 my $log = svn_parse($repo_url, $tree_dir, $days, $tree);
182 util::SaveStructure($dest, $log);