| #!/usr/bin/perl -W |
| # |
| # convert git commit id to a pretty patch we can apply to the stable tree |
| # |
| # Written in perl because the bash version is broken, it doesn't pass |
| # through the patch correctly :( |
| # |
| |
| my $base_id = ""; |
| my $line; |
| my $firstline = "true"; |
| my $git_id; |
| my $header_complete = "false"; |
| my $signed_off_by_seen = "false"; |
| my $signed_off_by_complete = "false"; |
| my $eat_subject_trailer = "false"; |
| my $tmpfile; |
| #my $kernel_version; |
| |
| |
| $SIG{__DIE__} = sub |
| { |
| # what usually happens is we don't have the git version, so clean up |
| # the temp file we created. |
| if ($tmpfile ne "") { |
| unlink $tmpfile; |
| } |
| }; |
| |
| $numArgs = $#ARGV + 1; |
| if ($numArgs < 1) { |
| print "must provide git id\n"; |
| exit; |
| } |
| |
| $base_id = shift; |
| |
| if ($base_id eq "") { |
| print "must provide git id\n"; |
| exit; |
| } |
| |
| #$kernel_version = shift; |
| #if (!defined($kernel_version)) { |
| # $kernel_version = ""; |
| #} |
| |
| #print "handing commit id $base_id\n"; |
| |
| $tmpfile = `mktemp patch.XXXXX` || die "Failed to run mktemp"; |
| chomp($tmpfile); |
| |
| # if we were smart, we could just reconstruct the header the way we want to |
| # with a format: string, but we are not, so let's parse the thing out... |
| $from = `git show --pretty=format:"%aN <%ae>" $base_id | head -n 1` || die "Failed to run git to get from"; |
| $subj = `git show --pretty=format:"Subject: %s" $base_id | head -n 1` || die "Failed to run git to get subject"; |
| |
| open FILE, ">$tmpfile" || die "Failed to create $tmpfile"; |
| #open GIT, "git show --pretty=email $base_id |" || die "Failed to run git"; |
| open GIT, "git format-patch -n1 --no-numbered -k --stdout $base_id |" || die "Failed to run git"; |
| |
| while ($line = <GIT>) { |
| |
| # subjects have the fun ability to line-wrap, but we handled that above |
| # when we grabbed the "raw" subject, so just ignore trailing subject |
| # lines. |
| if ($eat_subject_trailer eq "true") { |
| $eat_subject_trailer = "false"; |
| if ($line =~m/^ /) { |
| # eat this line |
| next; |
| } |
| } |
| |
| # If this is the subject line, use our own. |
| if ($line =~m/^Subject: /) { |
| $line = $subj; |
| $eat_subject_trailer = "true"; |
| } |
| |
| if ($line =~m/^Signed-off-by:/) { |
| $signed_off_by_seen = "true"; |
| } |
| |
| if ($signed_off_by_seen eq "true") { |
| if ($signed_off_by_complete eq "false") { |
| if ($line eq "\n" || $line eq "---\n") { |
| print FILE "Signed-off-by: Greg Kroah-Hartman <gregkh\@linuxfoundation.org>\n"; |
| $signed_off_by_complete = "true"; |
| $signed_off_by_seen = "false"; |
| } |
| } |
| } |
| |
| print FILE $line; |
| |
| if ($firstline eq "true") { |
| my @from = split(/ /, $line); |
| $git_id = $from[1]; |
| #print "git_id = $git_id\n"; |
| $firstline = "false"; |
| } |
| if ($header_complete eq "false") { |
| if ($line eq "\n") { |
| print FILE "From: $from\n"; |
| print FILE "commit $git_id upstream.\n\n"; |
| $header_complete = "true"; |
| } |
| } |
| } |
| close GIT; |
| close FILE; |
| |
| #print "$tmpfile\n"; |
| |
| system "vim -c \":set syntax=mail\" $tmpfile"; |
| system "reset"; |
| $new_file = `rename-patch $tmpfile`; |
| chomp($new_file); |
| system "mv $new_file ~/linux/stable/"; |
| #print "moved $new_file to ~/linux/stable/\n"; |
| |
| print "cd ~/linux/stable && ./apply_it $new_file @ARGV\n"; |
| system "cd ~/linux/stable && ./apply_it $new_file @ARGV"; |
| #system "cp ~/linux/stable/$new_file ~/linux/longterm"; |
| #system "cd ~/linux/longterm && ./apply_it $new_file"; |
| |
| #TMPFILE1=`mktemp patch.XXXXXX` || exit 1 |
| #TMPFILE2=`mktemp patch.XXXXXX` || exit 1 |
| # |
| #GIT_ID=`git show $COMMIT_ID | head -n 1 | cut -f 2 -d ' '` |
| #FROM=`git show --pretty=email $COMMIT_ID | head -n 2 | grep "From: "` |
| # |
| #git show --pretty=email $COMMIT_ID > $TMPFILE1 |
| # |
| #HEADER_COMPLETE=false |
| #while read line |
| #do |
| # # Strip out the [PATCH] portion of the subject line, it's annoying. |
| # new=`echo "$line" | sed -e 's/^Subject: \[PATCH\]/Subject:/g'` |
| # |
| # # copy the line out to the new file |
| # echo "$new" >> $TMPFILE2 |
| # |
| # # add our special text (author and git id) right before |
| # # the changelog text happens. |
| # if [ "$line" == "" ] ; then |
| # if [ $HEADER_COMPLETE == false ] ; then |
| # echo "$FROM" >> $TMPFILE2 |
| # echo "" >> $TMPFILE2 |
| # echo "commit $GIT_ID upstream." >> $TMPFILE2 |
| # echo "" >> $TMPFILE2 |
| # HEADER_COMPLETE=true |
| # fi |
| # fi |
| #done < $TMPFILE1 |
| #rm $TMPFILE1 |
| #vim $TMPFILE2 |
| #PATCH=`rename-patch $TMPFILE2` |
| #mv $PATCH ~/linux/stable/ |
| # |
| #echo "moved $PATCH to ~/linux/stable/" |
| # |