From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1NLiBv-0007uZ-4R for garchives@archives.gentoo.org; Fri, 18 Dec 2009 19:08:43 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 99FDFE059C; Fri, 18 Dec 2009 19:07:27 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 5540BE059C for ; Fri, 18 Dec 2009 19:07:27 +0000 (UTC) Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id A703467F52 for ; Fri, 18 Dec 2009 19:07:26 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-dev@lists.gentoo.org Subject: [gentoo-dev] rewritten epatch Date: Fri, 18 Dec 2009 14:07:47 -0500 User-Agent: KMail/1.12.4 (Linux/2.6.31.4; KDE/4.3.4; x86_64; ; ) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart14852811.07CSf1jWTY"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200912181407.47924.vapier@gentoo.org> X-Archives-Salt: 189baf12-3e04-42ee-a2cc-46d847086e78 X-Archives-Hash: 68bc91e0c6506f21096989d02506d585 --nextPart14852811.07CSf1jWTY Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable for various reasons/limitations/bugs/whatever, i rewrote epatch. seems to work for me, but in case someone wants to check before i release: epatch() { _epatch_draw_line() { # create a line of same length as input string [[ -z $1 ]] && set "$(printf "%65s" '')" echo "${1//?/=3D}" } unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 # Let the rest of the code process one user arg at a time -- # each arg may expand into multiple patches, and each arg may # need to start off with the default global EPATCH_xxx values if [[ $# -gt 1 ]] ; then local m for m in "$@" ; do epatch "${m}" done return 0 fi local SINGLE_PATCH=3D"no" # no args means process ${EPATCH_SOURCE} [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}" if [[ -f $1 ]] ; then SINGLE_PATCH=3D"yes" set -- "$1" # Use the suffix from the single patch (localize it); the code # below will find the suffix for us local EPATCH_SUFFIX=3D$1 elif [[ -d $1 ]] ; then # Some people like to make dirs of patches w/out suffixes (vim) set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} else # sanity check ... if it isn't a dir or file, wtf man ? [[ $# -ne 0 ]] && EPATCH_SOURCE=3D$1 echo eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" eerror eerror " ${EPATCH_SOURCE}" eerror " ( ${EPATCH_SOURCE##*/} )" echo die "Cannot find \$EPATCH_SOURCE!" fi local PIPE_CMD case ${EPATCH_SUFFIX##*\.} in xz) PIPE_CMD=3D"xz -dc" ;; lzma) PIPE_CMD=3D"lzma -dc" ;; bz2) PIPE_CMD=3D"bzip2 -dc" ;; gz|Z|z) PIPE_CMD=3D"gzip -dc" ;; ZIP|zip) PIPE_CMD=3D"unzip -p" ;; *) ;; esac [[ ${SINGLE_PATCH} =3D=3D "no" ]] && einfo "${EPATCH_MULTI_MSG}" local x for x in "$@" ; do # If the patch dir given contains subdirs, or our EPATCH_SUFFIX # didn't match anything, ignore continue on [[ ! -f ${x} ]] && continue local patchname=3D${x##*/} # Apply single patches, or forced sets of patches, or # patches with ARCH dependant names. # ???_arch_foo.patch # Else, skip this input altogether local a=3D${patchname#*_} # strip the ???_ a=3D${a%%_*} # strip the _foo.patch if ! [[ ${SINGLE_PATCH} =3D=3D "yes" || \ ${EPATCH_FORCE} =3D=3D "yes" || \ ${a} =3D=3D all || \ ${a} =3D=3D ${ARCH} ]] then continue fi # Let people filter things dynamically if [[ -n ${EPATCH_EXCLUDE} ]] ; then # let people use globs in the exclude eshopts_push -o noglob local ex for ex in ${EPATCH_EXCLUDE} ; do if [[ ${patchname} =3D=3D ${ex} ]] ; then eshopts_pop continue fi done eshopts_pop fi if [[ ${SINGLE_PATCH} =3D=3D "yes" ]] ; then if [[ -n ${EPATCH_SINGLE_MSG} ]] ; then einfo "${EPATCH_SINGLE_MSG}" else einfo "Applying ${patchname} ..." fi else einfo " ${patchname} ..." fi # most of the time, there will only be one run per unique name, # but if there are more, make sure we get unique log filenames local STDERR_TARGET=3D"${T}/${patchname}.out" if [[ -e ${STDERR_TARGET} ]] ; then STDERR_TARGET=3D"${T}/${patchname}-$$.out" fi printf "***** %s *****\n\n" "${patchname}" > "${STDERR_TARGET}" # Decompress the patch if need be local count=3D0 local PATCH_TARGET if [[ -n ${PIPE_CMD} ]] ; then PATCH_TARGET=3D"${T}/$$.patch" echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TA= RGET}" if ! (${PIPE_CMD} "${x}" > "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1= ; then echo eerror "Could not extract patch!" #die "Could not extract patch!" count=3D5 break fi else PATCH_TARGET=3D${x} fi # Check for absolute paths in patches. If sandbox is disabled, # people could (accidently) patch files in the root filesystem. # Or trigger other unpleasantries #237667. So disallow -p0 on # such patches. local abs_paths=3D$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != =3D "/dev/null" { print }') if [[ -n ${abs_paths} ]] ; then count=3D1 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs= _paths}" >> "${STDERR_TARGET}" fi # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ while [[ ${count} -lt 5 ]] ; do # Generate some useful debug info ... ( _epatch_draw_line "***** ${patchname} *****" echo echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}= '" echo _epatch_draw_line "***** ${patchname} *****" ) >> "${STDERR_TARGET}" if (patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}") >>= "${STDERR_TARGET}" 2>&1 ;=20 then ( _epatch_draw_line "***** ${patchname} *****" echo echo "ACTUALLY APPLYING ${patchname} ..." echo _epatch_draw_line "***** ${patchname} *****" patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 ) >> "${STDERR_TARGET}" if [ $? -ne 0 ] ; then echo eerror "A dry-run of patch command succeeded, but actually" eerror "applying the patch failed!" #die "Real world sux compared to the dreamworld!" count=3D5 fi break fi : $(( count++ )) done # if we had to decompress the patch, delete the temp one if [[ -n ${PIPE_CMD} ]] ; then rm -f "${PATCH_TARGET}" fi if [[ ${count} -ge 5 ]] ; then echo eerror "Failed Patch: ${patchname} !" eerror " ( ${PATCH_TARGET} )" eerror eerror "Include in your bugreport the contents of:" eerror eerror " ${STDERR_TARGET}" echo die "Failed Patch: ${patchname}!" fi # if everything worked, delete the patch log rm -f "${STDERR_TARGET}" eend 0 done [[ ${SINGLE_PATCH} =3D=3D "no" ]] && einfo "Done with patching" : # everything worked } =2Dmike --nextPart14852811.07CSf1jWTY Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) iQIcBAABAgAGBQJLK9MDAAoJEEFjO5/oN/WBeiMQAIigBTGWBqyFcIvcWd3XpqhU Ks3BPMLAJ5fd9XjJ5ze/nORmiZdfErjWUw+iHo2mZKrEbSln5SYIe2i2COAsgrgv 7K19a8IaPci1NN8df9/fMgrqnUmDhdFeqPZjVuFtP4XusOFZIJv+WahFyy4sH9KH ehB57+dwJ6LC3B0BQJ4YGdu9nftr7VSmrfhahqA1OBPtzccEML7zlOM5kSuScNYs jvJuZ8mrBb1oC3dCA0qbX97EJTAP++CmeHCPqqzioaGrY3rmId1moq75dXiEMnz8 4LzAEuKs7LPNgrBSqkciB+6vACQkI7HskbKgUYdlEtEEfThH8ZDaYF9hF/xG1M3u K8vzerS2vWbt9Uk2wHvwBAoUqYnEKwH2e20ZTHp2Zy1//9azKMLpb2zSKqgGOJ2h KXS9b6ZiTOEYhTkrv0S1me1RaZOG1KC+XxlN+lpTGmV8pffvo9Lyqse1BamIurfM +qHpY8XiZQoS+sZPCG1vv8sqdAB2KlvGFmINZNvItZhk2ImIoRKe7tMs2FOh5+Bh FVVleXU4HP90SkUfBUi6txegjqZeMKMId5kRRp/oLBTJ+1iliSp2HBdnL8hSU4Oj J5TmyQr50sS8bBSc8bstwROq7VpbWUoAegi4hH6yUXx53t9tjlAJybTkKIFdobJ9 sfBNV5g71K1edAaDy9/X =5afI -----END PGP SIGNATURE----- --nextPart14852811.07CSf1jWTY--