fixup.cc5711424b7ae36276a40c06ede5d95f87ca20f0
[git/dscho.git] / my-xy-status.perl
blobd4138cbbacea63d145e938dc00ce714f1852b16f
1 #!/usr/bin/perl
3 # Copyright (C) 2007 Johannes E. Schindelin
5 # A while ago some funny guy asked if you can set the mtime of all files
6 # to the timestamp of the commit which touched them last.
8 # This is, of course, possible, even if it is highly unlikely that the
9 # operation makes any sense. Since I think this was a typical XY problem
10 # (the guy asking for a solution, not stating the problem, which would
11 # most likely have another solution, a proper one at that) I call this
12 # script "xy-status".
14 # But the challenge was not lost on me, so here it goes.
16 %attributions = ();
17 @files = ();
19 open IN, "git ls-tree -r HEAD |";
20 while (<IN>) {
21 if (/^\S+\s+blob \S+\s+(\S+)$/) {
22 $files[$#files + 1] = $1;
23 $attributions{$1} = -1;
26 close IN;
28 $remaining = $#files + 1;
30 open IN, "git log -r --root --raw --no-abbrev --pretty=format:%h~%an~%ad~ |";
31 while (<IN>) {
32 if (/^([^:~]+)~(.*)~([^~]+)~$/) {
33 ($commit, $author, $date) = ($1, $2, $3);
34 } elsif (/^:\S+\s+1\S+\s+\S+\s+\S+\s+\S\s+(.*)$/) {
35 if ($attributions{$1} == -1) {
36 $attributions{$1} = "$author, $date ($commit)";
37 $remaining--;
38 if ($remaining <= 0) {
39 break;
44 close IN;
46 foreach $f (@files) {
47 print "$f $attributions{$f}\n";