Skip to content

Commit 6f51bc2

Browse files
committed
Merge branch 'busybox-w32'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents d9e98cb + b4c17b9 commit 6f51bc2

Some content is hidden

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

44 files changed

+449
-191
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*.perl eol=lf diff=perl
55
*.pl eof=lf diff=perl
66
*.pm eol=lf diff=perl
7+
*.png binary
78
*.py eol=lf diff=python
89
*.bat eol=crlf
910
CODE_OF_CONDUCT.md -whitespace

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-advise.o
722722
TEST_BUILTINS_OBJS += test-bitmap.o
723723
TEST_BUILTINS_OBJS += test-bloom.o
724724
TEST_BUILTINS_OBJS += test-chmtime.o
725+
TEST_BUILTINS_OBJS += test-cmp.o
725726
TEST_BUILTINS_OBJS += test-config.o
726727
TEST_BUILTINS_OBJS += test-crontab.o
727728
TEST_BUILTINS_OBJS += test-csprng.o
@@ -744,6 +745,7 @@ TEST_BUILTINS_OBJS += test-hash-speed.o
744745
TEST_BUILTINS_OBJS += test-hash.o
745746
TEST_BUILTINS_OBJS += test-hashmap.o
746747
TEST_BUILTINS_OBJS += test-hexdump.o
748+
TEST_BUILTINS_OBJS += test-iconv.o
747749
TEST_BUILTINS_OBJS += test-index-version.o
748750
TEST_BUILTINS_OBJS += test-json-writer.o
749751
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o

compat/mingw.c

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sspi.h>
1616
#include "win32/fscache.h"
1717
#include "../attr.h"
18+
#include "../string-list.h"
1819

1920
#define HCAST(type, handle) ((type)(intptr_t)handle)
2021

@@ -1626,6 +1627,65 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
16261627
return NULL;
16271628
}
16281629

1630+
static char *path_lookup(const char *cmd, int exe_only);
1631+
1632+
static char *is_busybox_applet(const char *cmd)
1633+
{
1634+
static struct string_list applets = STRING_LIST_INIT_DUP;
1635+
static char *busybox_path;
1636+
static int busybox_path_initialized;
1637+
1638+
/* Avoid infinite loop */
1639+
if (!strncasecmp(cmd, "busybox", 7) &&
1640+
(!cmd[7] || !strcasecmp(cmd + 7, ".exe")))
1641+
return NULL;
1642+
1643+
if (!busybox_path_initialized) {
1644+
busybox_path = path_lookup("busybox.exe", 1);
1645+
busybox_path_initialized = 1;
1646+
}
1647+
1648+
/* Assume that sh is compiled in... */
1649+
if (!busybox_path || !strcasecmp(cmd, "sh"))
1650+
return xstrdup_or_null(busybox_path);
1651+
1652+
if (!applets.nr) {
1653+
struct child_process cp = CHILD_PROCESS_INIT;
1654+
struct strbuf buf = STRBUF_INIT;
1655+
char *p;
1656+
1657+
strvec_pushl(&cp.args, busybox_path, "--help", NULL);
1658+
1659+
if (capture_command(&cp, &buf, 2048)) {
1660+
string_list_append(&applets, "");
1661+
return NULL;
1662+
}
1663+
1664+
/* parse output */
1665+
p = strstr(buf.buf, "Currently defined functions:\n");
1666+
if (!p) {
1667+
warning("Could not parse output of busybox --help");
1668+
string_list_append(&applets, "");
1669+
return NULL;
1670+
}
1671+
p = strchrnul(p, '\n');
1672+
for (;;) {
1673+
size_t len;
1674+
1675+
p += strspn(p, "\n\t ,");
1676+
len = strcspn(p, "\n\t ,");
1677+
if (!len)
1678+
break;
1679+
p[len] = '\0';
1680+
string_list_insert(&applets, p);
1681+
p = p + len + 1;
1682+
}
1683+
}
1684+
1685+
return string_list_has_string(&applets, cmd) ?
1686+
xstrdup(busybox_path) : NULL;
1687+
}
1688+
16291689
/*
16301690
* Determines the absolute path of cmd using the split path in path.
16311691
* If cmd contains a slash or backslash, no lookup is performed.
@@ -1654,6 +1714,9 @@ static char *path_lookup(const char *cmd, int exe_only)
16541714
path = sep + 1;
16551715
}
16561716

1717+
if (!prog && !isexe)
1718+
prog = is_busybox_applet(cmd);
1719+
16571720
return prog;
16581721
}
16591722

@@ -1853,8 +1916,8 @@ static int is_msys2_sh(const char *cmd)
18531916
}
18541917

18551918
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1856-
const char *dir,
1857-
int prepend_cmd, int fhin, int fhout, int fherr)
1919+
const char *dir, const char *prepend_cmd,
1920+
int fhin, int fhout, int fherr)
18581921
{
18591922
static int restrict_handle_inheritance = -1;
18601923
STARTUPINFOEXW si;
@@ -1945,9 +2008,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19452008
/* concatenate argv, quoting args as we go */
19462009
strbuf_init(&args, 0);
19472010
if (prepend_cmd) {
1948-
char *quoted = (char *)quote_arg(cmd);
2011+
char *quoted = (char *)quote_arg(prepend_cmd);
19492012
strbuf_addstr(&args, quoted);
1950-
if (quoted != cmd)
2013+
if (quoted != prepend_cmd)
19512014
free(quoted);
19522015
}
19532016
for (; *argv; argv++) {
@@ -2106,7 +2169,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
21062169
return (pid_t)pi.dwProcessId;
21072170
}
21082171

