まだ対応オプションは残っています。今回は、この2つのオプションを対応します。
--exclude=TEXT Exclude entries matching regular expression TEXT. --reverse Show entries in reverse (chronological) order
–excludeは、指定した文字列を除外するだけですので、以下の2行をそれぞれどこかへ追加するだけで実現できます。
$exclude='^$'; next if(/$exclude/);
次は、–reverseオプション。
指定すると、逆順にログが表示されます。
本家で使用すると、
takk@deb9:~/src/binutils-2.28/binutils$ grep-changelog --text bin2c ChangeLog* --reverse | sed -ne '/^2/p' | cut -d' ' -f1 2007-02-27 2007-02-27 2007-02-27 2007-02-28 2007-02-28 2007-07-05 2008-08-25 2009-08-22 2009-08-28 2010-01-26 2010-11-05 2010-11-05 takk@deb9:~/src/binutils-2.28/binutils$
昇順となります。
reverseをつけないと、降順。。。と言いたいところですが、ChangeLogファイル毎に降順です。なぜ、こうなっているのかよく分かりません。
takk@deb9:~/src/binutils-2.28/binutils$ grep-changelog --text bin2c ChangeLog* | sed -ne '/^2/p' | cut -d' ' -f1 2007-07-05 2007-02-28 2007-02-28 2007-02-27 2007-02-27 2007-02-27 2008-08-25 2009-08-28 2009-08-22 2010-11-05 2010-11-05 2010-01-26 takk@deb9:~/src/binutils-2.28/binutils$
自作grep-changelogの今回の修正版では、–reverseオプションをつけないと昇順で、つけると降順になるようにしました。
takk@deb9:~/src/binutils-2.28/binutils$ perl my-grep-changelog.pl --text bin2c | sed -ne '/^2/p' | cut -d' ' -f1 2007-02-27 2007-02-27 2007-02-27 2007-02-28 2007-02-28 2007-07-05 2008-08-25 2009-08-22 2009-08-28 2010-01-26 2010-11-05 2010-11-05 takk@deb9:~/src/binutils-2.28/binutils$ perl t.pl --text bin2c --reverse | sed -ne '/^2/p' | cut -d' ' -f1 2010-11-05 2010-11-05 2010-01-26 2009-08-28 2009-08-22 2008-08-25 2007-07-05 2007-02-28 2007-02-28 2007-02-27 2007-02-27 2007-02-27 takk@deb9:~/src/binutils-2.28/binutils$
では、全ソース。修正行は、5,8,16,57,70~73行目です。
takk@deb9:~/src/binutils-2.28/binutils$ cat -n my-grep-changelog.pl
1 $_ = "@ARGV";
2 s/--(\w+-?\w+) /--$1=/g;
3 $author='.+';
4 $text='.+';
5 $exclude='^$';
6 $from_date='00000000';
7 $to_date ='99999999';
8 $reverse=0;
9
10 foreach(split / /){
11 $author=$1 if(/--author=(\S+)/);
12 $text=$1 if(/--text=(\S+)/);
13 $exclude=$1 if(/--exclude=(\S+)/);
14 $from_date=$1.$2.$3 if(/--from-date=(\d\d\d\d)\-(\d\d)\-(\d\d)/);
15 $to_date=$1.$2.$3 if(/--to-date=(\d\d\d\d)\-(\d\d)\-(\d\d)/);
16 $reverse=1 if(/--reverse/);
17 }
18
19 if($from_date > $to_date){
20 exit 1;
21 }
22
23 %log=();
24 opendir(DIR,".");
25 @files = grep { /ChangeLog.*/ } readdir(DIR);
26 closedir(DIR);
27
28 $num = 1;
29 foreach(@files){
30 open(INFILE,"<$_");
31 $id = "";
32 while(<INFILE>){
33 chomp();
34 s/^ \t/\t/;
35 s/^ /\t/;
36
37 if(/^Mon|^Tue|^Wed|^Thu|^Fri|^Sat|^Sun/){
38 /^(.* [12]\d\d\d)/;
39 $d = $1;
40 open(CMD,"date +%F -d '$d' |");
41 @result = <CMD>;
42 close(CMD);
43 $newdate = "@result";
44 chop $newdate;
45 s/^$d/$newdate/;
46 }
47 if(/^\d\d\d\d\-\d\d\-\d\d/){
48 $title = "$_";
49 $num=0;
50 $id = $title .':::'. $num++;
51 next;
52 }
53 if(/^ \*/){
54 $id = $title .':::'. $num++;
55 }
56 if(/^ |^ \*|^$/ && $id ne ""){
57 next if(/$exclude/);
58 if(/$text/){
59 $log{$id} .= "$_";
60 $found{$id} ++;
61 }
62 next;
63 }
64 last;
65 }
66
67 close(INFILE);
68 }
69
70 @all = sort keys %log;
71 @all = reverse @all if($reverse==1);
72
73 foreach(@all){
74 $id = $_;
75 /^(....).(..).(..)/;
76 $dt = $1.$2.$3;
77 @tmp = split /\t/,$log{$_};
78
79 next if($dt < $from_date);
80 next if($dt > $to_date);
81
82 if($found{$id} > 0){
83 if($id =~ /$author/){
84 $title = (split /:::/,$id)[0];
85 print "$title\n";
86 foreach(@tmp){
87 print" $_\n";
88 }
89 print"\n";
90 }
91 }
92 }
takk@deb9:~/src/binutils-2.28/binutils$


コメント