3 # Patch sources using git-am, aligning things to use git-format-patch for
6 # (c) 2021 Phil Sutter <phil@nwl.cc>
8 # Based on the classic patch.sh, written by:
10 # (c) 2006, 2007 Thorsten Glaser <tg@freewrt.org>
11 # (c) 2002 Erik Andersen <andersen@codepoet.org>
13 [[ -n $BASH_VERSION ]] && shopt -s extglob
15 # Set directories from arguments, or use defaults.
17 patchdir
=${2-../patches}
20 if [ ! -d "${targetdir}" ] ; then
21 echo "Aborting. '${targetdir}' is not a directory."
24 if [ ! -d "${patchdir}" ] ; then
25 echo "Aborting. '${patchdir}' is not a directory."
32 if [ ! -d .git
]; then
33 # drop leftover .gitignores in non-git sources, they
34 # might prevent us from patching 'temporary' files
35 # which are still present in the tarball.
36 find .
-name .gitignore
-delete
39 elif [ -e .git
/rebase-apply
]; then
44 patch_tmp
=$
(printf ".git/patch_tmp/%04d" $i)
45 while [ -d $patch_tmp ]; do
47 patch_tmp
=$
(printf ".git/patch_tmp/%04d" $i)
50 patch_series
=$
(printf "%04d" $i)
52 git commit
--allow-empty --no-signoff --no-gpg-sign \
53 --author="OpenADK <wbx@openadk.org>" \
54 -m "OpenADK patch marker: $patch_series"
58 for i
in $
(eval echo ${patchpattern}); do
59 test -e "$i" ||
continue
64 type="gzip"; uncomp
="gunzip -dc"; ;;
66 type="bzip"; uncomp
="bunzip -dc"; ;;
68 type="bzip2"; uncomp
="bunzip2 -dc"; ;;
70 type="zip"; uncomp
="unzip -d"; ;;
72 type="compress"; uncomp
="uncompress -c"; ;;
74 type="plaintext"; uncomp
="cat"; ;;
76 [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
77 echo "$(basename $i)" >>${targetdir}/${patch_tmp}/__patchfiles__
78 patchname
="$(basename -s .gz -s .bz -s .bz2 -s .zip -s .Z -s .patch $i)"
80 if ! grep -q '^Subject: ' ${i}; then
81 echo "From: OpenADK <wbx@openadk.org>"
82 echo "Subject: [PATCH] ${patchname#[0-9]*-}"
86 } >${targetdir}/${patch_tmp}/${patchname}.
patch
90 # no patches to apply? bail out
91 [ -e ${targetdir}/${patch_tmp}/__patchfiles__
] ||
{
92 rmdir ${targetdir}/${patch_tmp}
96 # provide backwards compatibility to old style using 'patch' program
97 # XXX: this is unsafe and should be dropped at some point
101 realpath
$patchdir >${targetdir}/${patch_tmp}/__patchdir__
103 git am
$am_opts ${patch_tmp}/*.
patch
104 if [ $?
!= 0 ] ; then
105 echo "git-am failed! Please fix patches!"