4 # Thorsten Glaser <tg@mirbsd.org>
6 # Thorsten Glaser <tg@freewrt.org>
8 # Derived from the MirPorts Framework "update-patches" script:
10 # Copyright (c) 2003, 2004, 2005
11 # Thorsten "mirabile" Glaser <tg@MirBSD.de>
12 # Based upon code and idea (c) 2000
13 # Marc Espie for the OpenBSD project. All rights reserved.
15 # Provided that these terms and disclaimer and all copyright notices
16 # are retained or reproduced in an accompanying document, permission
17 # is granted to deal in this work without restriction, including un-
18 # limited rights to use, publicly perform, distribute, sell, modify,
19 # merge, give away, or sublicence.
21 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
22 # the utmost extent permitted by applicable law, neither express nor
23 # implied; without malicious intent or gross negligence. In no event
24 # may a licensor, author or contributor be held liable for indirect,
25 # direct, other damage, loss, or other issues arising in any way out
26 # of dealing in the work, even if advised of the possibility of such
27 # damage or existence of a defect, except proven that it results out
28 # of said person's immediate fault when using the work as intended.
34 if [[ ! -e $f1 ]]; then
35 [[ -d ${f1%/*}/. ]] || mkdir -p "${f1%/*}"
36 if [[ ! -s $f2 ]]; then
38 --- $f1 (non-existant)
44 touch -t 197001010000.00 "$f1"
46 diff -adup "$f1" "$f2"
53 TRANSFORM='sed s/[.+]/\\\\&/g'
54 PATCHDIR=$CURDIR/patches
55 EXTRADIR=$CURDIR/extra
59 SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
60 if [[ -n $SUBDIST ]]; then
61 mv "${WRKDIR1}.orig/${SUBDIST}" "${WRKDIR1}/${SUBDIST}.orig"
69 D_BASE=$(dirname "${WRKDIR1}")
70 D_SUB=$(basename "${WRKDIR1}")
74 ORGDIST=${D_BASE}/${D_SUB}.orig
76 if [[ -e $WRKDIST/.patched-newfiles ]]; then
77 touch "$ORGDIST/.patched-newfiles"
83 if [[ -e $WRKDIST/../.autoreconf_done ]]; then
84 touch "$ORGDIST/.autoreconf_done"
87 DIFF_FLAGS="-adu -I \"^--- $(print -r -- "$D_SUBP.orig/" | $TRANSFORM)@@ .*\""
88 DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(print -r -- "$D_SUBP/" | $TRANSFORM)@@ .*\""
90 (cd "${WRKDIST}"; find . -type f -print0) |&
91 while IFS= read -p -d '' -r file; do
93 [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue
94 for i in $DIFF_IGNOREFILES; do
95 [[ $file = $i ]] && continue 2
97 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
98 print -ru2 -- "Processing ${file}..."
99 # look in patchdir for an existing patchfile matching this
101 for i in $PATCH_LIST; do
102 # Ignore non-files, or old backup
103 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
105 # Patch found. Is this the one?
106 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then
107 # Multiple files in the diff?
108 if [[ $(grep -c "^--- $D_CMP" "$i") -gt 1 || \
109 $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]]; then
110 print -ru2 -- "Cannot process, $i contains patches"
111 print -ru2 -- "to multiple files! Aborting."
113 [[ -n $SUBDIST ]] && mv \
114 "${WRKDIR1}/${SUBDIST}.orig" \
115 "${WRKDIR1}.orig/${SUBDIST}"
118 # Multiple diffs with this file?
121 for j in $PATCH_LIST; do
122 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
124 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
125 "$j" >/dev/null || continue
129 if (( n != 1 )); then
130 print -ru2 -- "Cannot process, file $file"
131 print -ru2 -- "is contained in multiple patches:"
132 print -ru2 -- "$pflst"
134 [[ -n $SUBDIST ]] && mv \
135 "${WRKDIR1}/${SUBDIST}.orig" \
136 "${WRKDIR1}.orig/${SUBDIST}"
139 # No, process this patch
142 # found it, copy preamble before comparision
143 ( sed -e "/^--- /,\$d" <"$i"; \
144 cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
146 # did it change? mark it as changed
147 tfile=$(print -r -- "$file" | $TRANSFORM)
148 if eval diff "$(print -r -- "${DIFF_FLAGS}" | sed \
149 "s#@@#${tfile}#g")" '"$i" "$i.new"' 1>&2; then
152 print -ru2 -- "Patch $i for $file updated"
161 # Build a sensible name for the new patch file
162 patchname=patch-${file//[\/.
\x01- ]/_}
163 print -ru2 -- "No patch-* found for $file, creating $patchname"
164 ( cd "$D_BASE" && do_diff "$file" "$D_SUB.orig" "$D_SUB" ) >"$patchname"
166 accounted+=("$patchname")
169 # Verify all patches accounted for
172 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
173 grep '^\\ No newline at end of file' "$i" >/dev/null && \
174 print -ru2 -- "*** Patch $i needs manual intervention"
176 for j in "${accounted[@]}"; do
177 [[ $i = "$j" ]] || continue
181 (( found )) || print -ru2 -- "*** Patch $i not accounted for"
184 for i in "${edit[@]}"; do
188 [[ -n $SUBDIST ]] && mv "${WRKDIR1}/${SUBDIST}.orig" "${WRKDIR1}.orig/${SUBDIST}"