Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2010-2013, Intel Corporation. |
| 4 | # All Rights Reserved |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation; either version 2 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | # the GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | # |
| 20 | |
| 21 | # |
| 22 | # This script is intended to be used to prepare a series of patches |
| 23 | # and a cover letter in an appropriate and consistent format for |
| 24 | # submission to Open Embedded and The Yocto Project, as well as to |
| 25 | # related projects and layers. |
| 26 | # |
| 27 | |
| 28 | ODIR=pull-$$ |
| 29 | RELATIVE_TO="master" |
| 30 | COMMIT_ID="HEAD" |
| 31 | PREFIX="PATCH" |
| 32 | RFC=0 |
| 33 | |
| 34 | usage() { |
| 35 | CMD=$(basename $0) |
| 36 | cat <<EOM |
| 37 | Usage: $CMD [-h] [-o output_dir] [-m msg_body_file] [-s subject] [-r relative_to] [-i commit_id] [-d relative_dir] -u remote [-b branch] |
| 38 | -b branch Branch name in the specified remote (default: current branch) |
| 39 | -c Create an RFC (Request for Comment) patch series |
| 40 | -h Display this help message |
| 41 | -i commit_id Ending commit (default: HEAD) |
| 42 | -m msg_body_file The file containing a blurb to be inserted into the summary email |
| 43 | -o output_dir Specify the output directory for the messages (default: pull-PID) |
| 44 | -p prefix Use [prefix N/M] instead of [PATCH N/M] as the subject prefix |
| 45 | -r relative_to Starting commit (default: master) |
| 46 | -s subject The subject to be inserted into the summary email |
| 47 | -u remote The git remote where the branch is located |
| 48 | -d relative_dir Generate patches relative to directory |
| 49 | |
| 50 | Examples: |
| 51 | $CMD -u contrib -b nitin/basic |
| 52 | $CMD -u contrib -r distro/master -i nitin/distro -b nitin/distro |
| 53 | $CMD -u contrib -r master -i misc -b nitin/misc -o pull-misc |
| 54 | $CMD -u contrib -p "RFC PATCH" -b nitin/experimental |
| 55 | $CMD -u contrib -i misc -b nitin/misc -d ./bitbake |
| 56 | EOM |
| 57 | } |
| 58 | |
| 59 | # Parse and validate arguments |
| 60 | while getopts "b:cd:hi:m:o:p:r:s:u:" OPT; do |
| 61 | case $OPT in |
| 62 | b) |
| 63 | BRANCH="$OPTARG" |
| 64 | ;; |
| 65 | c) |
| 66 | RFC=1 |
| 67 | ;; |
| 68 | d) |
| 69 | RELDIR="$OPTARG" |
| 70 | ;; |
| 71 | h) |
| 72 | usage |
| 73 | exit 0 |
| 74 | ;; |
| 75 | i) |
| 76 | COMMIT_ID="$OPTARG" |
| 77 | ;; |
| 78 | m) |
| 79 | BODY="$OPTARG" |
| 80 | if [ ! -e "$BODY" ]; then |
| 81 | echo "ERROR: Body file does not exist" |
| 82 | exit 1 |
| 83 | fi |
| 84 | ;; |
| 85 | o) |
| 86 | ODIR="$OPTARG" |
| 87 | ;; |
| 88 | p) |
| 89 | PREFIX="$OPTARG" |
| 90 | ;; |
| 91 | r) |
| 92 | RELATIVE_TO="$OPTARG" |
| 93 | ;; |
| 94 | s) |
| 95 | SUBJECT="$OPTARG" |
| 96 | ;; |
| 97 | u) |
| 98 | REMOTE="$OPTARG" |
| 99 | REMOTE_URL=$(git config remote.$REMOTE.url) |
| 100 | if [ $? -ne 0 ]; then |
| 101 | echo "ERROR: git config failed to find a url for '$REMOTE'" |
| 102 | echo |
| 103 | echo "To add a remote url for $REMOTE, use:" |
| 104 | echo " git config remote.$REMOTE.url <url>" |
| 105 | exit 1 |
| 106 | fi |
| 107 | |
| 108 | # Rewrite private URLs to public URLs |
| 109 | # Determine the repository name for use in the WEB_URL later |
| 110 | case "$REMOTE_URL" in |
| 111 | *@*) |
| 112 | USER_RE="[A-Za-z0-9_.@][A-Za-z0-9_.@-]*\$\?" |
| 113 | PROTO_RE="[a-z][a-z+]*://" |
| 114 | GIT_RE="\(^\($PROTO_RE\)\?$USER_RE@\)\([^:/]*\)[:/]\(.*\)" |
| 115 | REMOTE_URL=${REMOTE_URL%.git} |
| 116 | REMOTE_REPO=$(echo $REMOTE_URL | sed "s#$GIT_RE#\4#") |
| 117 | REMOTE_URL=$(echo $REMOTE_URL | sed "s#$GIT_RE#git://\3/\4#") |
| 118 | ;; |
| 119 | *) |
| 120 | echo "WARNING: Unrecognized remote URL: $REMOTE_URL" |
| 121 | echo " The pull and browse URLs will likely be incorrect" |
| 122 | ;; |
| 123 | esac |
| 124 | ;; |
| 125 | esac |
| 126 | done |
| 127 | |
| 128 | if [ -z "$BRANCH" ]; then |
| 129 | BRANCH=$(git branch | grep -e "^\* " | cut -d' ' -f2) |
| 130 | echo "NOTE: Assuming remote branch '$BRANCH', use -b to override." |
| 131 | fi |
| 132 | |
| 133 | if [ -z "$REMOTE_URL" ]; then |
| 134 | echo "ERROR: Missing parameter -u, no git remote!" |
| 135 | usage |
| 136 | exit 1 |
| 137 | fi |
| 138 | |
| 139 | if [ $RFC -eq 1 ]; then |
| 140 | PREFIX="RFC $PREFIX" |
| 141 | fi |
| 142 | |
| 143 | |
| 144 | # Set WEB_URL from known remotes |
| 145 | WEB_URL="" |
| 146 | case "$REMOTE_URL" in |
| 147 | *git.yoctoproject.org*) |
| 148 | WEB_URL="http://git.yoctoproject.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH" |
| 149 | ;; |
| 150 | *git.pokylinux.org*) |
| 151 | WEB_URL="http://git.pokylinux.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH" |
| 152 | ;; |
| 153 | *git.openembedded.org*) |
| 154 | WEB_URL="http://cgit.openembedded.org/cgit.cgi/$REMOTE_REPO/log/?h=$BRANCH" |
| 155 | ;; |
| 156 | *github.com*) |
| 157 | WEB_URL="https://github.com/$REMOTE_REPO/tree/$BRANCH" |
| 158 | ;; |
| 159 | esac |
| 160 | |
| 161 | # Perform a sanity test on the web URL. Issue a warning if it is not |
| 162 | # accessible, but do not abort as users may want to run offline. |
| 163 | if [ -n "$WEB_URL" ]; then |
| 164 | wget --no-check-certificate -q $WEB_URL -O /dev/null |
| 165 | if [ $? -ne 0 ]; then |
| 166 | echo "WARNING: Branch '$BRANCH' was not found on the contrib git tree." |
| 167 | echo " Please check your remote and branch parameter before sending." |
| 168 | echo "" |
| 169 | fi |
| 170 | fi |
| 171 | |
| 172 | if [ -e $ODIR ]; then |
| 173 | echo "ERROR: output directory $ODIR exists." |
| 174 | exit 1 |
| 175 | fi |
| 176 | mkdir $ODIR |
| 177 | |
| 178 | if [ -n "$RELDIR" ]; then |
| 179 | ODIR=$(realpath $ODIR) |
| 180 | pdir=$(pwd) |
| 181 | cd $RELDIR |
| 182 | extraopts="--relative" |
| 183 | fi |
| 184 | |
| 185 | # Generate the patches and cover letter |
| 186 | git format-patch $extraopts -M40 --subject-prefix="$PREFIX" -n -o $ODIR --thread=shallow --cover-letter $RELATIVE_TO..$COMMIT_ID > /dev/null |
| 187 | |
| 188 | [ -n "$RELDIR" ] && cd $pdir |
| 189 | |
| 190 | # Customize the cover letter |
| 191 | CL="$ODIR/0000-cover-letter.patch" |
| 192 | PM="$ODIR/pull-msg" |
| 193 | GIT_VERSION=$(`git --version` | tr -d '[:alpha:][:space:].' | sed 's/\(...\).*/\1/') |
| 194 | NEWER_GIT_VERSION=210 |
| 195 | if [ $GIT_VERSION -lt $NEWER_GIT_VERSION ]; then |
| 196 | git request-pull $RELATIVE_TO $REMOTE_URL $COMMIT_ID >> "$PM" |
| 197 | else |
| 198 | git request-pull $RELATIVE_TO $REMOTE_URL :$BRANCH >> "$PM" |
| 199 | fi |
| 200 | if [ $? -ne 0 ]; then |
| 201 | echo "ERROR: git request-pull reported an error" |
| 202 | exit 1 |
| 203 | fi |
| 204 | |
| 205 | # The cover letter already has a diffstat, remove it from the pull-msg |
| 206 | # before inserting it. |
| 207 | sed -n "0,\#$REMOTE_URL# p" "$PM" | sed -i "/BLURB HERE/ r /dev/stdin" "$CL" |
| 208 | rm "$PM" |
| 209 | |
| 210 | # If this is an RFC, make that clear in the cover letter |
| 211 | if [ $RFC -eq 1 ]; then |
| 212 | (cat <<EOM |
| 213 | Please review the following changes for suitability for inclusion. If you have |
| 214 | any objections or suggestions for improvement, please respond to the patches. If |
| 215 | you agree with the changes, please provide your Acked-by. |
| 216 | |
| 217 | EOM |
| 218 | ) | sed -i "/BLURB HERE/ r /dev/stdin" "$CL" |
| 219 | fi |
| 220 | |
| 221 | # Insert the WEB_URL if there is one |
| 222 | if [ -n "$WEB_URL" ]; then |
| 223 | echo " $WEB_URL" | sed -i "\#$REMOTE_URL# r /dev/stdin" "$CL" |
| 224 | fi |
| 225 | |
| 226 | |
| 227 | # If the user specified a message body, insert it into the cover letter and |
| 228 | # remove the BLURB token. |
| 229 | if [ -n "$BODY" ]; then |
| 230 | sed -i "/BLURB HERE/ r $BODY" "$CL" |
| 231 | sed -i "/BLURB HERE/ d" "$CL" |
| 232 | fi |
| 233 | |
| 234 | # If the user specified a subject, replace the SUBJECT token with it. |
| 235 | if [ -n "$SUBJECT" ]; then |
| 236 | sed -i -e "s/\*\*\* SUBJECT HERE \*\*\*/$SUBJECT/" "$CL" |
| 237 | fi |
| 238 | |
| 239 | |
| 240 | # Generate report for user |
| 241 | cat <<EOM |
| 242 | The following patches have been prepared: |
| 243 | $(for PATCH in $(ls $ODIR/*); do echo " $PATCH"; done) |
| 244 | |
| 245 | Review their content, especially the summary mail: |
| 246 | $CL |
| 247 | |
| 248 | When you are satisfied, you can send them with: |
| 249 | send-pull-request -a -p $ODIR |
| 250 | EOM |
| 251 | |
| 252 | # Check the patches for trailing white space |
| 253 | egrep -q -e "^\+.*\s+$" $ODIR/* |
| 254 | if [ $? -ne 1 ]; then |
| 255 | echo |
| 256 | echo "WARNING: Trailing white space detected at these locations" |
| 257 | egrep -nH --color -e "^\+.*\s+$" $ODIR/* |
| 258 | fi |