dracut/git2spec.pl

62 lines
1.1 KiB
Perl
Raw Normal View History

2011-05-31 18:34:37 +04:00
#!/usr/bin/perl
sub last_tag {
open( GIT, 'git log --pretty=format:%H |');
LINE: while( <GIT> ) {
open( GIT2, "git tag --contains $_ |");
while( <GIT2> ) {
chomp;
last LINE if /..*/;
}
close GIT2;
}
$tag=$_;
close GIT2;
close GIT; # be done
return $tag;
};
sub create_patches {
my $tag=shift;
my $pdir=shift;
2011-05-31 18:34:37 +04:00
my $num=0;
2012-02-22 18:33:08 +04:00
open( GIT, 'git format-patch -M -N --no-signature -o "'.$pdir.'" '.$tag.' |');
2011-05-31 18:34:37 +04:00
@lines=<GIT>;
close GIT; # be done
return @lines;
};
2011-05-31 18:34:37 +04:00
use POSIX qw(strftime);
my $datestr = strftime "%Y%m%d", gmtime;
my $tag=shift;
my $pdir=shift;
2011-05-31 18:34:37 +04:00
$tag=&last_tag if not defined $tag;
my @patches=&create_patches($tag, $pdir);
2011-05-31 18:34:37 +04:00
my $num=$#patches + 2;
$tag=~s/[^0-9]+?([0-9]+)/$1/;
my $release="$num.git$datestr";
$release="1" if $num == 1;
while(<>) {
if (/^Version:/) {
print "Version: $tag\n";
}
elsif (/^Release:/) {
print "Release: $release%{?dist}\n";
2011-05-31 18:34:37 +04:00
}
elsif ((/^Source0:/) || (/^Source:/)) {
print $_;
$num=1;
for(@patches) {
2011-11-17 14:01:41 +04:00
s/.*\///g;
2011-05-31 18:34:37 +04:00
print "Patch$num: $_";
$num++;
}
print "\n";
}
else {
print $_;
}
}