Skip to content

Commit 0976d8e

Browse files
committed
Merge branch 'git-sdk'
This enhances the `sdk` shell function we want to promote as the main way to Do Things In The SDK by introducing the `cd` subcommand to initialize and switch to a given project, by improving the help, by adding the `git-extra` project to the known projects, and by adding support for Tab completion (in the Git SDK Bash). It also updates the SDK installer to initialize a shallow clone of the Git mirror of the SDK instead of "Pacman'ing everything from scratch". Signed-off-by: Johannes Schindelin <[email protected]>
2 parents e826d31 + d1a55d3 commit 0976d8e

File tree

5 files changed

+125
-241
lines changed

5 files changed

+125
-241
lines changed

git-extra/PKGBUILD

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ source=('inputrc'
4242
'gitattributes'
4343
'astextplain'
4444
'git-sdk.sh'
45+
'sdk.completion'
4546
'git-update-git-for-windows'
4647
'git-update'
4748
'blocked-file-util.c'
@@ -96,6 +97,7 @@ build() {
9697
package() {
9798
builddir=build-${MINGW_CHOST}
9899
install -d -m755 $pkgdir/etc/profile.d
100+
install -d -m755 $pkgdir/usr/share/bash-completion/completions
99101
install -d -m755 $pkgdir/etc/post-install
100102
install -d -m755 $pkgdir/usr/bin
101103
install -d -m755 $pkgdir/usr/share/git
@@ -118,6 +120,7 @@ package() {
118120
install -m755 env.sh $pkgdir/etc/profile.d
119121
install -m755 bash_profile.sh $pkgdir/etc/profile.d
120122
install -m755 git-sdk.sh $pkgdir/etc/profile.d
123+
install -m755 sdk.completion $pkgdir/usr/share/bash-completion/completions/sdk
121124
install -m644 msys2-32.ico $pkgdir/usr/share/git
122125
install -m644 99-post-install-cleanup.post $pkgdir/etc/post-install
123126
install -m755 astextplain $pkgdir/usr/bin

git-extra/git-sdk.sh

+41-16
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ sdk () {
2626
The 'sdk' shell function helps you to get up and running
2727
with the Git for Windows SDK. The available subcommands are:
2828
29-
create-desktop-icon: install a desktop icon that starts the GfW SDK shell.
29+
create-desktop-icon: install a desktop icon that starts the Git for
30+
Windows SDK Bash.
3031
31-
init <repo>: initialize and/or update a development repo. Known repos
32-
are: build-extra, git, MINGW-packages, MSYS2-packages.
32+
cd <project>: initialize/update a worktree and cd into it. Known projects
33+
are: git, git-extra, build-extra, MINGW-packages, MSYS2-packages.
3334
34-
build: builds one of the following: git, git-and-installer.
35+
init <project>: initialize and/or update a worktree. Known projects
36+
are the same as for the 'cd' command.
37+
38+
build <project>: builds one of the following: git, git-and-installer.
3539
EOF
3640
;;
3741
welcome)
@@ -67,42 +71,62 @@ sdk () {
6771
echo "$*" >&2
6872
return 1
6973
;;
74+
# for completion
75+
valid_commands)
76+
echo "build cd create-desktop-icon init"
77+
;;
78+
valid_projects)
79+
echo "build-extra git git-extra MINGW-packages MSYS2-packages"
80+
;;
81+
# here start the commands
7082
init-lazy)
7183
case "$2" in
7284
build-extra|git|MINGW-packages|MSYS2-packages)
73-
test -d /usr/src/"$2"/.git && return
74-
mkdir -p /usr/src/"$2" &&
75-
git -C /usr/src/"$2" init &&
76-
git -C /usr/src/"$2" config core.autocrlf false &&
77-
git -C /usr/src/"$2" remote add origin \
85+
src_dir=/usr/src/"$2"
86+
src_cdup_dir="$src_dir"
87+
test -d "$src_dir"/.git && return
88+
mkdir -p "$src_dir" &&
89+
git -C "$src_dir" init &&
90+
git -C "$src_dir" config core.autocrlf false &&
91+
git -C "$src_dir" remote add origin \
7892
https://github.com/git-for-windows/"$2" ||
79-
sdk die "Could not initialize /usr/src/$2"
93+
sdk die "Could not initialize $src_dir"
94+
;;
95+
git-extra)
96+
sdk init-lazy build-extra &&
97+
src_dir="$src_dir/$2" ||
98+
return 1
8099
;;
81100
*)
82101
sdk die "Unhandled repository: $2" >&2
83102
;;
84103
esac
85104
;;
105+
cd)
106+
sdk init "$2" &&
107+
cd "$src_dir" ||
108+
sdk die "Could not change directory to '$2'"
109+
;;
86110
init)
87111
sdk init-lazy "$2" &&
88-
git -C "/usr/src/$2" pull origin master
112+
git -C "$src_cdup_dir" pull origin master
89113
;;
90114
build)
91115
case "$2" in
92116
git)
93117
sdk init git &&
94-
make -C /usr/src/git -j$(nproc) DEVELOPER=1
118+
make -C "$src_dir" -j$(nproc) DEVELOPER=1
95119
;;
96120
installer)
97121
sdk init build-extra &&
98-
/usr/src/build-extra/installer/release.sh "${3:-0-test}"
122+
"$src_dir"/installer/release.sh "${3:-0-test}"
99123
;;
100124
git-and-installer)
101125
sdk build git &&
102-
make -C /usr/src/git strip install &&
126+
make -C "$src_dir" strip install &&
103127
pacman -Syyu git-extra &&
104128
sdk init build-extra &&
105-
/usr/src/build-extra/installer/release.sh "${3:-0-test}"
129+
"$src_dir"/installer/release.sh "${3:-0-test}"
106130
;;
107131
*)
108132
cat >&2 <<EOF
@@ -118,7 +142,8 @@ EOF
118142
esac
119143
;;
120144
*)
121-
sdk die "Usage: sdk ( build-git | init <repo> | create-desktop-icon | help )"
145+
printf "Usage: sdk <command> [<argument>...]\n\n" >&2 &&
146+
sdk help
122147
;;
123148
esac
124149
}

