Skip to content

Commit ae9168d

Browse files
committed
Merge branch 'busybox-w32'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 7602fc0 + 62cb5ce commit ae9168d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+367
-120
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.pm text eol=lf diff=perl
77
*.py text eol=lf diff=python
88
*.bat text eol=crlf
9+
*.png binary
910
CODE_OF_CONDUCT.md -whitespace
1011
/Documentation/**/*.txt text eol=lf
1112
/command-list.txt text eol=lf

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ TEST_BUILTINS_OBJS += test-hash-speed.o
814814
TEST_BUILTINS_OBJS += test-hash.o
815815
TEST_BUILTINS_OBJS += test-hashmap.o
816816
TEST_BUILTINS_OBJS += test-hexdump.o
817+
TEST_BUILTINS_OBJS += test-iconv.o
817818
TEST_BUILTINS_OBJS += test-json-writer.o
818819
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
819820
TEST_BUILTINS_OBJS += test-match-trees.o

compat/mingw.c

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "../repository.h"
2424
#include "win32/fscache.h"
2525
#include "../attr.h"
26+
#include "../string-list.h"
2627

2728
#define HCAST(type, handle) ((type)(intptr_t)handle)
2829

@@ -1651,6 +1652,65 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
16511652
return NULL;
16521653
}
16531654

1655+
static char *path_lookup(const char *cmd, int exe_only);
1656+
1657+
static char *is_busybox_applet(const char *cmd)
1658+
{
1659+
static struct string_list applets = STRING_LIST_INIT_DUP;
1660+
static char *busybox_path;
1661+
static int busybox_path_initialized;
1662+
1663+
/* Avoid infinite loop */
1664+
if (!strncasecmp(cmd, "busybox", 7) &&
1665+
(!cmd[7] || !strcasecmp(cmd + 7, ".exe")))
1666+
return NULL;
1667+
1668+
if (!busybox_path_initialized) {
1669+
busybox_path = path_lookup("busybox.exe", 1);
1670+
busybox_path_initialized = 1;
1671+
}
1672+
1673+
/* Assume that sh is compiled in... */
1674+
if (!busybox_path || !strcasecmp(cmd, "sh"))
1675+
return xstrdup_or_null(busybox_path);
1676+
1677+
if (!applets.nr) {
1678+
struct child_process cp = CHILD_PROCESS_INIT;
1679+
struct strbuf buf = STRBUF_INIT;
1680+
char *p;
1681+
1682+
strvec_pushl(&cp.args, busybox_path, "--help", NULL);
1683+
1684+
if (capture_command(&cp, &buf, 2048)) {
1685+
string_list_append(&applets, "");
1686+
return NULL;
1687+
}
1688+
1689+
/* parse output */
1690+
p = strstr(buf.buf, "Currently defined functions:\n");
1691+
if (!p) {
1692+
warning("Could not parse output of busybox --help");
1693+
string_list_append(&applets, "");
1694+
return NULL;
1695+
}
1696+
p = strchrnul(p, '\n');
1697+
for (;;) {
1698+
size_t len;
1699+
1700+
p += strspn(p, "\n\t ,");
1701+
len = strcspn(p, "\n\t ,");
1702+
if (!len)
1703+
break;
1704+
p[len] = '\0';
1705+
string_list_insert(&applets, p);
1706+
p = p + len + 1;
1707+
}
1708+
}
1709+
1710+
return string_list_has_string(&applets, cmd) ?
1711+
xstrdup(busybox_path) : NULL;
1712+
}
1713+
16541714
/*
16551715
* Determines the absolute path of cmd using the split path in path.
16561716
* If cmd contains a slash or backslash, no lookup is performed.
@@ -1679,6 +1739,9 @@ static char *path_lookup(const char *cmd, int exe_only)
16791739
path = sep + 1;
16801740
}
16811741

1742+
if (!prog && !isexe)
1743+
prog = is_busybox_applet(cmd);
1744+
16821745
return prog;
16831746
}
16841747

@@ -1882,8 +1945,8 @@ static int is_msys2_sh(const char *cmd)
18821945
}
18831946

18841947
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1885-
const char *dir,
1886-
int prepend_cmd, int fhin, int fhout, int fherr)
1948+
const char *dir, const char *prepend_cmd,
1949+
int fhin, int fhout, int fherr)
18871950
{
18881951
static int restrict_handle_inheritance = -1;
18891952
STARTUPINFOEXW si;
@@ -1974,9 +2037,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19742037
/* concatenate argv, quoting args as we go */
19752038
strbuf_init(&args, 0);
19762039
if (prepend_cmd) {
1977-
char *quoted = (char *)quote_arg(cmd);
2040+
char *quoted = (char *)quote_arg(prepend_cmd);
19782041
strbuf_addstr(&args, quoted);
1979-
if (quoted != cmd)
2042+
if (quoted != prepend_cmd)
19802043
free(quoted);
19812044
}
19822045
for (; *argv; argv++) {
@@ -2135,7 +2198,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21352198
return (pid_t)pi.dwProcessId;
21362199
}
21372200

