-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply-patches.sh
More file actions
executable file
·72 lines (62 loc) · 2.59 KB
/
Copy pathapply-patches.sh
File metadata and controls
executable file
·72 lines (62 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# apply-patches.sh — bring the working tree's local patches
# (board/batocera/x86/local-patches/*.patch) up to date.
#
# These patches wire fork-only features into files this repo shares with
# upstream batocera (e.g. the top-level Config.in, or configgen's
# importer.py) without committing to them directly, so the shared files
# stay byte-for-byte upstream-clean and merges from batocera-linux:master
# don't conflict. A single patch file may touch more than one shared file
# for the same feature (e.g. standalone-mame.patch covers both Config.in
# and importer.py) — git apply treats that as one atomic unit. See "The
# local Config.in patches" in USER-INSTRUCTIONS.md.
#
# Not everything that looks like it needs this treatment does: some
# shared files (es_systems.yml's per-system emulators: sub-block, for
# one) are validated-but-unused by the code that reads them. Check
# whether an edit is actually load-bearing before reaching for a patch —
# dead code doesn't need to be preserved at all, patched or committed.
#
# Safe to re-run any time: each patch is checked before acting, so an
# already-applied patch is left alone and only missing ones get applied.
# This is the one place new local patches get registered — just drop a
# new *.patch file into board/batocera/x86/local-patches/ and it's picked
# up automatically, no edit to this script required.
#
# Usage: ./apply-patches.sh
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PATCH_DIR="${REPO_ROOT}/board/batocera/x86/local-patches"
cd "${REPO_ROOT}"
shopt -s nullglob
PATCHES=("${PATCH_DIR}"/*.patch)
shopt -u nullglob
if [ ${#PATCHES[@]} -eq 0 ]; then
echo "No patches found in ${PATCH_DIR}."
exit 0
fi
applied_count=0
already_count=0
failed_count=0
for patch in "${PATCHES[@]}"; do
name="$(basename "$patch")"
if git apply --check "$patch" 2>/dev/null; then
git apply "$patch"
echo "applied: ${name}"
applied_count=$((applied_count + 1))
elif git apply --reverse --check "$patch" 2>/dev/null; then
echo "already applied: ${name}"
already_count=$((already_count + 1))
else
echo "CONFLICT: ${name} — does not apply or reverse cleanly" >&2
echo " the file(s) it targets may have changed since this patch was written." >&2
echo " reconcile or regenerate ${name} by hand (see USER-INSTRUCTIONS.md)." >&2
failed_count=$((failed_count + 1))
fi
done
echo
echo "Summary: ${applied_count} applied, ${already_count} already applied, ${failed_count} conflicts."
if [ "$failed_count" -gt 0 ]; then
exit 1
fi