git-extra/sdk.completion

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
_sdk()
2+
{
3+
local cur prev opts
4+
COMPREPLY=()
5+
cur="${COMP_WORDS[COMP_CWORD]}"
6+
prev="${COMP_WORDS[COMP_CWORD-1]}"
7+
8+
case "$prev" in
9+
build|cd|init)
10+
local projects=$(sdk valid_projects)
11+
COMPREPLY=($(compgen -W "$projects" -- $cur))
12+
return 0
13+
;;
14+
create-desktop-icon)
15+
return 1
16+
;;
17+
esac
18+
19+
opts=$(sdk valid_commands)
20+
COMPREPLY=($(compgen -W "$opts" -- $cur))
21+
return 0
22+
}
23+
complete -F _sdk sdk

sdk-installer/release.sh

+34-51
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Recreate git-sdk-$VERSION.exe
44

55
test -z "$1" && {
6-
echo "Usage: $0 <version> [<gitbranch>]"
6+
echo "Usage: $0 <version>"
77
exit 1
88
}
99

@@ -25,75 +25,58 @@ x86_64)
2525
;;
2626
esac
2727

28-
GIT_BRANCH="${2:-master}"
29-
GIT_CLONE_URL=https://github.com/git-for-windows/git
28+
GIT_SDK_URL=https://github.com/git-for-windows/git-sdk-$BITNESS
3029

3130
FAKEROOTDIR="$(cd "$(dirname "$0")" && pwd)/root"
3231
TARGET="$HOME"/git-sdk-installer-"$1"-$BITNESS.7z.exe
3332
OPTS7="-m0=lzma -mx=9 -md=64M"
3433
TMPPACK=/tmp.7z
3534
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
35+
BIN_DIR=/mingw$BITNESS/bin
3636