2138-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2201+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2202+
const char *prepend_cmd)
21392203
{
21402204
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21412205
}
@@ -2163,14 +2227,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21632227
pid = -1;
21642228
}
21652229
else {
2166-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2230+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21672231
fhin, fhout, fherr);
21682232
free(iprog);
21692233
}
21702234
argv[0] = argv0;
21712235
}
21722236
else
2173-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2237+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21742238
fhin, fhout, fherr);
21752239
free(prog);
21762240
}
@@ -2195,7 +2259,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21952259
argv2[0] = (char *)cmd; /* full path to the script file */
21962260
COPY_ARRAY(&argv2[1], &argv[1], argc);
21972261
exec_id = trace2_exec(prog, (const char **)argv2);
2198-
pid = mingw_spawnv(prog, (const char **)argv2, 1);
2262+
pid = mingw_spawnv(prog, (const char **)argv2, interpr);
21992263
if (pid >= 0) {
22002264
int status;
22012265
if (waitpid(pid, &status, 0) < 0)
@@ -2219,7 +2283,7 @@ int mingw_execv(const char *cmd, char *const *argv)
22192283
int exec_id;
22202284

22212285
exec_id = trace2_exec(cmd, (const char **)argv);
2222-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2286+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
22232287
if (pid < 0) {
22242288
trace2_exec_result(exec_id, -1);
22252289
return -1;

config.mak.uname

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,62 @@ ifeq ($(uname_S),MINGW)
729729
ETC_GITCONFIG = ../etc/gitconfig
730730
ETC_GITATTRIBUTES = ../etc/gitattributes
731731
endif
732+
ifeq (i686,$(uname_M))
733+
MINGW_PREFIX := mingw32
734+
endif
735+
ifeq (x86_64,$(uname_M))
736+
MINGW_PREFIX := mingw64
737+
endif
738+
739+
DESTDIR_WINDOWS = $(shell cygpath -aw '$(DESTDIR_SQ)')
740+
DESTDIR_MIXED = $(shell cygpath -am '$(DESTDIR_SQ)')
741+
install-mingit-test-artifacts:
742+
install -m755 -d '$(DESTDIR_SQ)/usr/bin'
743+
printf '%s\n%s\n' >'$(DESTDIR_SQ)/usr/bin/perl' \
744+
"#!/mingw64/bin/busybox sh" \
745+
"exec \"$(shell cygpath -am /usr/bin/perl.exe)\" \"\$$@\""
746+
747+
install -m755 -d '$(DESTDIR_SQ)'
748+
printf '%s%s\n%s\n%s\n%s\n%s\n' >'$(DESTDIR_SQ)/init.bat' \
749+
"PATH=$(DESTDIR_WINDOWS)\\$(MINGW_PREFIX)\\bin;" \
750+
"C:\\WINDOWS;C:\\WINDOWS\\system32" \
751+
"@set GIT_TEST_INSTALLED=$(DESTDIR_MIXED)/$(MINGW_PREFIX)/bin" \
752+
"@`echo "$(DESTDIR_WINDOWS)" | sed 's/:.*/:/'`" \
753+
"@cd `echo "$(DESTDIR_WINDOWS)" | sed 's/^.://'`\\test-git\\t" \
754+
"@echo Now, run 'helper\\test-run-command testsuite'"
755+
756+
install -m755 -d '$(DESTDIR_SQ)/test-git'
757+
sed 's/^\(NO_PERL\|NO_PYTHON\)=.*/\1=YesPlease/' \
758+
<GIT-BUILD-OPTIONS >'$(DESTDIR_SQ)/test-git/GIT-BUILD-OPTIONS'
759+
760+
install -m755 -d '$(DESTDIR_SQ)/test-git/t/helper'
761+
install -m755 $(TEST_PROGRAMS) '$(DESTDIR_SQ)/test-git/t/helper'
762+
(cd t && $(TAR) cf - t[0-9][0-9][0-9][0-9] lib-diff) | \
763+
(cd '$(DESTDIR_SQ)/test-git/t' && $(TAR) xf -)
764+
install -m755 t/t556x_common t/*.sh '$(DESTDIR_SQ)/test-git/t'
765+
766+
install -m755 -d '$(DESTDIR_SQ)/test-git/templates'
767+
(cd templates && $(TAR) cf - blt) | \
768+
(cd '$(DESTDIR_SQ)/test-git/templates' && $(TAR) xf -)
769+
770+
# po/build/locale for t0200
771+
install -m755 -d '$(DESTDIR_SQ)/test-git/po/build/locale'
772+
(cd po/build/locale && $(TAR) cf - .) | \
773+
(cd '$(DESTDIR_SQ)/test-git/po/build/locale' && $(TAR) xf -)
774+
775+
# git-daemon.exe for t5802, git-http-backend.exe for t5560
776+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
777+
install -m755 git-daemon.exe git-http-backend.exe \
778+
'$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
779+
780+
# git-upload-archive (dashed) for t5000
781+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
782+
install -m755 git-upload-archive.exe '$(DESTDIR_SQ)/$(MINGW_PREFIX)/bin'
783+
784+
# git-difftool--helper for t7800
785+
install -m755 -d '$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core'
786+
install -m755 git-difftool--helper \
787+
'$(DESTDIR_SQ)/$(MINGW_PREFIX)/libexec/git-core'
732788
endif
733789
ifeq ($(uname_S),QNX)
734790
COMPAT_CFLAGS += -DSA_RESTART=0

git-sh-setup.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,30 @@ create_virtual_base() {
292292
# Platform specific tweaks to work around some commands
293293
case $(uname -s) in
294294
*MINGW*)
295-
# Windows has its own (incompatible) sort and find
296-
sort () {
297-
/usr/bin/sort "$@"
298-
}
299-
find () {
300-
/usr/bin/find "$@"
301-
}
302-
# git sees Windows-style pwd
303-
pwd () {
304-
builtin pwd -W
305-
}
295+
if test -x /usr/bin/sort
296+
then
297+
# Windows has its own (incompatible) sort; override
298+
sort () {
299+
/usr/bin/sort "$@"
300+
}
301+
fi
302+
if test -x /usr/bin/find
303+
then
304+
# Windows has its own (incompatible) find; override
305+
find () {
306+
/usr/bin/find "$@"
307+
}
308+
fi
309+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
310+
# Unix-style paths. At least in Bash, we have a builtin pwd that
311+
# understands the -W option to force "mixed" paths, i.e. with drive
312+
# prefix but still with forward slashes. Let's use that, if available.
313+
if type builtin >/dev/null 2>&1
314+
then
315+
pwd () {
316+
builtin pwd -W
317+
}
318+
fi
306319
is_absolute_path () {
307320
case "$1" in
308321
[/\\]* | [A-Za-z]:*)

t/helper/test-iconv.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "test-tool.h"
2+
#include "git-compat-util.h"
3+
#include "strbuf.h"
4+
#include "gettext.h"
5+
#include "parse-options.h"
6+
#include "utf8.h"
7+
8+
int cmd__iconv(int argc, const char **argv)
9+
{
10+
struct strbuf buf = STRBUF_INIT;
11+
char *from = NULL, *to = NULL, *p;
12+
size_t len;
13+
int ret = 0;
14+
const char * const iconv_usage[] = {
15+
N_("test-helper --iconv [<options>]"),
16+
NULL
17+
};
18+
struct option options[] = {
19+
OPT_STRING('f', "from-code", &from, "encoding", "from"),
20+
OPT_STRING('t', "to-code", &to, "encoding", "to"),
21+
OPT_END()
22+
};
23+
24+
argc = parse_options(argc, argv, NULL, options,
25+
iconv_usage, 0);
26+
27+
if (argc > 1 || !from || !to)
28+
usage_with_options(iconv_usage, options);
29+
30+
if (!argc) {
31+
if (strbuf_read(&buf, 0, 2048) < 0)
32+
die_errno("Could not read from stdin");
33+
} else if (strbuf_read_file(&buf, argv[0], 2048) < 0)
34+
die_errno("Could not read from '%s'", argv[0]);
35+
36+
p = reencode_string_len(buf.buf, buf.len, to, from, &len);
37+
if (!p)
38+
die_errno("Could not reencode");
39+
if (write(1, p, len) < 0)
40+
ret = !!error_errno("Could not write %"PRIuMAX" bytes",
41+
(uintmax_t)len);
42+
43+
strbuf_release(&buf);
44+
free(p);
45+
46+
return ret;
47+
}

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static struct test_cmd cmds[] = {
3939
{ "hashmap", cmd__hashmap },
4040
{ "hash-speed", cmd__hash_speed },
4141
{ "hexdump", cmd__hexdump },
42+
{ "iconv", cmd__iconv },
4243
{ "json-writer", cmd__json_writer },
4344
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
4445
{ "match-trees", cmd__match_trees },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int cmd__getcwd(int argc, const char **argv);
3333
int cmd__hashmap(int argc, const char **argv);
3434
int cmd__hash_speed(int argc, const char **argv);
3535
int cmd__hexdump(int argc, const char **argv);
36+
int cmd__iconv(int argc, const char **argv);
3637
int cmd__json_writer(int argc, const char **argv);
3738
int cmd__lazy_init_name_hash(int argc, const char **argv);
3839
int cmd__match_trees(int argc, const char **argv);

t/interop/interop-lib.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
. ../../GIT-BUILD-OPTIONS
55
INTEROP_ROOT=$(pwd)
66
BUILD_ROOT=$INTEROP_ROOT/build
7+
case "$PATH" in
8+
*\;*) PATH_SEP=\; ;;
9+
*) PATH_SEP=: ;;
10+
esac
711

812
build_version () {
913
if test -z "$1"
@@ -57,7 +61,7 @@ wrap_git () {
5761
write_script "$1" <<-EOF
5862
GIT_EXEC_PATH="$2"
5963
export GIT_EXEC_PATH
60-
PATH="$2:\$PATH"
64+
PATH="$2$PATH_SEP\$PATH"
6165
export GIT_EXEC_PATH
6266
exec git "\$@"
6367
EOF
@@ -71,7 +75,7 @@ generate_wrappers () {
7175
echo >&2 fatal: test tried to run generic git: $*
7276
exit 1
7377
EOF
74-
PATH=$(pwd)/.bin:$PATH
78+
PATH=$(pwd)/.bin$PATH_SEP$PATH
7579
}
7680

7781
VERSION_A=${GIT_TEST_VERSION_A:-$VERSION_A}
File renamed without changes.
File renamed without changes.

t/lib-proto-disable.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ setup_ext_wrapper () {
214214
cd "$TRASH_DIRECTORY/remote" &&
215215
eval "$*"
216216
EOF
217-
PATH=$TRASH_DIRECTORY:$PATH &&
217+
PATH=$TRASH_DIRECTORY$PATH_SEP$PATH &&
218218
export TRASH_DIRECTORY
219219
'
220220
}

t/t0014-alias.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_expect_success 'looping aliases - internal execution' '
3939

4040
test_expect_success 'run-command formats empty args properly' '
4141
test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
42-
sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
42+
sed -ne "/run_command: git-frotz/s/.*trace: run_command: //p" actual.raw >actual &&
4343
echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
4444
test_cmp expect actual
4545
'

t/t0021-conversion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
88
. ./test-lib.sh
99
. "$TEST_DIRECTORY"/lib-terminal.sh
1010

11-
PATH=$PWD:$PATH
11+
PATH=$PWD$PATH_SEP$PATH
1212
TEST_ROOT="$(pwd)"
1313

1414
write_script <<\EOF "$TEST_ROOT/rot13.sh"

0 commit comments

Comments
 (0)