-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathvendor-one.sh
executable file
·106 lines (80 loc) · 2.59 KB
/
vendor-one.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# https://unix.stackexchange.com/a/654932/19205
# Using bash for -o pipefail
set -e
set -x
set -o pipefail
cd `dirname $0`
project=duckdb
vendor_base_dir=src/duckdb
vendor_dir=${vendor_base_dir}
repo_org=${project}
repo_name=${project}
if [ -z "$1" ]; then
upstream_basedir=../../${project}
else
upstream_basedir="$1"
fi
upstream_dir=.git/${project}
if [ "$upstream_basedir" != "$upstream_dir" ]; then
git clone "$upstream_basedir" "$upstream_dir"
fi
if [ -n "$(git status --porcelain)" ]; then
echo "Error: working directory not clean"
exit 1
fi
if [ -n "$(git -C "$upstream_dir" status --porcelain)" ]; then
echo "Warning: working directory $upstream_dir not clean"
fi
base=$(git log -n 3 --format="%s" -- ${vendor_dir} | tee /dev/stderr | sed -nr '/^.*'${repo_org}.${repo_name}'@([0-9a-f]+)( .*)?$/{s//\1/;p;}' | head -n 1)
original=$(git -C "$upstream_dir" log --first-parent --reverse --format="%H" ${base}..HEAD)
message=
is_tag=
for commit in $original; do
echo "Importing commit $commit"
git -C "$upstream_dir" checkout "$commit"
rm -rf ${vendor_dir}
echo "R: configure"
DUCKDB_PATH="$upstream_dir" python3 rconfigure.py
for f in patch/*.patch; do
if patch -i $f -p1 --forward --dry-run; then
patch -i $f -p1 --forward --no-backup-if-mismatch
else
echo "Removing patch $f"
rm $f
fi
done
# Always vendor tags
if [ $(git -C "$upstream_dir" describe --tags "$commit" | grep -c -- -) -eq 0 ]; then
message="vendor: Update vendored sources (tag $(git -C "$upstream_dir" describe --tags "$commit")) to ${repo_org}/${repo_name}@$commit"
is_tag=true
break
fi
if [ $(git status --porcelain -- ${vendor_base_dir} | wc -l) -gt 1 ]; then
message="vendor: Update vendored sources to ${repo_org}/${repo_name}@$commit"
break
fi
done
if [ "$message" = "" ]; then
echo "No changes."
git checkout -- ${vendor_base_dir}
rm -rf "$upstream_dir"
exit 0
fi
our_tag=$(git describe --tags --abbrev=0 | sed -r 's/-[0-9]$//')
upstream_tag=$(git -C "$upstream_dir" describe --tags --abbrev=0)
echo "Our tag: $our_tag"
echo "Upstream tag: $upstream_tag"
if [ -z "${is_tag}" -a "${our_tag#$upstream_tag}" == "$our_tag" ]; then
echo "Not vendoring because our tag $our_tag does not start with upstream tag $upstream_tag"
git checkout -- ${vendor_base_dir}
rm -rf "$upstream_dir"
exit 0
fi
git add .
(
echo "$message"
echo
git -C "$upstream_dir" log --first-parent --format="%s" ${base}..${commit} | tee /dev/stderr | sed -r 's%(#[0-9]+)%'${repo_org}/${repo_name}'\1%g'
) | git commit --file /dev/stdin
rm -rf "$upstream_dir"