forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-msys2.sh
executable file
·243 lines (219 loc) · 5.71 KB
/
commit-msys2.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/sh
# To help Continuous Integration, this script commits the files installed via
# MSYS2 packages into the Git for Windows SDK. The resulting repository can be
# easily cloned and cached by build agents.
die () {
echo "$*" >&2
exit 1
}
root="$(cd "$(dirname "$0")/../../.." && pwd)" ||
die "Could not determine root directory"
root_gitdir="$(git -C "$root" rev-parse --absolute-git-dir)" &&
test -d "$root_gitdir" ||
die "Could not determine root gitdir"
list_packages () {
(cd "${root%/}"/var/lib/pacman/local &&
# order by ctime
ls -rtc | grep -v ALPM_DB_VERSION)
}
commit_package () {
(cd "$root" ||
die "Could not cd to $root"
git update-index -q --refresh &&
git diff-index --cached --quiet HEAD -- ||
die "There are uncommitted changes in $root"
package="$(echo var/cache/pacman/pkg/"$1"*.pkg.tar.xz)"
test -f "$package" || die "Could not find the package of $1"
if git rev-parse -q --verify refs/heads/import-tars >/dev/null
then
git branch -D import-tars
fi &&
"$import_tars" "$package" &&
git ls-tree -r import-tars |
sed -n 's/^\([0-9]* \)blob \([0-9a-f]*\)\(\t[^.].*\)/\1\2\3/p' |
git update-index --index-info &&
git add "${root%/}"/var/lib/pacman/local/"$1" &&
git commit -s -m "$1" ||
die "Could not commit $1") ||
exit
}
generate_package_gitignore () {
dir="$(cd "${root%/}"/var/lib/pacman/local/ &&
case "$1" in
mingw-w64-x86_64-libusb-compat-git)
echo "$1"-r[0-9]*
;;
*)
echo "$1"-[0-9]*
;;
esac)" &&
case "$dir" in
*' '*)
die "Multiple packages: $dir"
;;
'')
die "$1: not installed?"
;;
*)
test -d "${root%/}/var/lib/pacman/local/$dir" || {
test -n "$2" ||
die "$1: not installed?"
return
}
printf '\n# Package: %s\n%s\n' \
"$dir" "/var/lib/pacman/local/$dir/" &&
sed -n 's|^[^%].*[^/]$|/&|p' \
"${root%/}/var/lib/pacman/local/$dir/files"
;;
esac
}
summarize_commit () {
test $# -le 1 ||
die "summarize_commit: too many arguments ($*)"
if test -z "$1"
then
git diff --cached -M50 --raw -- var/lib/pacman/local/\*/desc
else
git show "$1" --format=%H \
-M15 --raw -- var/lib/pacman/local/\*/desc
fi |
sed -ne '/.* M\tvar\/lib\/pacman\/local\/\(mingw-w64-.*-\)\?git-extra-[1-9].*\/desc$/d' \
-e '/ R[0-9]*\t/{s/-\([0-9]\)/ (\1/;h;s|-\([0-9][^/]*\)/desc$|\t\1)|;s|.*\t| -> |;x;s|/desc\t.*||;s|.*\t[^\t]*/||;G;s|\n||g;p}' \
-e '/ A\t/{s|.*local/\([^/]*\)/desc|\1|;s|-\([0-9].*\)| (new: \1)|p}' \
-e '/ D\t/{s|.*local/\([^/]*\)/desc|\1|;s|-\([0-9].*\)| (removed)|p}'
}
case "$1" in
init)
import_tars="${root%/}"/usr/src/git/contrib/fast-import/import-tars.perl
test -x "$import_tars" ||
die "You need to run this script in a Git for Windows SDK"
if test ! -d "$root_gitdir"
then
(cd "$root" && git init) ||
die "Could not initialize Git repository"
fi
if test false != "$(git -C "$root" config core.autocrlf)"
then
git -C "$root" config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi
for package in $(list_packages)
do
commit_package $package || exit
done
(cd "$root" &&
git add var/lib/pacman/sync &&
git commit -s -m "Pacman package index") ||
die "Could not conclude initial commits"
;;
add|remove)
action=$1 &&
shift &&
if test add = "$action"
then
pacman_option=-Syy &&
commit_title_prefix="Add"
else
pacman_option=-R &&
commit_title_prefix="Remove"
fi &&
(cd "$root" &&
if test false != "$(git config core.autocrlf)"
then
git config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi &&
packages="$(for package; do
case "$package" in
mingw-w64-i686-*|mingw-w64-x86_64-*) echo "$package";;
mingw-w64-*)
(
cd /var/lib/pacman/local &&
ls -d mingw-w64-*-"${package#mingw-w64-}"-[0-9]* |
sed 's|-[0-9].*||'
)
;;
*) echo "$package";;
esac; done)" &&
pacman $pacman_option --noconfirm $packages &&
git add -A . ||
die "Could not $action $*"
git diff-index --exit-code --cached HEAD ||
git commit -q -s -m "$commit_title_prefix $*") ||
die "Could not commit changes"
;;
summary)
shift
summarize_commit "$@"
;;
commit)
(cd "$root" &&
if test false != "$(git config core.autocrlf)"
then
git config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi &&
git add -A . &&
if git diff-index --exit-code --cached HEAD -- \
':(exclude)var/lib/pacman/sync/' \
':(exclude)var/lib/pacman/local/git-extra-*/desc' \
':(exclude)var/lib/pacman/local/mingw-w64-*-git-extra-*/desc' \
':(exclude)etc/rebase.db*'
then
# No changes, really, but maybe a new Pacman db
git reset --hard
else
summary="$(summarize_commit)"
count=$(echo "$summary" | wc -l) &&
if test $count -lt 2
then
oneline="Update $count package"
else
oneline="Update $count packages"
fi &&
git commit -q -s -m "$oneline" -m "$summary"
fi) ||
die "Could not commit changes"
;;
ignore)
shift
remove_uninstalled=
case "$*" in
-a|--all)
set -- $( (
git -C "${root%/}"/ ls-files --exclude-standard \
--other var/lib/pacman/local/ |
sed -n 's|^var/lib/pacman/local/\([^/]*\)-r\?[0-9][-0-9a-z_.]*-[1-9][0-9]*/.*|\1|p';
sed -n 's|^# Package: \(.*\)-r\?[0-9][-0-9a-z_.]*-[1-9][0-9]*|\1|p' \
<"${root%/}/.git/info/exclude"
) | sort | uniq
)
remove_uninstalled=t
;;
esac
mkdir -p "$root_gitdir"/info &&
touch "$root_gitdir"/info/exclude ||
die "Could not ensure that .git/info/exclude exists"
for pkg
do
# Remove existing entries, if any
sed -i '/^$/{
:1
N
/^\n# \(Package: \)\?'$pkg'\(-[0-9][^-]*-[0-9][0-9]*\)\?$/{
:2
N
s/.*\n//
/./b2
b1
}
}' "$root_gitdir"/info/exclude &&
generate_package_gitignore "$pkg" $remove_uninstalled \
>>"$root_gitdir"/info/exclude ||
die "Could not ignore $pkg"
done
;;
*)
die "Unknown command: $1"
;;
esac