forked from apache/brpc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch_from_baidu
executable file
·84 lines (81 loc) · 3.33 KB
/
patch_from_baidu
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
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage1: patch_from_baidu PATCHFILE (generated by 'git diff --no-prefix')"
echo "Usage2: patch_from_baidu GIT_DIR COMMIT"
exit 1
fi
PATCHFILE=$1
if [ -d "$1/.git" ]; then
if [ -z "$2" ]; then
echo "Second argument must be a git commit"
exit 1
fi
CURRENT_DIR=`pwd`
GIT_DIR=$1
COMMIT=$2
PATCHFILE=$CURRENT_DIR/$COMMIT.patch
echo "*** Generating diff of $GIT_DIR@$COMMIT"
cd $GIT_DIR && git diff --no-prefix $COMMIT^! > $PATCHFILE
cd $CURRENT_DIR
fi
MODIFIED_PATCHFILE=$(basename $(basename $PATCHFILE .patch) .diff).from_baidu.patch
# guess prefix of test files
TEST_PREFIX="test_"
TEST_SUFFIX=
if fgrep -q " src/baidu/rpc/" $PATCHFILE; then
TEST_PREFIX="brpc_"
TEST_SUFFIX="_unittest"
elif fgrep -q " bthread/" $PATCHFILE; then
TEST_PREFIX="bthread_"
TEST_SUFFIX="_unittest"
elif fgrep -q " bvar/" $PATCHFILE; then
TEST_PREFIX="bvar_"
TEST_SUFFIX="_unittest"
fi
cat $PATCHFILE | sed -e 's/src\/baidu\/rpc\//src\/brpc\//g' \
-e 's/\<baidu\/rpc\//brpc\//g' \
-e 's/\<baidu\-rpc\([^-]\)/brpc\1/g' \
-e 's/\<test\/test_bthread\.cpp/test\/bthread_unittest.cpp/g' \
-e 's/\<test\/test_object_pool\.cpp/test\/object_pool_unittest.cpp/g' \
-e 's/\<test\/test_resource_pool\.cpp/test\/resource_pool_unittest.cpp/g' \
-e "s/\<test\/test_\(\S*\)\.cpp/test\/${TEST_PREFIX}\1${TEST_SUFFIX}.cpp/g" \
-e 's/\<namespace \+baidu *{/namespace brpc {/g' \
-e 's/\<namespace \+rpc *{//g' \
-e 's/} *\/\/ \+namespace \+baidu/} \/\/ namespace brpc/g' \
-e 's/} *\/\/ \+namespace \+rpc\>//g' \
-e 's/\<baidu::rpc::/brpc::/g' \
-e 's/\<rpc::/brpc::/g' \
-e 's/\<base::/butil::/g' \
-e 's/\<BAIDU_RPC_/BRPC_/g' \
-e 's/\<protocol\/\(\S*\)\.proto/src\/\1.proto/g' \
-e 's/ bthread_cond\.cpp/ src\/bthread\/condition_variable.cpp/g' \
-e 's/ bthread_\([^.]*\)\.cpp/ src\/bthread\/\1.cpp/g' \
-e 's/ bthread_\([^.]*\)\.h/ src\/bthread\/\1.h/g' \
-e 's/ bthread\.\(h\|cpp\)/ src\/bthread\/bthread.\1/g' \
-e 's/<\(brpc\/[^>]*\)>/"\1"/g' \
-e 's/<\(bvar\/[^>]*\)>/"\1"/g' \
-e 's/<base\/\([^>]*\)>/"butil\/\1"/g' \
-e 's/"base\/\([^"]*\)"/"butil\/\1"/g' \
-e 's/<\(bthread\/[^>]*\)>/"\1"/g' \
-e 's/<\(mcpack2pb\/[^>]*\)>/"\1"/g' \
-e 's/\<protobuf_json\>/json2pb/g' \
-e 's/src\/json_to_pb/src\/json2pb\/json_to_pb/g' \
-e 's/src\/pb_to_json/src\/json2pb\/pb_to_json/g' \
-e 's/test\/test_protobuf_json/test\/brpc_protobuf_json_unittest/g' \
-e 's/ base\// src\/butil\//g' \
-e 's/ bthread\// src\/bthread\//g' \
-e 's/ bvar\// src\/bvar\//g' \
> $MODIFIED_PATCHFILE
EXTRA_ARGS=
if [ -z "$DO_RUN" ]; then
EXTRA_ARGS="--dry-run $EXTRA_ARGS"
echo "*** This is a dry-run. To really apply, run: DO_RUN=1 tools/patch_from_baidu $1"
fi
patch -p0 -u -l $EXTRA_ARGS < $MODIFIED_PATCHFILE
if [ ! -z "$DO_RUN" ]; then
REJ_FILES=`find . -name "*.rej"`
if [ ! -z "$REJ_FILES" ]; then
echo "==== The patching is not done yet! Apply following rej files manually ===="
echo $REJ_FILES
fi
fi