3 # Patch sources using git-am, aligning things to use git-format-patch for
6 # (c) 2016 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 git commit
-a --allow-empty \
40 --author="OpenADK <wbx@openadk.org>" \
41 -m "OpenADK patch marker: 0000"
43 [ -e .git
/rebase-apply
] && \
47 patch_tmp
=$
(printf ".git/patch_tmp/%04d" $i)
48 while [ -d $patch_tmp ]; do
50 patch_tmp
=$
(printf ".git/patch_tmp/%04d" $i)
53 patch_series
=$
(printf "%04d" $i)
57 for i
in $
(eval echo ${patchpattern}); do
58 test -e "$i" ||
continue
63 type="gzip"; uncomp
="gunzip -dc"; ;;
65 type="bzip"; uncomp
="bunzip -dc"; ;;
67 type="bzip2"; uncomp
="bunzip2 -dc"; ;;
69 type="zip"; uncomp
="unzip -d"; ;;
71 type="compress"; uncomp
="uncompress -c"; ;;
73 type="plaintext"; uncomp
="cat"; ;;
75 [ -d "${i}" ] && echo "Ignoring subdirectory ${i}" && continue
76 echo "$(basename $i)" >>${targetdir}/${patch_tmp}/__patchfiles__
78 patchname
="$(basename -s .gz -s .bz -s .bz2 -s .zip -s .Z -s .patch $i)"
79 if ! grep -q '^Subject: ' ${i}; then
80 fake_hdr
="From: OpenADK <wbx@openadk.org>\nSubject: [PATCH] ${patchname#[0-9]*-}\n\n"
82 { echo -en $fake_hdr; ${uncomp} ${i}; } >${targetdir}/${patch_tmp}/${patchname}.
patch
86 # no patches to apply? bail out
87 [ -e ${targetdir}/${patch_tmp}/__patchfiles__
] ||
{
88 rmdir ${targetdir}/${patch_tmp}
92 # provide backwards compatibility to old style using 'patch' program
93 # XXX: this is unsafe and should be dropped at some point
96 realpath
$patchdir >${targetdir}/${patch_tmp}/__patchdir__
98 git am
$am_opts ${patch_tmp}/*.
patch
100 echo "git-am failed! Please fix patches!"
103 git commit
-a --allow-empty \
104 --author="OpenADK <wbx@openadk.org>" \
105 -m "OpenADK patch marker: $patch_series"