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