]> git.ipfire.org Git - thirdparty/dracut.git/blob - git2spec.pl
2ea74c835ddebb0ef9cbe1a3d2a8c2029d7f8a65
[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
28 sub filter_patch {
29 my $patch=shift;
30 open(P, $patch);
31 @lines=<P>;
32 close(P);
33 grep (/^ 0 files changed/, @lines);
34 }
35
36 use POSIX qw(strftime);
37 my $datestr = strftime "%Y%m%d", gmtime;
38
39 my $tag=shift;
40 $tag=&last_tag if not defined $tag;
41 my @patches=&create_patches($tag);
42 my $num=$#patches + 2;
43 $tag=~s/[^0-9]+?([0-9]+)/$1/;
44 my $release="$num.git$datestr";
45 $release="1" if $num == 1;
46
47 while(<>) {
48 if (/^Version:/) {
49 print "Version: $tag\n";
50 }
51 elsif (/^Release:/) {
52 print "Release: $release%{?dist}\n";
53 }
54 elsif ((/^Source0:/) || (/^Source:/)) {
55 print $_;
56 $num=1;
57 for(@patches) {
58 next if filter_patch $_;
59 print "Patch$num: $_";
60 $num++;
61 }
62 print "\n";
63 }
64 elsif (/^%setup/) {
65 print $_;
66 $num=1;
67 for(@patches) {
68 next if filter_patch $_;
69 print "%patch$num -p1\n";
70 $num++;
71 }
72 print "\n";
73 }
74 else {
75 print $_;
76 }
77 }