2109-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2172+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2173+
const char *prepend_cmd)
21102174
{
21112175
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
21122176
}
@@ -2134,14 +2198,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
21342198
pid = -1;
21352199
}
21362200
else {
2137-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2201+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
21382202
fhin, fhout, fherr);
21392203
free(iprog);
21402204
}
21412205
argv[0] = argv0;
21422206
}
21432207
else
2144-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2208+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21452209
fhin, fhout, fherr);
21462210
free(prog);
21472211
}
@@ -2169,7 +2233,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21692233
argv2[0] = (char *)cmd; /* full path to the script file */
21702234
COPY_ARRAY(&argv2[1], &argv[1], argc);
21712235
exec_id = trace2_exec(prog, argv2);
2172-
pid = mingw_spawnv(prog, argv2, 1);
2236+
pid = mingw_spawnv(prog, argv2, interpr);
21732237
if (pid >= 0) {
21742238
int status;
21752239
if (waitpid(pid, &status, 0) < 0)
@@ -2193,7 +2257,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21932257
int exec_id;
21942258

21952259
exec_id = trace2_exec(cmd, (const char **)argv);
2196-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2260+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21972261
if (pid < 0) {
21982262
trace2_exec_result(exec_id, -1);
21992263
return -1;

config.mak.uname

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 "run-command.h"
7+
8+
#ifdef WIN32
9+
#define NO_SUCH_DIR "\\\\.\\GLOBALROOT\\invalid"
10+
#else
11+
#define NO_SUCH_DIR "/dev/null"
12+
#endif
13+
14+
static int run_diff(const char *path1, const char *path2)
15+
{
16+
const char *argv[] = {
17+
"diff", "--no-index", NULL, NULL, NULL
18+
};
19+
const char *env[] = {
20+
"GIT_PAGER=cat",
21+
"GIT_DIR=" NO_SUCH_DIR,
22+
"HOME=" NO_SUCH_DIR,
23+
NULL
24+
};
25+
26+
argv[2] = path1;
27+
argv[3] = path2;
28+
return run_command_v_opt_cd_env(argv,
29+
RUN_COMMAND_NO_STDIN | RUN_GIT_CMD,
30+
NULL, env);
31+
}
32+
33+
int cmd__cmp(int argc, const char **argv)
34+
{
35+
FILE *f0, *f1;
36+
struct strbuf b0 = STRBUF_INIT, b1 = STRBUF_INIT;
37+
38+
if (argc != 3)
39+
die("Require exactly 2 arguments, got %d", argc);
40+
41+
if (!(f0 = !strcmp(argv[1], "-") ? stdin : fopen(argv[1], "r")))
42+
return error_errno("could not open '%s'", argv[1]);
43+
if (!(f1 = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"))) {
44+
fclose(f0);
45+
return error_errno("could not open '%s'", argv[2]);
46+
}
47+
48+
for (;;) {
49+
int r0 = strbuf_getline(&b0, f0);
50+
int r1 = strbuf_getline(&b1, f1);
51+
52+
if (r0 == EOF) {
53+
fclose(f0);
54+
fclose(f1);
55+
strbuf_release(&b0);
56+
strbuf_release(&b1);
57+
if (r1 == EOF)
58+
return 0;
59+
cmp_failed:
60+
if (!run_diff(argv[1], argv[2]))
61+
die("Huh? 'diff --no-index %s %s' succeeded",
62+
argv[1], argv[2]);
63+
return 1;
64+
}
65+
if (r1 == EOF || strbuf_cmp(&b0, &b1)) {
66+
fclose(f0);
67+
fclose(f1);
68+
strbuf_release(&b0);
69+
strbuf_release(&b1);
70+
goto cmp_failed;
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)