Added option to get the stats from numstat instead of diff

The option --numstat of git log gives the statistics of
lines added and removed file.  Hence, it is not necessary
to parser a raw diff.

Another benefit, it is a less verbose log to be processed,
which helps to process long logs.  This also prepares the
code for counting the changes per file type.

Signed-off-by: Germán Póo-Caamaño <gpoo@gnome.org>
This commit is contained in:
Germán Póo-Caamaño
2011-06-22 17:25:17 -07:00
parent 4a729f1d72
commit 935be113b3
3 changed files with 50 additions and 16 deletions

10
README
View File

@@ -20,6 +20,10 @@ Run it like this:
git log -p -M [details] | gitdm [options] git log -p -M [details] | gitdm [options]
Alternatively, you can run with:
git log --numstat -M [details] | gitdm -n [options]
The [details] tell git which changesets are of interest; the [options] can The [details] tell git which changesets are of interest; the [options] can
be: be:
@@ -44,6 +48,8 @@ be:
-l num Only list the top <num> entries in each report. -l num Only list the top <num> entries in each report.
-n Use --numstat instead of generated patches to get the statistics.
-o file Write text output to the given file (default is stdout). -o file Write text output to the given file (default is stdout).
-r pat Only generate statistics for changes to files whose -r pat Only generate statistics for changes to files whose
@@ -68,6 +74,10 @@ looks like:
git log -p -M v2.6.19..v2.6.20 | \ git log -p -M v2.6.19..v2.6.20 | \
gitdm -u -s -a -o results -h results.html gitdm -u -s -a -o results -h results.html
or:
git log --numstat -M v2.6.19..v2.6.20 | \
gitdm -u -s -a -n -o results -h results.html
CONFIGURATION FILE CONFIGURATION FILE

52
gitdm
View File

@@ -37,6 +37,7 @@ DumpDB = 0
CFName = 'gitdm.config' CFName = 'gitdm.config'
DirName = '' DirName = ''
Aggregate = 'month' Aggregate = 'month'
Numstat = 0
# #
# Options: # Options:
@@ -48,6 +49,7 @@ Aggregate = 'month'
# -D Output date statistics # -D Output date statistics
# -h hfile HTML output to hfile # -h hfile HTML output to hfile
# -l count Maximum length for output lists # -l count Maximum length for output lists
# -n Use numstats instead of generated patch from git log
# -o file File for text output # -o file File for text output
# -r pattern Restrict to files matching pattern # -r pattern Restrict to files matching pattern
# -s Ignore author SOB lines # -s Ignore author SOB lines
@@ -59,9 +61,9 @@ Aggregate = 'month'
def ParseOpts (): def ParseOpts ():
global MapUnknown, DevReports global MapUnknown, DevReports
global DateStats, AuthorSOBs, FileFilter, AkpmOverLt, DumpDB global DateStats, AuthorSOBs, FileFilter, AkpmOverLt, DumpDB
global CFName, CSVFile, DirName, Aggregate global CFName, CSVFile, DirName, Aggregate, Numstat
opts, rest = getopt.getopt (sys.argv[1:], 'ab:dc:Dh:l:o:r:suwx:z') opts, rest = getopt.getopt (sys.argv[1:], 'ab:dc:Dh:l:no:r:suwx:z')
for opt in opts: for opt in opts:
if opt[0] == '-a': if opt[0] == '-a':
AkpmOverLt = 1 AkpmOverLt = 1
@@ -77,6 +79,8 @@ def ParseOpts ():
reports.SetHTMLOutput (open (opt[1], 'w')) reports.SetHTMLOutput (open (opt[1], 'w'))
elif opt[0] == '-l': elif opt[0] == '-l':
reports.SetMaxList (int (opt[1])) reports.SetMaxList (int (opt[1]))
elif opt[0] == '-n':
Numstat = 1
elif opt[0] == '-o': elif opt[0] == '-o':
reports.SetOutput (open (opt[1], 'w')) reports.SetOutput (open (opt[1], 'w'))
elif opt[0] == '-r': elif opt[0] == '-r':
@@ -248,20 +252,36 @@ def grabpatch():
sys.stderr.write ('Funky date: %s\n' % p.date) sys.stderr.write ('Funky date: %s\n' % p.date)
p.date = Today p.date = Today
continue continue
# if not Numstat:
# If we have a file filter, check for file lines. #
# # If we have a file filter, check for file lines.
if FileFilter: #
ignore = ApplyFileFilter (Line, ignore) if FileFilter:
# ignore = ApplyFileFilter (Line, ignore)
# OK, maybe it's part of the diff itself. #
# # OK, maybe it's part of the diff itself.
if not ignore: #
if Padd.match (Line): if not ignore:
p.added += 1 if Padd.match (Line):
continue p.added += 1
if Prem.match (Line): continue
p.removed += 1 if Prem.match (Line):
p.removed += 1
else:
# Get the statistics (lines added/removes) using numstats
# and without requiring a diff (--numstat instead -p)
m = Pnumstat.match (Line)
if m:
# If we have a file filter, check for file lines.
if FileFilter and not FileFilter.search (m.group(3)):
continue
try:
p.added += int(m.group(1))
p.removed += int(m.group(2))
except ValueError:
# A binary file (image, etc.) is marked with '-'
pass
if '@' in p.author.name: if '@' in p.author.name:
GripeAboutAuthorName (p.author.name) GripeAboutAuthorName (p.author.name)

View File

@@ -37,3 +37,7 @@ PExtMerge = re.compile(r'^ +Merge( branch .* of)? ([^ ]+:[^ ]+)\n$')
PIntMerge = re.compile(r'^ +(Merge|Pull) .* into .*$') PIntMerge = re.compile(r'^ +(Merge|Pull) .* into .*$')
# PIntMerge2 = re.compile(r"^ +Merge branch(es)? '.*$") # PIntMerge2 = re.compile(r"^ +Merge branch(es)? '.*$")
PIntMerge2 = re.compile(r"^ +Merge .*$") PIntMerge2 = re.compile(r"^ +Merge .*$")
#
# Another way to get the statistics (per file). It implies --numstat
Pnumstat = re.compile('^(\d+|-)\s+(\d+|-)\s+(.*)$')
Prename = re.compile('(.*)\{(.*) => (.*)\}(.*)')