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