]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - scripts/c2p
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / scripts / c2p
CommitLineData
9e22a467
GKH
1#!/usr/bin/perl -W
2#
3# convert git commit id to a pretty patch we can apply to the stable tree
4#
5# Written in perl because the bash version is broken, it doesn't pass
6# through the patch correctly :(
7#
8
9my $base_id = "";
10my $line;
11my $firstline = "true";
12my $git_id;
13my $header_complete = "false";
b34caee8
GKH
14my $signed_off_by_seen = "false";
15my $signed_off_by_complete = "false";
904d0d6e 16my $eat_subject_trailer = "false";
9e22a467 17my $tmpfile;
a02dd1f0 18#my $kernel_version;
b34caee8
GKH
19
20
21$SIG{__DIE__} = sub
22{
23 # what usually happens is we don't have the git version, so clean up
24 # the temp file we created.
25 if ($tmpfile ne "") {
26 unlink $tmpfile;
27 }
28};
9e22a467 29
4aa5ba68 30$numArgs = $#ARGV + 1;
b34caee8 31if ($numArgs < 1) {
4aa5ba68
GKH
32 print "must provide git id\n";
33 exit;
34}
35
9e22a467
GKH
36$base_id = shift;
37
38if ($base_id eq "") {
39 print "must provide git id\n";
4aa5ba68 40 exit;
9e22a467
GKH
41}
42
a02dd1f0
GKH
43#$kernel_version = shift;
44#if (!defined($kernel_version)) {
45# $kernel_version = "";
46#}
b34caee8 47
9e22a467
GKH
48#print "handing commit id $base_id\n";
49
50$tmpfile = `mktemp patch.XXXXX` || die "Failed to run mktemp";
51chomp($tmpfile);
904d0d6e
GKH
52
53# if we were smart, we could just reconstruct the header the way we want to
54# with a format: string, but we are not, so let's parse the thing out...
55$from = `git show --pretty=format:"%aN <%ae>" $base_id | head -n 1` || die "Failed to run git to get from";
56$subj = `git show --pretty=format:"Subject: %s" $base_id | head -n 1` || die "Failed to run git to get subject";
9e22a467
GKH
57
58open FILE, ">$tmpfile" || die "Failed to create $tmpfile";
2f308883
GKH
59#open GIT, "git show --pretty=email $base_id |" || die "Failed to run git";
60open GIT, "git format-patch -n1 --no-numbered -k --stdout $base_id |" || die "Failed to run git";
9e22a467
GKH
61
62while ($line = <GIT>) {
904d0d6e
GKH
63
64 # subjects have the fun ability to line-wrap, but we handled that above
65 # when we grabbed the "raw" subject, so just ignore trailing subject
66 # lines.
67 if ($eat_subject_trailer eq "true") {
68 $eat_subject_trailer = "false";
69 if ($line =~m/^ /) {
70 # eat this line
71 next;
72 }
73 }
74
75 # If this is the subject line, use our own.
76 if ($line =~m/^Subject: /) {
77 $line = $subj;
78 $eat_subject_trailer = "true";
79 }
b34caee8
GKH
80
81 if ($line =~m/^Signed-off-by:/) {
82 $signed_off_by_seen = "true";
83 }
84
85 if ($signed_off_by_seen eq "true") {
86 if ($signed_off_by_complete eq "false") {
2f308883 87 if ($line eq "\n" || $line eq "---\n") {
b34caee8
GKH
88 print FILE "Signed-off-by: Greg Kroah-Hartman <gregkh\@linuxfoundation.org>\n";
89 $signed_off_by_complete = "true";
90 $signed_off_by_seen = "false";
91 }
92 }
93 }
94
95 print FILE $line;
96
9e22a467
GKH
97 if ($firstline eq "true") {
98 my @from = split(/ /, $line);
99 $git_id = $from[1];
100 #print "git_id = $git_id\n";
101 $firstline = "false";
102 }
103 if ($header_complete eq "false") {
104 if ($line eq "\n") {
904d0d6e 105 print FILE "From: $from\n";
9e22a467
GKH
106 print FILE "commit $git_id upstream.\n\n";
107 $header_complete = "true";
108 }
109 }
110}
111close GIT;
112close FILE;
113
114#print "$tmpfile\n";
115
b34caee8 116system "vim -c \":set syntax=mail\" $tmpfile";
4aa5ba68 117system "reset";
9e22a467
GKH
118$new_file = `rename-patch $tmpfile`;
119chomp($new_file);
120system "mv $new_file ~/linux/stable/";
4aa5ba68
GKH
121#print "moved $new_file to ~/linux/stable/\n";
122
a02dd1f0
GKH
123print "cd ~/linux/stable && ./apply_it $new_file @ARGV\n";
124system "cd ~/linux/stable && ./apply_it $new_file @ARGV";
b34caee8
GKH
125#system "cp ~/linux/stable/$new_file ~/linux/longterm";
126#system "cd ~/linux/longterm && ./apply_it $new_file";
9e22a467
GKH
127
128#TMPFILE1=`mktemp patch.XXXXXX` || exit 1
129#TMPFILE2=`mktemp patch.XXXXXX` || exit 1
130#
131#GIT_ID=`git show $COMMIT_ID | head -n 1 | cut -f 2 -d ' '`
132#FROM=`git show --pretty=email $COMMIT_ID | head -n 2 | grep "From: "`
133#
134#git show --pretty=email $COMMIT_ID > $TMPFILE1
135#
136#HEADER_COMPLETE=false
137#while read line
138#do
139# # Strip out the [PATCH] portion of the subject line, it's annoying.
140# new=`echo "$line" | sed -e 's/^Subject: \[PATCH\]/Subject:/g'`
141#
142# # copy the line out to the new file
143# echo "$new" >> $TMPFILE2
144#
145# # add our special text (author and git id) right before
146# # the changelog text happens.
147# if [ "$line" == "" ] ; then
148# if [ $HEADER_COMPLETE == false ] ; then
149# echo "$FROM" >> $TMPFILE2
150# echo "" >> $TMPFILE2
151# echo "commit $GIT_ID upstream." >> $TMPFILE2
152# echo "" >> $TMPFILE2
153# HEADER_COMPLETE=true
154# fi
155# fi
156#done < $TMPFILE1
157#rm $TMPFILE1
158#vim $TMPFILE2
159#PATCH=`rename-patch $TMPFILE2`
160#mv $PATCH ~/linux/stable/
161#
162#echo "moved $PATCH to ~/linux/stable/"
163#