Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
Source at commit 9a093fe created 10 years 6 months ago. By Werner Almesberger, bin/authors: list files in git repo by author, with wildcards | |
---|---|
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 | |
16 | open(LOG, "git log --format='%an <%ae>' --name-only --no-merges |") || |
17 | die "popen log"; |
18 | while (<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 | } |
31 | if (defined $last) { |
32 | push @{ $f{$last} }, $a; |
33 | $a{$a} = 1; |
34 | } |
35 | close LOG; |
36 | |
37 | |
38 | sub 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 | |
76 | for $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 | } |
102 |
Branches:
master