37-
mkdir -p "$FAKEROOTDIR/usr/bin" "$FAKEROOTDIR/etc" ||
38-
die "Could not create fake root directory"
37+
echo "Enumerating required files..." >&2
38+
# First, enumerate the .dll files needed by the .exe files, then, enumerate all
39+
# the .dll files in bin/, then filter out the duplicates (which are the .dll
40+
# files in bin/ which are needed by the .exe files).
41+
exes_and_dlls=
42+
todo="git.exe ../libexec/git-core/git-remote-https.exe "
43+
# Add DLLs' transitive dependencies
44+
while test -n "$todo"
45+
do
46+
file=${todo%% *}
47+
todo=${todo#* }
48+
exes_and_dlls="$exes_and_dlls$file "
49+
50+
for dll in $(objdump -p "$BIN_DIR/$file" |
51+
sed -n "s|^\tDLL Name: ||p")
52+
do
53+
case " $exes_and_dlls $todo " in
54+
*" $dll "*) ;; # already found/queued
55+
*) test ! -f "$BIN_DIR/$dll" || todo="$todo$dll ";;
56+
esac
57+
done
58+
done
59+
60+
echo "Copying and compressing files..." >&2
61+
rm -rf "$FAKEROOTDIR" &&
62+
mkdir -p "$FAKEROOTDIR/mini$BIN_DIR" ||
63+
die "Could not create $FAKEROOTDIR$BIN_DIR directory"
3964

4065
sed -e "s|@@ARCH@@|$ARCH|g" \
4166
-e "s|@@BITNESS@@|$BITNESS|g" \
42-
-e "s|@@GIT_BRANCH@@|$GIT_BRANCH|g" \
43-
-e "s|@@GIT_CLONE_URL@@|$GIT_CLONE_URL|g" \
67+
-e "s|@@GIT_SDK_URL@@|$GIT_SDK_URL|g" \
4468
<"$SCRIPT_PATH"/setup-git-sdk.bat >"$FAKEROOTDIR"/setup-git-sdk.bat ||
4569
die "Could not generate setup script"
4670

47-
cp /usr/bin/dash.exe "$FAKEROOTDIR/usr/bin/sh.exe" &&
48-
sed -e 's/^#\(XferCommand.*curl\).*/\1 --anyauth -C - -L -f %u >%o/' \
49-
</etc/pacman.conf >"$FAKEROOTDIR/etc/pacman.conf.proxy" ||
50-
die "Could not copy extra files into fake root"
51-
52-
dlls_for_exes () {
53-
# Add DLLs' transitive dependencies
54-
dlls=
55-
todo="$* "
56-
while test -n "$todo"
57-
do
58-
path=${todo%% *}
59-
todo=${todo#* }
60-
case "$path" in ''|' ') continue;; esac
61-
for dll in $(objdump -p "$path" |
62-
sed -n 's/^\tDLL Name: msys-/usr\/bin\/msys-/p')
63-
do
64-
case "$dlls" in
65-
*"$dll"*) ;; # already found
66-
*) dlls="$dlls $dll"; todo="$todo /$dll ";;
67-
esac
68-
done
69-
done
70-
echo "$dlls"
71-
}
72-
73-
fileList="etc/nsswitch.conf \
74-
etc/pacman.conf \
75-
etc/pacman.d \
76-
usr/bin/pacman-key \
77-
usr/bin/tput.exe \
78-
usr/bin/pacman.exe \
79-
usr/bin/curl.exe \
80-
usr/bin/gpg.exe \
81-
usr/bin/chmod.exe \
82-
usr/bin/wc.exe \
83-
usr/bin/find.exe \
84-
$(dlls_for_exes /usr/bin/gpg.exe /usr/bin/curl.exe /usr/bin/chmod.exe \
85-
/usr/bin/wc.exe /usr/bin/find.exe) \
86-
usr/ssl/certs/ca-bundle.crt \
87-
var/lib/pacman \
88-
usr/share/pacman/keyrings \
89-
$FAKEROOTDIR/setup-git-sdk.bat $FAKEROOTDIR/etc $FAKEROOTDIR/usr"
71+
(cd $BIN_DIR && cp $exes_and_dlls "$FAKEROOTDIR/mini$BIN_DIR") ||
72+
die "Could not copy .exe and .dll files into fake root"
9073

9174
type 7za ||
9275
pacman -Sy --noconfirm p7zip ||
9376
die "Could not install 7-Zip"
9477

9578
echo "Creating archive" &&
96-
(cd / && 7za -x'!var/lib/pacman/*' a $OPTS7 "$TMPPACK" $fileList) &&
79+
(cd "$FAKEROOTDIR" && 7za -x'!var/lib/pacman/*' a $OPTS7 "$TMPPACK" *) &&
9780
(cat "$SCRIPT_PATH/../7-Zip/7zSD.sfx" &&
9881
echo ';!@Install@!UTF-8!' &&
9982
echo 'Title="Git for Windows '$BITNESS'-bit SDK"' &&

0 commit comments

Comments
 (0)