source: valtobtest/subversion-1.6.2/contrib/client-side/search-svnlog.pl @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

  • Property svn:executable set to *
File size: 3.2 KB
Line 
1#!/usr/bin/perl -w
2
3# ====================================================================
4# Show log messages matching a certain pattern.  Usage:
5#
6#    search-svnlog.pl [-v] [-f LOGFILE] REGEXP
7#
8# See &usage() for details.
9#
10# ====================================================================
11# Copyright (c) 2000-2004 CollabNet.  All rights reserved.
12#
13# This software is licensed as described in the file COPYING, which
14# you should have received as part of this distribution.  The terms
15# are also available at http://subversion.tigris.org/license-1.html.
16# If newer versions of this license are posted there, you may use a
17# newer version instead, at your option.
18#
19# This software consists of voluntary contributions made by many
20# individuals.  For exact contribution history, see the revision
21# history and logs, available at http://subversion.tigris.org/.
22# ====================================================================
23
24use strict;
25use Getopt::Long;
26
27my $log_file;
28my $invert = 0;
29my $caseless = 0;
30
31GetOptions('f|file=s' => \$log_file,
32           'v|invert' => \$invert,
33           'i|caseinsensitive' => \$caseless) or &usage;
34
35&usage("$0: too few arguments") unless @ARGV;
36&usage("$0: too many arguments") if @ARGV > 1;
37
38my $filter = shift;
39$filter = '(?i)' . $filter if $caseless;
40
41my $log_cmd = "svn log";
42
43my $log_separator = '-' x 72 . "\n";
44
45my $open_string = defined $log_file ? $log_file : "$log_cmd |";
46open(LOGDATA, $open_string) or
47  die "$0: cannot open `$open_string' for reading: $!\n";
48
49my $this_entry_accum = "";
50my $this_rev = -1;
51my $this_lines = 0;
52my $seen_blank_line;  # A blank line separates headers from body.
53
54while (<LOGDATA>)
55{
56  if (/^r([0-9]+) \| [^\|]* \| [^\|]* \| ([0-9]+) (line|lines)$/)
57  {
58    $this_rev = $1;
59    $this_lines = $2 + 1;  # Compensate for blank line preceding body.
60
61    $this_entry_accum .= $_;
62  }
63  elsif ($this_lines == 0)  # Reached end of msg.  Looking at log separator?
64  {
65    if (! ($_ eq $log_separator))
66    {
67      die "$0: wrong number of lines for log message!\n${this_entry_accum}\n";
68    }
69
70    if ($this_entry_accum =~ /$filter/og ^ $invert)
71    {
72      print "${this_entry_accum}${log_separator}";
73    }
74
75    # Reset accumulators.
76    $seen_blank_line = 0;
77    $this_entry_accum = "";
78    $this_rev = -1;
79  }
80  elsif ($this_lines < 0)
81  {
82    die "$0: line weirdness parsing log.\n";
83  }
84  else   # Just continue accumulating.
85  {
86    $this_entry_accum .= $_;
87
88    if ($seen_blank_line)
89    {
90      $this_lines--;
91    }
92    elsif (/^$/)
93    {
94      $seen_blank_line = 1;
95      $this_lines--;
96    }
97  }
98}
99
100close(LOGDATA) or
101  die "$0: closing `$open_string' failed: $!\n";
102
103exit 0;
104
105sub usage {
106  warn "@_\n" if @_;
107  die "usage: $0: [-v] [-i] [-f LOGFILE] REGEXP\n",
108      "\n",
109      "Print only log messages matching REGEXP, either by running 'svn log'\n",
110      "in the current working directory, or if '-f LOGFILE' is passed, then\n",
111      "read the log data from LOGFILE (which should be in the same format\n",
112      "as the output of 'svn log').\n",
113      "\n",
114      "If '-v' is given, the matching is inverted (like 'grep -v').\n",
115      "\n",
116      "If '-i' is given, the matching is case-insensitive (like 'grep -i').\n";
117}
Note: See TracBrowser for help on using the repository browser.