scripts/patch-rework.sh
changeset 2224 fc58927f24b8
parent 2147 0ec4491d6496
child 2564 5d4e91c0343e
     1.1 --- a/scripts/patch-rework.sh	Thu Oct 07 23:45:25 2010 +0200
     1.2 +++ b/scripts/patch-rework.sh	Sun Dec 19 11:57:08 2010 +0100
     1.3 @@ -9,32 +9,75 @@
     1.4  # The remainder is for diff
     1.5  diff="$@"
     1.6  
     1.7 +do_help() {
     1.8 +    cat <<-_EOF_
     1.9 +		${0##*/}: transform a patchset of non-p1 patches into -p1 patches
    1.10 +		
    1.11 +		Usage:
    1.12 +		    ${0##*/} <basedir> <src> <dst> [diffopts ...]
    1.13 +		
    1.14 +		Where:
    1.15 +		    basedir
    1.16 +		        points to the directory of the component to patch
    1.17 +		
    1.18 +		    src
    1.19 +		        points to the directory containing the existing patchset
    1.20 +		        to transform
    1.21 +		
    1.22 +		    dst
    1.23 +		        points to the directory where to put transformed patches
    1.24 +		
    1.25 +		    diffopts
    1.26 +		        optional options to pass to diff, for debug purposes. You
    1.27 +		        should not need it
    1.28 +		
    1.29 +		Example:
    1.30 +		    Transform Gentoo patches against gcc-4.4.2 (some of which are
    1.31 +		    -p0, -p1 or even -p2 patches) into all -p1 patches:
    1.32 +		
    1.33 +		        tar xjf gcc-4.4.2.tar.bz2
    1.34 +		        patch-rework.sh gcc-4.4.2                   \\
    1.35 +		                        /path/to/gentoo/gcc/patches \\
    1.36 +		                        gcc-4.4.2.patches
    1.37 +		_EOF_
    1.38 +}
    1.39 +
    1.40 +# Sanity checks
    1.41 +if [    -z "${base}"                    \
    1.42 +     -o ! -d "${base}"                  \
    1.43 +     -o ! -d "${src}"                   \
    1.44 +     -o -e "${dst}" -a ! -d "${dst}"    \
    1.45 +   ]; then
    1.46 +	do_help
    1.47 +	exit 1
    1.48 +fi
    1.49 +
    1.50 +mkdir -p "${dst}"
    1.51 +base="${base%%/}"
    1.52 +src="$( cd "${src}"; pwd )"
    1.53 +dst="$( cd "${dst}"; pwd )"
    1.54 +
    1.55  # This function checks that the files listed in the file in "$1"
    1.56  # do exist, at the given depth-stripping level (aka diff -p#)
    1.57  do_check_files_at_depth() {
    1.58    local flist="$1"
    1.59    local depth="$2"
    1.60 -  local ok=0  # 0: OK,  !0: KO
    1.61 +  local ret=0   # 0: OK,  !0: KO
    1.62  
    1.63    exec 6<&0
    1.64    exec 7<"${flist}"
    1.65  
    1.66    while read -u7 f; do
    1.67      f="$( echo "${f}" |sed -r -e "s:^([^/]+/){${depth}}::;" )"
    1.68 -    [ -f "${f}" ] || ok=1
    1.69 +    [ -f "${f}" ] || ret=1
    1.70    done
    1.71  
    1.72    exec 7<&-
    1.73    exec <&6
    1.74  
    1.75 -  return ${ok}
    1.76 +  return ${ret}
    1.77  }
    1.78  
    1.79 -mkdir -p "${dst}"
    1.80 -base="${base%%/}"
    1.81 -src="$( cd "${src}"; pwd )"
    1.82 -dst="$( cd "${dst}"; pwd )"
    1.83 -
    1.84  # Iterate through patches
    1.85  for p in "${src}/"*.patch; do
    1.86    pname="$( basename "${p}" )"