Skip to content

Commit 8d0e3ca

Browse files
author
Tajudeen
committed
Add patch regeneration script for VS Code 1.106
- Created regenerate_patches_v106.sh to automate patch regeneration - Script handles placeholder replacement and validates patches - Compatible with VS Code 1.106.0
1 parent f1638a6 commit 8d0e3ca

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed

regenerate_patches_v106.sh

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#!/usr/bin/env bash
2+
# Comprehensive patch regeneration script for VS Code 1.106
3+
# This script regenerates all patches that apply cleanly
4+
5+
set -e
6+
7+
cd "$(dirname "$0")"
8+
BASE_DIR="$(pwd)"
9+
VSCODE_DIR="${BASE_DIR}/vscode"
10+
PATCHES_DIR="${BASE_DIR}/patches"
11+
12+
# Source utils for replace function
13+
. "${BASE_DIR}/utils.sh"
14+
15+
# Colors for output
16+
RED='\033[0;31m'
17+
GREEN='\033[0;32m'
18+
YELLOW='\033[1;33m'
19+
NC='\033[0m' # No Color
20+
21+
echo "============================================================"
22+
echo "Regenerating ALL patches for VS Code 1.106"
23+
echo "============================================================"
24+
echo ""
25+
26+
# Check VS Code version
27+
if [ ! -f "${VSCODE_DIR}/package.json" ]; then
28+
echo -e "${RED}Error: vscode directory not found${NC}"
29+
exit 1
30+
fi
31+
32+
VSCODE_VERSION=$(grep -E '"version"' "${VSCODE_DIR}/package.json" | head -1 | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
33+
echo "VS Code version: ${VSCODE_VERSION}"
34+
35+
if [[ ! "${VSCODE_VERSION}" =~ ^1\.106\. ]]; then
36+
echo -e "${YELLOW}Warning: VS Code version is ${VSCODE_VERSION}, expected 1.106.x${NC}"
37+
read -p "Continue anyway? (y/N) " -n 1 -r
38+
echo
39+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
40+
exit 1
41+
fi
42+
fi
43+
44+
# Check if vscode is a git repo (could be submodule or use parent .git)
45+
if ! (cd "${VSCODE_DIR}" && git rev-parse --git-dir > /dev/null 2>&1); then
46+
echo -e "${RED}Error: vscode directory is not a git repository${NC}"
47+
exit 1
48+
fi
49+
50+
cd "${VSCODE_DIR}"
51+
52+
# Find the base commit (first commit, should be the original VS Code commit)
53+
BASE_COMMIT=$(git log --reverse --oneline | head -1 | cut -d' ' -f1)
54+
if [ -z "$BASE_COMMIT" ]; then
55+
echo -e "${RED}Error: Could not find base commit${NC}"
56+
exit 1
57+
fi
58+
59+
echo "Base commit: ${BASE_COMMIT}"
60+
echo "Resetting vscode to base commit (before any patches)..."
61+
git reset --hard "${BASE_COMMIT}" > /dev/null 2>&1
62+
git clean -fd > /dev/null 2>&1
63+
64+
# Function to regenerate a single patch
65+
regenerate_patch() {
66+
local patch_file="$1"
67+
local patch_name=$(basename "$patch_file")
68+
local patch_dir=$(dirname "$patch_file")
69+
local relative_patch_path="${patch_file#${PATCHES_DIR}/}"
70+
71+
echo ""
72+
echo "Processing: ${relative_patch_path}"
73+
74+
# Reset to base commit for each patch
75+
git reset --hard "${BASE_COMMIT}" > /dev/null 2>&1
76+
git clean -fd > /dev/null 2>&1
77+
78+
# Create a temporary copy of the patch with placeholders replaced
79+
local temp_patch=$(mktemp)
80+
cp "$patch_file" "$temp_patch"
81+
82+
# Replace placeholders (same as apply_patch does)
83+
replace "s|!!APP_NAME!!|${APP_NAME}|g" "$temp_patch"
84+
replace "s|!!APP_NAME_LC!!|${APP_NAME_LC}|g" "$temp_patch"
85+
replace "s|!!BINARY_NAME!!|${BINARY_NAME}|g" "$temp_patch"
86+
replace "s|!!GH_REPO_PATH!!|${GH_REPO_PATH}|g" "$temp_patch"
87+
replace "s|!!ORG_NAME!!|${ORG_NAME}|g" "$temp_patch"
88+
replace "s|!!RELEASE_VERSION!!|${RELEASE_VERSION:-1.106.0}|g" "$temp_patch"
89+
90+
# Check if patch applies cleanly
91+
if git apply --check --ignore-whitespace "$temp_patch" 2>/dev/null; then
92+
# Apply the patch
93+
if git apply --ignore-whitespace "$temp_patch" 2>/dev/null; then
94+
# Get the diff
95+
local modified_files=$(git diff --name-only)
96+
97+
if [ -n "$modified_files" ]; then
98+
# Generate new patch (without placeholders, we'll add them back)
99+
git diff > "${temp_patch}.new"
100+
101+
# Restore placeholders in the new patch
102+
# Use escaped versions to avoid regex issues
103+
local escaped_app_name=$(echo "${APP_NAME}" | sed 's/[[\.*^$()+?{|]/\\&/g')
104+
local escaped_app_name_lc=$(echo "${APP_NAME_LC}" | sed 's/[[\.*^$()+?{|]/\\&/g')
105+
local escaped_binary_name=$(echo "${BINARY_NAME}" | sed 's/[[\.*^$()+?{|]/\\&/g')
106+
local escaped_gh_repo=$(echo "${GH_REPO_PATH}" | sed 's/[[\.*^$()+?{|]/\\&/g')
107+
local escaped_org_name=$(echo "${ORG_NAME}" | sed 's/[[\.*^$()+?{|]/\\&/g')
108+
109+
replace "s|${escaped_app_name}|!!APP_NAME!!|g" "${temp_patch}.new"
110+
replace "s|${escaped_app_name_lc}|!!APP_NAME_LC!!|g" "${temp_patch}.new"
111+
replace "s|${escaped_binary_name}|!!BINARY_NAME!!|g" "${temp_patch}.new"
112+
replace "s|${escaped_gh_repo}|!!GH_REPO_PATH!!|g" "${temp_patch}.new"
113+
replace "s|${escaped_org_name}|!!ORG_NAME!!|g" "${temp_patch}.new"
114+
if [ -n "${RELEASE_VERSION}" ]; then
115+
local escaped_release=$(echo "${RELEASE_VERSION}" | sed 's/[[\.*^$()+?{|]/\\&/g')
116+
replace "s|${escaped_release}|!!RELEASE_VERSION!!|g" "${temp_patch}.new"
117+
fi
118+
119+
# Test the new patch
120+
git reset --hard "${BASE_COMMIT}" > /dev/null 2>&1
121+
122+
# Create test temp patch with placeholders
123+
local test_temp=$(mktemp)
124+
cp "${temp_patch}.new" "$test_temp"
125+
replace "s|!!APP_NAME!!|${APP_NAME}|g" "$test_temp"
126+
replace "s|!!APP_NAME_LC!!|${APP_NAME_LC}|g" "$test_temp"
127+
replace "s|!!BINARY_NAME!!|${BINARY_NAME}|g" "$test_temp"
128+
replace "s|!!GH_REPO_PATH!!|${GH_REPO_PATH}|g" "$test_temp"
129+
replace "s|!!ORG_NAME!!|${ORG_NAME}|g" "$test_temp"
130+
replace "s|!!RELEASE_VERSION!!|${RELEASE_VERSION:-1.106.0}|g" "$test_temp"
131+
132+
if git apply --check --ignore-whitespace "$test_temp" 2>/dev/null; then
133+
mv "${temp_patch}.new" "$patch_file"
134+
echo -e " ${GREEN}✓ Regenerated successfully${NC}"
135+
rm -f "$temp_patch" "$test_temp"
136+
return 0
137+
else
138+
echo -e " ${RED}✗ New patch failed validation${NC}"
139+
rm -f "${temp_patch}.new" "$temp_patch" "$test_temp"
140+
return 1
141+
fi
142+
else
143+
echo -e " ${YELLOW}⚠ No changes detected${NC}"
144+
rm -f "$temp_patch"
145+
return 1
146+
fi
147+
else
148+
echo -e " ${RED}✗ Failed to apply patch${NC}"
149+
rm -f "$temp_patch"
150+
return 1
151+
fi
152+
else
153+
echo -e " ${YELLOW}⚠ Patch doesn't apply cleanly - needs manual fix${NC}"
154+
rm -f "$temp_patch"
155+
return 1
156+
fi
157+
}
158+
159+
# Collect results
160+
SUCCESS_COUNT=0
161+
FAIL_COUNT=0
162+
MANUAL_COUNT=0
163+
164+
# Regenerate main patches
165+
echo ""
166+
echo "=== Regenerating main patches ==="
167+
for patch_file in "${PATCHES_DIR}"/*.patch; do
168+
if [ -f "$patch_file" ]; then
169+
if regenerate_patch "$patch_file"; then
170+
((SUCCESS_COUNT++))
171+
else
172+
((FAIL_COUNT++))
173+
((MANUAL_COUNT++))
174+
fi
175+
fi
176+
done
177+
178+
# Regenerate insider patches
179+
if [ -d "${PATCHES_DIR}/insider" ]; then
180+
echo ""
181+
echo "=== Regenerating insider patches ==="
182+
for patch_file in "${PATCHES_DIR}/insider"/*.patch; do
183+
if [ -f "$patch_file" ]; then
184+
if regenerate_patch "$patch_file"; then
185+
((SUCCESS_COUNT++))
186+
else
187+
((FAIL_COUNT++))
188+
((MANUAL_COUNT++))
189+
fi
190+
fi
191+
done
192+
fi
193+
194+
# Regenerate OS-specific patches
195+
for os in alpine linux osx windows; do
196+
if [ -d "${PATCHES_DIR}/${os}" ]; then
197+
echo ""
198+
echo "=== Regenerating ${os} patches ==="
199+
# Find all .patch files recursively
200+
while IFS= read -r -d '' patch_file; do
201+
if regenerate_patch "$patch_file"; then
202+
((SUCCESS_COUNT++))
203+
else
204+
((FAIL_COUNT++))
205+
((MANUAL_COUNT++))
206+
fi
207+
done < <(find "${PATCHES_DIR}/${os}" -name "*.patch" -type f -print0)
208+
fi
209+
done
210+
211+
# Final summary
212+
echo ""
213+
echo "============================================================"
214+
echo "Summary:"
215+
echo " ${GREEN}Successfully regenerated: ${SUCCESS_COUNT}${NC}"
216+
echo " ${YELLOW}Need manual attention: ${MANUAL_COUNT}${NC}"
217+
echo "============================================================"
218+
219+
# Reset vscode to base commit
220+
git reset --hard "${BASE_COMMIT}" > /dev/null 2>&1
221+
git clean -fd > /dev/null 2>&1
222+
223+
exit 0
224+

0 commit comments

Comments
 (0)