Skip to content

Commit d228605

Browse files
author
Mandeep Singh Grang
committed
Add script to cherry pick patches to monorepo
1 parent 39e15ef commit d228605

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# Note: Do the following before running this script:
4+
# 1. Checkout your old clang master branch (say <somedir>/llvm/tools/clang). Call this SRCDIR.
5+
# 2. Checkout the new monorepo (say <somedir>/src. Call this TGTDIR.
6+
# 3. cd $SRCDIR
7+
# 4. git log --pretty=oneline --format=%H > patchlist
8+
# 5. for i in `cat patchlist`; do git diff ${i}~1 ${i} > ${i}.patch; done
9+
10+
SRCDIR=<>
11+
TGTDIR=<>
12+
PROJ=clang
13+
PATCHLIST=$SRCDIR/patchlist
14+
15+
if [[ ! -f $PATCHLIST ]]; then
16+
echo "error: $PATCHLIST not found."
17+
exit 1
18+
fi
19+
20+
SHA=`tail -n1 $PATCHLIST`
21+
if [[ ! -f "${SRCDIR}/${SHA}.patch" ]]; then
22+
echo "error: ${SHA}.patch not found."
23+
exit 1
24+
fi
25+
26+
cd $SRCDIR
27+
COMMIT_TITLE="`git log -n 1 --pretty=oneline --format=%s $SHA`"
28+
COMMIT_MSG="`git log -n 1 --pretty=full $SHA`"
29+
30+
cd $TGTDIR
31+
echo "Applying patch $SHA ..."
32+
33+
patch -p1 --directory=$TGTDIR/$PROJ < $SRCDIR/${SHA}.patch
34+
if [[ $? -ne 0 ]]; then
35+
echo "error: Patch $SHA failed to apply cleanly."
36+
exit 1
37+
fi
38+
39+
git add $PROJ && git commit -m "${COMMIT_TITLE}
40+
41+
Cherry-picked from ${COMMIT_MSG}"
42+
43+
if [[ $? -ne 0 ]]; then
44+
echo "error: Cherry-pick failed."
45+
exit 1
46+
fi
47+
48+
echo "Successfully applied patch $SHA"
49+
50+
sed -i '$ d' $PATCHLIST
51+
rm -rf ${SRCDIR}/${SHA}.patch
52+
53+
echo "Patches remaining: `wc -l $PATCHLIST | cut -f1 -d' '`"

0 commit comments

Comments
 (0)