Root/bin/authors

Source at commit a27d1958fb3a238dcdc9fe15e0d0649448409129 created 5 years 7 months ago.
By Werner Almesberger, ircstat/ML: update for 12/2013
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 ls-files |") || die "popen ls-files";
17while (<LOG>) {
18    chop;
19    $e{$_} = 1;
20}
21close LOG;
22
23open(LOG, "git log --format='%an <%ae>' --name-only --no-merges |") ||
24   die "popen log";
25while (<LOG>) {
26    chop;
27    if (/^$/) {
28        $a = $last;
29        undef $last;
30        next;
31    }
32    if (defined $e{$last}) {
33        push @{ $f{$last} }, $a;
34        $a{$a} = 1;
35    }
36    $last = $_;
37}
38if (defined $e{$last}) {
39    push @{ $f{$last} }, $a;
40    $a{$a} = 1;
41}
42close LOG;
43
44
45sub add
46{
47    local ($a, $f) = @_;
48    local $d, $n, $t;
49    local $best, $best_k, $k;
50
51    if ($f =~ m|/([^/]+)$|) {
52        $d = "$`/";
53        $n = $1;
54    } else {
55        $d = "";
56        $n = $f;
57    }
58    undef $best;
59    undef $best_k;
60    LONGER: for ($i = 0; $i <= length $n; $i++) {
61        $t = $d.substr($n, 0, $i);
62        $k = 0;
63        FIT: for (keys %f) {
64            next unless substr($_, 0, length $t) eq $t;
65            $k++;
66            for (@{ $f{$_} }) {
67                next FIT if $_ eq $a;
68            }
69            next LONGER;
70        }
71        last if $best_k > $k;
72        $best = $t;
73        $best_k = $k;
74    }
75    if ($best eq $f) {
76        $m{$f} = 1;
77    } else {
78        $m{"$best*"} = 1;
79    }
80}
81
82
83for $a (sort keys %a) {
84    undef %m;
85    for $f (keys %f) {
86        for (@{ $f{$f} }) {
87            next if $_ ne $a;
88            &add($a, $f);
89            last;
90        }
91    }
92    next unless %m;
93    print $a, "\n";
94    undef $p;
95    for (sort keys %m) {
96        if (!defined $p) {
97            $p = $_;
98            next;
99        }
100        if (length("$p $_") > $WIDTH) {
101            print "$p\n";
102            $p = $_;
103        } else {
104            $p .= " $_";
105        }
106    }
107    print $p, "\n\n";
108}
109

Archive Download this file

Branches:
master



interactive