]> git.ipfire.org Git - thirdparty/dracut.git/blob - git2spec.pl
Makefile, git2spec.pl: use temporary builddir
[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 $pdir=shift;
22 my $num=0;
23 open( GIT, 'git format-patch -N --no-signature -o "'.$pdir.'" '.$tag.' |');
24 @lines=<GIT>;
25 close GIT; # be done
26 return @lines;
27 };
28
29 use POSIX qw(strftime);
30 my $datestr = strftime "%Y%m%d", gmtime;
31
32 my $tag=shift;
33 my $pdir=shift;
34 $tag=&last_tag if not defined $tag;
35 my @patches=&create_patches($tag, $pdir);
36 my $num=$#patches + 2;
37 $tag=~s/[^0-9]+?([0-9]+)/$1/;
38 my $release="$num.git$datestr";
39 $release="1" if $num == 1;
40
41 while(<>) {
42 if (/^Version:/) {
43 print "Version: $tag\n";
44 }
45 elsif (/^Release:/) {
46 print "Release: $release%{?dist}\n";
47 }
48 elsif ((/^Source0:/) || (/^Source:/)) {
49 print $_;
50 $num=1;
51 for(@patches) {
52 print "Patch$num: $_";
53 $num++;
54 }
55 print "\n";
56 }
57 else {
58 print $_;
59 }
60 }