]> git.ipfire.org Git - thirdparty/dracut.git/blobdiff - git2spec.pl
Fix 98dracut-systemd/dracut-emergency.sh
[thirdparty/dracut.git] / git2spec.pl
index 2ea74c835ddebb0ef9cbe1a3d2a8c2029d7f8a65..7853791e715a3e833a600acc05918bd0c11d6476 100755 (executable)
@@ -1,44 +1,41 @@
 #!/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 $num=0;
-    open( GIT, 'git format-patch --no-renames -N --no-signature '.$tag.' |');
-    @lines=<GIT>;
-    close GIT;         # be done
+    my $pdir=shift;
+    my $n=1;
+    my @lines;
+    my $fname;
+    my $f=0;
+
+    mkdir $pdir, 0755;
+
+    open( GIT, 'git log -p --pretty=email --stat -m --first-parent --reverse '.$tag.'..HEAD |');
+
+    while (<GIT>) {
+        if (/^From [a-z0-9]{40} .*$/) {
+            $fname = sprintf("%04d", $n++).".patch";
+            open FH, ">".$pdir."/".$fname;
+            $f=1;
+        }
+        if (/^---$/ && $f == 1) {
+            push @lines, $fname;
+            $f=0;
+        }
+        print FH;
+    }
+
     return @lines;
 };
 
-sub filter_patch {
-       my $patch=shift;
-       open(P, $patch);
-       @lines=<P>;
-       close(P);
-       grep (/^ 0 files changed/, @lines);
-}
-
 use POSIX qw(strftime);
 my $datestr = strftime "%Y%m%d", gmtime;
 
 my $tag=shift;
-$tag=&last_tag if not defined $tag;
-my @patches=&create_patches($tag);
+my $pdir=shift;
+$tag=`git describe --abbrev=0 --tags` if not defined $tag;
+chomp($tag);
+my @patches=&create_patches($tag, $pdir);
 my $num=$#patches + 2;
 $tag=~s/[^0-9]+?([0-9]+)/$1/;
 my $release="$num.git$datestr";
@@ -48,25 +45,15 @@ while(<>) {
     if (/^Version:/) {
        print "Version: $tag\n";
     }
-    elsif (/^Release:/) {
-       print "Release: $release%{?dist}\n";
+    elsif (/^%define dist_free_release/) {
+       print "%define dist_free_release $release\n";
     }
     elsif ((/^Source0:/) || (/^Source:/)) {
        print $_;
        $num=1;
        for(@patches) {
-           next if filter_patch $_;
-           print "Patch$num: $_";
-           $num++;
-       }
-       print "\n";
-    }
-    elsif (/^%setup/) {
-       print $_;
-       $num=1;
-       for(@patches) {
-           next if filter_patch $_;
-           print "%patch$num -p1\n";
+           s/.*\///g;
+           print "Patch$num: $_\n";
            $num++;
        }
        print "\n";