8
8
from xml .sax .saxutils import escape as h
9
9
from sys import stderr
10
10
import re
11
+ import sre_constants
11
12
12
13
# Some global variables
13
14
SVN_SEP = "------------------------------------------------------------------------"
@@ -70,6 +71,15 @@ def main(argv):
70
71
else :
71
72
print >> stderr , "No repository format given, for more info see:\n convert_logs.py help"
72
73
sys .exit (1 )
74
+
75
+ # check for valid cmd line arguments before doing anything
76
+ if opts .ignore_author is not None :
77
+ try :
78
+ re .compile (opts .ignore_author )
79
+ except sre_constants .error :
80
+ print >> stderr , "Unable to compile author reg ex: %s" % \
81
+ opts .ignore_author
82
+ sys .exit (1 )
73
83
74
84
if not os .path .exists (log_file ):
75
85
#hacky, but OptionParse doesn't support options that only sometimes
@@ -82,8 +92,12 @@ def main(argv):
82
92
else :
83
93
log_file = open (log_file , 'r' )
84
94
85
- events = parser (log_file , opts )
86
-
95
+ events = parser (log_file , opts )
96
+
97
+ # Remove all authors we wanted to ignore here
98
+ if opts .ignore_author is not None :
99
+ events = remove_ignored_author (opts .ignore_author , events )
100
+
87
101
#its really best if we don't have to sort, but by default most are
88
102
# in the reverse order that we want, so we sort by default
89
103
if not opts .nosort :
@@ -159,6 +173,10 @@ def parse_args(argv):
159
173
p .add_option ("--nosort" , dest = "nosort" , default = False , action = "store_true" ,
160
174
help = "use if the input log is already in chronological order for speed" )
161
175
176
+ p .add_option ("--ignore-author" , dest = "ignore_author" , default = None ,
177
+ action = "store" ,
178
+ help = "Ignore authors that match this regular expression." )
179
+
162
180
163
181
(options , args ) = p .parse_args (argv )
164
182
@@ -397,6 +415,14 @@ def parse_perforce_path(file_handle, opts):
397
415
if file_key_re .match (key_name ):
398
416
yield Event (file_name , int (changelist ['time' ] + '000' ), changelist ['user' ])
399
417
418
+
419
+ def remove_ignored_author (ignore , events ):
420
+ """ Remove the events that match the given ignore reg ex. """
421
+ events = filter (lambda evt : re .match (ignore , evt .author ) is None ,
422
+ events )
423
+ return events
424
+
425
+
400
426
def run_marshal (command ):
401
427
import marshal
402
428
0 commit comments