Skip to content

Commit f0f7f97

Browse files
committed
Add a simple script for downstream maintenance
1 parent 79d8c8e commit f0f7f97

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

scripts/git-migrate.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/bash
2+
3+
function confirmation() {
4+
read -p "$1 (y/n)" -n 1 -r
5+
echo
6+
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
7+
exit 1
8+
fi
9+
}
10+
11+
if [[ $# -eq 0 ]]; then
12+
echo "Usage: $0 commit commit commit ..."
13+
exit 1
14+
fi
15+
16+
GIT_ROOT="$(basename $(git rev-parse --show-toplevel))"
17+
if [[ "$GIT_ROOT" =~ (openssl|nss|gnutls) ]]; then
18+
GIT_TYPE="downstream"
19+
else
20+
GIT_TYPE="upstream"
21+
fi
22+
23+
echo -e "git root directory is '$GIT_ROOT' which is \e[1m$GIT_TYPE\e[0m"
24+
confirmation "Is this information correct?"
25+
if [[ "$GIT_TYPE" == "downstream" ]]; then
26+
echo "This directory will be used as a component name for a path substitution"
27+
confirmation "Is this setup OK?"
28+
fi
29+
30+
echo "Requested patches for following commits:"
31+
git show -s --oneline $@
32+
33+
echo "-------------------"
34+
35+
for commit in "$@"; do
36+
echo "Generating patch for $commit"
37+
patch="$(git format-patch -1 $commit)"
38+
if [[ $? -eq 0 && -n $patch ]]; then
39+
tmpfile="$(mktemp)"
40+
mv "$patch" "$tmpfile"
41+
awk -v dstr_comp="$GIT_ROOT" '
42+
function bold(text) {
43+
return "\033[1m" text "\033[0m";
44+
}
45+
function green(text) {
46+
return "\033[32m" text "\033[39m";
47+
}
48+
function red(text) {
49+
return "\033[31m" text "\033[39m";
50+
}
51+
52+
# Match diff paths, eg.:
53+
# --- a/openssl/Interoperability/CC-openssl-with-gnutls/runtest.sh
54+
# +++ b/openssl/Interoperability/CC-openssl-with-gnutls/runtest.sh
55+
match($0, /^[+-]{3} [ab]\/([^\/]+)\/.+$/, m) {
56+
if(m[1] ~ /(openssl|nss|gnutls)/) {
57+
# First path component is a component name => upstream repo
58+
# Supported components: openssl, nss, gnutls
59+
print "Found an " bold("upstream") " path: " green($0) > "/dev/stderr"
60+
# Remove the component name from the path
61+
$0 = gensub(/^([+-]{3} [ab])\/[^\/]+(\/.+)$/,
62+
"\\1\\2", 1, $0);
63+
print "Rewriting this path to: " red($0) > "/dev/stderr"
64+
} else if(m[1] ~ /(Interoperability)/) {
65+
# First path component is a test type => downstream repo
66+
# Supported test types: Interoperability
67+
print "Found a " bold("downstream") " path: " green($0) > "/dev/stderr"
68+
# Prepend the component name to the path
69+
$0 = gensub(/^([+-]{3} [ab]\/)([^\/]+\/.+)$/,
70+
"\\1" dstr_comp "/\\2", 1, $0);
71+
print "Rewriting this path to: " red($0)> "/dev/stderr"
72+
}
73+
}
74+
{
75+
print $0;
76+
}
77+
' "$tmpfile" > "$patch"
78+
echo "Patch saved as $patch"
79+
rm "$tmpfile"
80+
else
81+
echo >&2 "git format-patch failed: ($patch)"
82+
fi
83+
done

0 commit comments

Comments
 (0)