]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - scripts/c2p
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / scripts / c2p
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
9 my $base_id = "";
10 my $line;
11 my $firstline = "true";
12 my $git_id;
13 my $header_complete = "false";
14 my $signed_off_by_seen = "false";
15 my $signed_off_by_complete = "false";
16 my $eat_subject_trailer = "false";
17 my $tmpfile;
18 #my $kernel_version;
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 };
29
30 $numArgs = $#ARGV + 1;
31 if ($numArgs < 1) {
32 print "must provide git id\n";
33 exit;
34 }
35
36 $base_id = shift;
37
38 if ($base_id eq "") {
39 print "must provide git id\n";
40 exit;
41 }
42
43 #$kernel_version = shift;
44 #if (!defined($kernel_version)) {
45 # $kernel_version = "";
46 #}
47
48 #print "handing commit id $base_id\n";
49
50 $tmpfile = `mktemp patch.XXXXX` || die "Failed to run mktemp";
51 chomp($tmpfile);
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";
57
58 open FILE, ">$tmpfile" || die "Failed to create $tmpfile";
59 open GIT, "git show --pretty=email $base_id |" || die "Failed to run git";
60
61 while ($line = <GIT>) {
62
63 # subjects have the fun ability to line-wrap, but we handled that above
64 # when we grabbed the "raw" subject, so just ignore trailing subject
65 # lines.
66 if ($eat_subject_trailer eq "true") {
67 $eat_subject_trailer = "false";
68 if ($line =~m/^ /) {
69 # eat this line
70 next;
71 }
72 }
73
74 # If this is the subject line, use our own.
75 if ($line =~m/^Subject: /) {
76 $line = $subj;
77 $eat_subject_trailer = "true";
78 }
79
80 if ($line =~m/^Signed-off-by:/) {
81 $signed_off_by_seen = "true";
82 }
83
84 if ($signed_off_by_seen eq "true") {
85 if ($signed_off_by_complete eq "false") {
86 if ($line eq "\n") {
87 print FILE "Signed-off-by: Greg Kroah-Hartman <gregkh\@linuxfoundation.org>\n";
88 $signed_off_by_complete = "true";
89 $signed_off_by_seen = "false";
90 }
91 }
92 }
93
94 print FILE $line;
95
96 if ($firstline eq "true") {
97 my @from = split(/ /, $line);
98 $git_id = $from[1];
99 #print "git_id = $git_id\n";
100 $firstline = "false";
101 }
102 if ($header_complete eq "false") {
103 if ($line eq "\n") {
104 print FILE "From: $from\n";
105 print FILE "commit $git_id upstream.\n\n";
106 $header_complete = "true";
107 }
108 }
109 }
110 close GIT;
111 close FILE;
112
113 #print "$tmpfile\n";
114
115 system "vim -c \":set syntax=mail\" $tmpfile";
116 system "reset";
117 $new_file = `rename-patch $tmpfile`;
118 chomp($new_file);
119 system "mv $new_file ~/linux/stable/";
120 #print "moved $new_file to ~/linux/stable/\n";
121
122 print "cd ~/linux/stable && ./apply_it $new_file @ARGV\n";
123 system "cd ~/linux/stable && ./apply_it $new_file @ARGV";
124 #system "cp ~/linux/stable/$new_file ~/linux/longterm";
125 #system "cd ~/linux/longterm && ./apply_it $new_file";
126
127 #TMPFILE1=`mktemp patch.XXXXXX` || exit 1
128 #TMPFILE2=`mktemp patch.XXXXXX` || exit 1
129 #
130 #GIT_ID=`git show $COMMIT_ID | head -n 1 | cut -f 2 -d ' '`
131 #FROM=`git show --pretty=email $COMMIT_ID | head -n 2 | grep "From: "`
132 #
133 #git show --pretty=email $COMMIT_ID > $TMPFILE1
134 #
135 #HEADER_COMPLETE=false
136 #while read line
137 #do
138 # # Strip out the [PATCH] portion of the subject line, it's annoying.
139 # new=`echo "$line" | sed -e 's/^Subject: \[PATCH\]/Subject:/g'`
140 #
141 # # copy the line out to the new file
142 # echo "$new" >> $TMPFILE2
143 #
144 # # add our special text (author and git id) right before
145 # # the changelog text happens.
146 # if [ "$line" == "" ] ; then
147 # if [ $HEADER_COMPLETE == false ] ; then
148 # echo "$FROM" >> $TMPFILE2
149 # echo "" >> $TMPFILE2
150 # echo "commit $GIT_ID upstream." >> $TMPFILE2
151 # echo "" >> $TMPFILE2
152 # HEADER_COMPLETE=true
153 # fi
154 # fi
155 #done < $TMPFILE1
156 #rm $TMPFILE1
157 #vim $TMPFILE2
158 #PATCH=`rename-patch $TMPFILE2`
159 #mv $PATCH ~/linux/stable/
160 #
161 #echo "moved $PATCH to ~/linux/stable/"
162 #