Date:2013-09-27 14:53:59 (6 months 27 days ago)
Author:Werner Almesberger
Commit:9a093fecd48a47d3727e026b540b574f43eb443d
Message:bin/authors: list files in git repo by author, with wildcards

Files: bin/authors (1 diff)

Change Details

bin/authors
1#!/usr/bin/perl
2#
3# authors - List files in get repo by author, using wildcards
4#
5# Copyright 2013 by Werner Almesberger
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12
13
14$WIDTH = 79;
15
16open(LOG, "git log --format='%an <%ae>' --name-only --no-merges |") ||
17   die "popen log";
18while (<LOG>) {
19    chop;
20    if (/^$/) {
21        $a = $last;
22        undef $last;
23        next;
24    }
25    if (defined $last) {
26        push @{ $f{$last} }, $a;
27        $a{$a} = 1;
28    }
29    $last = $_;
30}
31if (defined $last) {
32    push @{ $f{$last} }, $a;
33    $a{$a} = 1;
34}
35close LOG;
36
37
38sub add
39{
40    local ($a, $f) = @_;
41    local $d, $n, $t;
42    local $best, $best_k, $k;
43
44    if ($f =~ m|/([^/]+)$|) {
45        $d = "$`/";
46        $n = $1;
47    } else {
48        $d = "";
49        $n = $f;
50    }
51    undef $best;
52    undef $best_k;
53    LONGER: for ($i = 0; $i <= length $n; $i++) {
54        $t = $d.substr($n, 0, $i);
55        $k = 0;
56        FIT: for (keys %f) {
57            next unless substr($_, 0, length $t) eq $t;
58            $k++;
59            for (@{ $f{$_} }) {
60                next FIT if $_ eq $a;
61            }
62            next LONGER;
63        }
64        last if $best_k > $k;
65        $best = $t;
66        $best_k = $k;
67    }
68    if ($best eq $f) {
69        $m{$f} = 1;
70    } else {
71        $m{"$best*"} = 1;
72    }
73}
74
75
76for $a (sort keys %a) {
77    undef %m;
78    for $f (keys %f) {
79        for (@{ $f{$f} }) {
80            next if $_ ne $a;
81            &add($a, $f);
82            last;
83        }
84    }
85    next unless %m;
86    print $a, "\n";
87    undef $p;
88    for (sort keys %m) {
89        if (!defined $p) {
90            $p = $_;
91            next;
92        }
93        if (length("$p $_") > $WIDTH) {
94            print "$p\n";
95            $p = $_;
96        } else {
97            $p .= " $_";
98        }
99    }
100    print $p, "\n\n";
101}

Archive Download the corresponding diff file

Branches:
master



interactive