]> git.ipfire.org Git - thirdparty/dracut.git/blob - git2spec.pl
git2spec.pl: make rename diffs
[thirdparty/dracut.git] / git2spec.pl
1 #!/usr/bin/perl
2
3 sub last_tag {
4 open( GIT, 'git log --pretty=format:%H |');
5 LINE: while( <GIT> ) {
6 open( GIT2, "git tag --contains $_ |");
7 while( <GIT2> ) {
8 chomp;
9 last LINE if /..*/;
10 }
11 close GIT2;
12 }
13 $tag=$_;
14 close GIT2;
15 close GIT; # be done
16 return $tag;
17 };
18
19 sub create_patches {
20 my $tag=shift;
21 my $num=0;
22 open( GIT, 'git format-patch --no-renames -N --no-signature '.$tag.' |');
23 @lines=<GIT>;
24 close GIT; # be done
25 return @lines;
26 };
27 use POSIX qw(strftime);
28 my $datestr = strftime "%Y%m%d", gmtime;
29
30 my $tag=shift;
31 $tag=&last_tag if not defined $tag;
32 my @patches=&create_patches($tag);
33 my $num=$#patches + 2;
34 $tag=~s/[^0-9]+?([0-9]+)/$1/;
35 my $release="$num.git$datestr";
36 $release="1" if $num == 1;
37
38 while(<>) {
39 if (/^Version:/) {
40 print "Version: $tag\n";
41 }
42 elsif (/^Release:/) {
43 print "Release: $release\n";
44 }
45 elsif ((/^Source0:/) || (/^Source:/)) {
46 print $_;
47 $num=1;
48 for(@patches) {
49 print "Patch$num: $_";
50 $num++;
51 }
52 print "\n";
53 }
54 elsif (/^%setup/) {
55 print $_;
56 $num=1;
57 for(@patches) {
58 print "%patch$num -p1\n";
59 $num++;
60 }
61 print "\n";
62 }
63 else {
64 print $_;
65 }
66 }