From 73f1df4e472eb8f7d5a04603460c98fdc9782b44 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Tue, 23 Aug 2011 10:23:23 -0400 Subject: [PATCH] First draft of line blame counter script. --- blame-counter.plx | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100755 blame-counter.plx diff --git a/blame-counter.plx b/blame-counter.plx new file mode 100755 index 0000000..2c0f637 --- /dev/null +++ b/blame-counter.plx @@ -0,0 +1,95 @@ +#!/usr/bin/perl -w +# blame-counter.plx -*- Perl -*- +# +# Copyright (C) 2011 Bradley M. Kuhn +# +# This software's license gives you freedom; you can copy, convey, +# propogate, redistribute and/or modify this program under the terms of +# the GNU General Public License (GPL) as published by the Free +# Software Foundation (FSF), either version 3 of the License, or (at your +# option) any later version of the GPL published by the FSF. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program in a file in the toplevel directory called +# "GPLv3". If not, see . +# + +use strict; +use warnings; + +###################################################################### + + +if (@ARGV != 3) { + print "usage: $0 ", + " \n"; + exit 1; +} +# Note: $DATA_FILE is in the format as output from: +# for i in `find -type f -print | egrep -v '^./.git'`; do +# echo "FILE: $i" >> ../DATA_FILE; git blame -M -M -M -C -C -C -w -f -n -l $i >> ../DATA_FILE +# done + +my($DATA_FILE, $COMMITS_IN_RANGE_FILE, $CONFIRMED_COMMITS_FILE) = @ARGV; + + +sub ReadCommitsFile ($) { + my($file) = @_; + + open(COMMITS_FILE, "<", $file) or die "unable to pen $file for reading: $!"; + + my %commits; + while (my $line = ) { + chomp $line; + die "strange commit ID, $line, found in $file" unless $line =~ /^[a-f0-9]+$/; + $commits{$line} = $file; + } + close COMMITS_FILE; + return \%commits; +} + +my $commitsInRange = ReadCommitsFile($COMMITS_IN_RANGE_FILE); + +my $confirmedCommits = ReadCommitsFile($CONFIRMED_COMMITS_FILE); + + + +open(DATA_FILE, "<", $DATA_FILE) or die "unable to open $DATA_FILE for reading: $!"; + +my %data; +my $currentFile; + +while (my $dataLine = ) { + if ($dataLine =~ /^\s*FILE\s*:\s*(.*?)\s*$/) { + $currentFile = $1; + $data{$currentFile} = { commitsInRange => 0, confirmedCommits => 0 }; + } else { + die "invalid line: $dataLine in blame output" unless ($dataLine =~ + /^\s*(\S+)\s+\S+\s+\d+\s+\((.+)\s+(\d{4,4}\-\d{2,2}\-\d{2,2}\s+\d{2,2}:\d{2,2}:\d{2,2})\s+([\+\-\d]+)\s+(\d+)\s*\)\s+(.*)$/); + my($commitID, $name, $date, $tz, $curLineNumber, $actualCurrentLine) = ($1, $2, $3, $4, $5, $6); + + if (defined $commitsInRange->{$commitID}) { + $data{$currentFile}{commitsInRange}++; + if (defined $confirmedCommits->{$commitID}) { + $data{$currentFile}{confirmedCommits}++; + } + + } + } +} +close DATA_FILE; +foreach my $file (sort keys %data) { + next if $data{$file}{commitsInRange} == 0 or $data{$file}{confirmedCommits} == 0; + + print sprintf("%s has %d lines from commits in range and %d of those lines are on confirmed list\n", + $file, $data{$file}{commitsInRange}, $data{$file}{confirmedCommits}); +} +# +# Local variables: +# compile-command: "perl -c blame-counter.plx" +# End: