Skip to content

Commit 304ae3e

Browse files
committed
Merge branch 'busybox-w32'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents bfac9b2 + 2dd49d4 commit 304ae3e

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
@@ -702,6 +702,7 @@ TEST_BUILTINS_OBJS += test-advise.o
702702
TEST_BUILTINS_OBJS += test-bitmap.o
703703
TEST_BUILTINS_OBJS += test-bloom.o
704704
TEST_BUILTINS_OBJS += test-chmtime.o
705+
TEST_BUILTINS_OBJS += test-cmp.o
705706
TEST_BUILTINS_OBJS += test-config.o
706707
TEST_BUILTINS_OBJS += test-crontab.o
707708
TEST_BUILTINS_OBJS += test-ctype.o
@@ -722,6 +723,7 @@ TEST_BUILTINS_OBJS += test-getcwd.o
722723
TEST_BUILTINS_OBJS += test-hash-speed.o
723724
TEST_BUILTINS_OBJS += test-hash.o
724725
TEST_BUILTINS_OBJS += test-hashmap.o
726+
TEST_BUILTINS_OBJS += test-iconv.o
725727
TEST_BUILTINS_OBJS += test-index-version.o
726728
TEST_BUILTINS_OBJS += test-json-writer.o
727729
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
@@ -14,6 +14,7 @@
1414
#include <sspi.h>
1515
#include "win32/fscache.h"
1616
#include "../attr.h"
17+
#include "../string-list.h"
1718

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

@@ -1570,6 +1571,65 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
15701571
return NULL;
15711572
}
15721573

1574+
static char *path_lookup(const char *cmd, int exe_only);
1575+
1576+
static char *is_busybox_applet(const char *cmd)
1577+
{
1578+
static struct string_list applets = STRING_LIST_INIT_DUP;
1579+
static char *busybox_path;
1580+
static int busybox_path_initialized;
1581+
1582+
/* Avoid infinite loop */
1583+
if (!strncasecmp(cmd, "busybox", 7) &&
1584+
(!cmd[7] || !strcasecmp(cmd + 7, ".exe")))
1585+
return NULL;
1586+
1587+
if (!busybox_path_initialized) {
1588+
busybox_path = path_lookup("busybox.exe", 1);
1589+
busybox_path_initialized = 1;
1590+
}
1591+
1592+
/* Assume that sh is compiled in... */
1593+
if (!busybox_path || !strcasecmp(cmd, "sh"))
1594+
return xstrdup_or_null(busybox_path);
1595+
1596+
if (!applets.nr) {
1597+
struct child_process cp = CHILD_PROCESS_INIT;
1598+
struct strbuf buf = STRBUF_INIT;
1599+
char *p;
1600+
1601+
strvec_pushl(&cp.args, busybox_path, "--help", NULL);
1602+
1603+
if (capture_command(&cp, &buf, 2048)) {
1604+
string_list_append(&applets, "");
1605+
return NULL;
1606+
}
1607+
1608+
/* parse output */
1609+
p = strstr(buf.buf, "Currently defined functions:\n");
1610+
if (!p) {
1611+
warning("Could not parse output of busybox --help");
1612+
string_list_append(&applets, "");
1613+
return NULL;
1614+
}
1615+
p = strchrnul(p, '\n');
1616+
for (;;) {
1617+
size_t len;
1618+
1619+
p += strspn(p, "\n\t ,");
1620+
len = strcspn(p, "\n\t ,");
1621+
if (!len)
1622+
break;
1623+
p[len] = '\0';
1624+
string_list_insert(&applets, p);
1625+
p = p + len + 1;
1626+
}
1627+
}
1628+
1629+
return string_list_has_string(&applets, cmd) ?
1630+
xstrdup(busybox_path) : NULL;
1631+
}
1632+
15731633
/*
15741634
* Determines the absolute path of cmd using the split path in path.
15751635
* If cmd contains a slash or backslash, no lookup is performed.
@@ -1598,6 +1658,9 @@ static char *path_lookup(const char *cmd, int exe_only)
15981658
path = sep + 1;
15991659
}
16001660

1661+
if (!prog && !isexe)
1662+
prog = is_busybox_applet(cmd);
1663+
16011664
return prog;
16021665
}
16031666

@@ -1797,8 +1860,8 @@ static int is_msys2_sh(const char *cmd)
17971860
}
17981861

17991862
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1800-
const char *dir,
1801-
int prepend_cmd, int fhin, int fhout, int fherr)
1863+
const char *dir, const char *prepend_cmd,
1864+
int fhin, int fhout, int fherr)
18021865
{
18031866
static int restrict_handle_inheritance = -1;
18041867
STARTUPINFOEXW si;
@@ -1889,9 +1952,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18891952
/* concatenate argv, quoting args as we go */
18901953
strbuf_init(&args, 0);
18911954
if (prepend_cmd) {
1892-
char *quoted = (char *)quote_arg(cmd);
1955+
char *quoted = (char *)quote_arg(prepend_cmd);
18931956
strbuf_addstr(&args, quoted);
1894-
if (quoted != cmd)
1957+
if (quoted != prepend_cmd)
18951958
free(quoted);
18961959
}
18971960
for (; *argv; argv++) {
@@ -2050,7 +2113,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20502113
return (pid_t)pi.dwProcessId;
20512114
}
20522115

2053-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2116+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2117+
const char *prepend_cmd)
20542118
{
20552119
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20562120
}
@@ -2078,14 +2142,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20782142
pid = -1;
20792143
}
20802144
else {
2081-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2145+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20822146
fhin, fhout, fherr);
20832147
free(iprog);
20842148
}
20852149
argv[0] = argv0;
20862150
}
20872151
else
2088-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2152+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
20892153
fhin, fhout, fherr);
20902154
free(prog);
20912155
}
@@ -2113,7 +2177,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21132177
argv2[0] = (char *)cmd; /* full path to the script file */
21142178
COPY_ARRAY(&argv2[1], &argv[1], argc);
21152179
exec_id = trace2_exec(prog, argv2);
2116-
pid = mingw_spawnv(prog, argv2, 1);
2180+
pid = mingw_spawnv(prog, argv2, interpr);
21172181
if (pid >= 0) {
21182182
int status;
21192183
if (waitpid(pid, &status, 0) < 0)
@@ -2137,7 +2201,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21372201
int exec_id;
21382202

21392203
exec_id = trace2_exec(cmd, (const char **)argv);
2140-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2204+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21412205
if (pid < 0) {
21422206
trace2_exec_result(exec_id, -1);
21432207
return -1;

config.mak.uname

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

git-sh-setup.sh

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,30 @@ create_virtual_base() {
309309
# Platform specific tweaks to work around some commands
310310
case $(uname -s) in
311311
*MINGW*)
312-
# Windows has its own (incompatible) sort and find
313-
sort () {
314-
/usr/bin/sort "$@"
315-
}
316-
find () {
317-
/usr/bin/find "$@"
318-
}
319-
# git sees Windows-style pwd
320-
pwd () {
321-
builtin pwd -W
322-
}
312+
if test -x /usr/bin/sort
313+
then
314+
# Windows has its own (incompatible) sort; override
315+
sort () {
316+
/usr/bin/sort "$@"
317+
}
318+
fi
319+
if test -x /usr/bin/find
320+
then
321+
# Windows has its own (incompatible) find; override
322+
find () {
323+
/usr/bin/find "$@"
324+
}
325+
fi
326+
# On Windows, Git wants Windows paths. But /usr/bin/pwd spits out
327+
# Unix-style paths. At least in Bash, we have a builtin pwd that
328+
# understands the -W option to force "mixed" paths, i.e. with drive
329+
# prefix but still with forward slashes. Let's use that, if available.
330+
if type builtin >/dev/null 2>&1
331+
then
332+
pwd () {
333+
builtin pwd -W
334+
}
335+
fi
323336
is_absolute_path () {
324337
case "$1" in
325338
[/\\]* | [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)