ChangeLogの書式について再度確認します。
2007-02-27のログに着目します。
takk@deb9:~/src/binutils-2.28/binutils$ grep '2007.02.27' -A13 ChangeLog-2007 | cat -n
1 2007-02-27 Alan Modra <amodra@bigpond.net.au>
2
3 * bin2c.c: New file.
4 * Makefile.am (EXTRA_PROGRAMS): Add bin2c.
5 (CFILES): Add bin2c.c.
6 (bin2c_SOURCES): Define.
7 (bin2c.o): Dependencies from "make dep-am".
8 * configure.in (BUILD_MISC): Add bin2c.
9 * version.c: Update year.
10 * po/POTFILES.in: Regenerate.
11 * Makefile.in: Regenerate.
12 * configure: Regenerate.
13
takk@deb9:~/src/binutils-2.28/binutils$
このログについて本家grep-changelogでbin2cを指定して抽出すると、同じタイトルで3つのログに分離されて表示されています。表示されるログは、上のテキストの3行目、4~7行目、8行目です。
takk@deb9:~/src/binutils-2.28/binutils$ grep-changelog --text bin2c ChangeLog-2007 2007-02-27 Alan Modra <amodra@bigpond.net.au> * bin2c.c: New file. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * Makefile.am (EXTRA_PROGRAMS): Add bin2c. (CFILES): Add bin2c.c. (bin2c_SOURCES): Define. (bin2c.o): Dependencies from "make dep-am". 2007-02-27 Alan Modra <amodra@bigpond.net.au> * configure.in (BUILD_MISC): Add bin2c. takk@deb9:~/src/binutils-2.28/binutils$
grep-changelognついて勘違いしてました。*(アスタリスク)から始まるログの単位で、タイトルとログの関連付けをしているだけのようです。正規化すると言えばよいでしょうか。
試しに、–textオプションを使用せずに実行してみます。
takk@deb9:~/src/binutils-2.28/binutils$ grep-changelog ChangeLog-2007 省略 2007-02-27 Alan Modra <amodra@bigpond.net.au> * bin2c.c: New file. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * Makefile.am (EXTRA_PROGRAMS): Add bin2c. (CFILES): Add bin2c.c. (bin2c_SOURCES): Define. (bin2c.o): Dependencies from "make dep-am". 2007-02-27 Alan Modra <amodra@bigpond.net.au> * configure.in (BUILD_MISC): Add bin2c. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * version.c: Update year. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * po/POTFILES.in: Regenerate. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * Makefile.in: Regenerate. 2007-02-27 Alan Modra <amodra@bigpond.net.au> * configure: Regenerate. 省略
やはりそうです。*(アスタリスク)から始まるログの単位で分離してるんですね。
では、本家と同じような抽出ができるように自作版を修正します。
全ソースです。変更箇所は、16~18、21~23行目です。
takk@deb9:~/src/binutils-2.28/binutils$ cat -n t.pl
1 $pattern = $ARGV[0];
2
3 %log=();
4 opendir(DIR,".");
5 @files = grep { /ChangeLog.*/ } readdir(DIR);
6 closedir(DIR);
7
8 $num = 1;
9 foreach(@files){
10 open(INFILE,"<$_");
11 $id = "";
12 while(<INFILE>){
13 chomp();
14 s/^ /\t/;
15 if(/^\d\d\d\d-\d\d-\d\d/){
16 $title = "$_";
17 $num=0;
18 $id = $title .':::'. $num++;
19 next;
20 }
21 if(/^ \*/){
22 $id = $title .':::'. $num++;
23 }
24 if(/^ |^$/ && $id ne ""){
25 $log{$id} .= "$_";
26 $found{$id} ++ if(/$pattern/);
27 next;
28 }
29 last;
30 }
31
32 close(INFILE);
33 }
34
35
36
37 foreach(sort keys %log){
38 $id = $_;
39 @tmp = split /\t/,$log{$_};
40
41 if($found{$id} > 0){
42 print "$id\n";
43 foreach(@tmp){
44 print" $_\n";
45 }
46 print"\n";
47 }
48 }
49
50
takk@deb9:~/src/binutils-2.28/binutils$
これで本家grep-changelogに近い出力になったかと思います。
実行してみます。
takk@deb9:~/src/binutils-2.28/binutils$ perl t.pl bin2c 省略 2007-02-27 Alan Modra <amodra@bigpond.net.au>:::1 * bin2c.c: New file. 2007-02-27 Alan Modra <amodra@bigpond.net.au>:::2 * Makefile.am (EXTRA_PROGRAMS): Add bin2c. (CFILES): Add bin2c.c. (bin2c_SOURCES): Define. (bin2c.o): Dependencies from "make dep-am". 2007-02-27 Alan Modra <amodra@bigpond.net.au>:::3 * configure.in (BUILD_MISC): Add bin2c. 省略
各タイトルに:::数字、ってのがついてますが、削除するのは、s/:::.*$//するだけですので、何てことはないですね。


コメント