Skip to content

Commit a9c955f

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge branch 'busybox-w32'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents aca4b18 + 38c8331 commit a9c955f

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
@@ -713,6 +713,7 @@ TEST_BUILTINS_OBJS += test-advise.o
713713
TEST_BUILTINS_OBJS += test-bitmap.o
714714
TEST_BUILTINS_OBJS += test-bloom.o
715715
TEST_BUILTINS_OBJS += test-chmtime.o
716+
TEST_BUILTINS_OBJS += test-cmp.o
716717
TEST_BUILTINS_OBJS += test-config.o
717718
TEST_BUILTINS_OBJS += test-crontab.o
718719
TEST_BUILTINS_OBJS += test-csprng.o
@@ -734,6 +735,7 @@ TEST_BUILTINS_OBJS += test-getcwd.o
734735
TEST_BUILTINS_OBJS += test-hash-speed.o
735736
TEST_BUILTINS_OBJS += test-hash.o
736737
TEST_BUILTINS_OBJS += test-hashmap.o
738+
TEST_BUILTINS_OBJS += test-iconv.o
737739
TEST_BUILTINS_OBJS += test-index-version.o
738740
TEST_BUILTINS_OBJS += test-json-writer.o
739741
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

@@ -1586,6 +1587,65 @@ static char *lookup_prog(const char *dir, int dirlen, const char *cmd,
15861587
return NULL;
15871588
}
15881589

1590+
static char *path_lookup(const char *cmd, int exe_only);
1591+
1592+
static char *is_busybox_applet(const char *cmd)
1593+
{
1594+
static struct string_list applets = STRING_LIST_INIT_DUP;
1595+
static char *busybox_path;
1596+
static int busybox_path_initialized;
1597+
1598+
/* Avoid infinite loop */
1599+
if (!strncasecmp(cmd, "busybox", 7) &&
1600+
(!cmd[7] || !strcasecmp(cmd + 7, ".exe")))
1601+
return NULL;
1602+
1603+
if (!busybox_path_initialized) {
1604+
busybox_path = path_lookup("busybox.exe", 1);
1605+
busybox_path_initialized = 1;
1606+
}
1607+
1608+
/* Assume that sh is compiled in... */
1609+
if (!busybox_path || !strcasecmp(cmd, "sh"))
1610+
return xstrdup_or_null(busybox_path);
1611+
1612+
if (!applets.nr) {
1613+
struct child_process cp = CHILD_PROCESS_INIT;
1614+
struct strbuf buf = STRBUF_INIT;
1615+
char *p;
1616+
1617+
strvec_pushl(&cp.args, busybox_path, "--help", NULL);
1618+
1619+
if (capture_command(&cp, &buf, 2048)) {
1620+
string_list_append(&applets, "");
1621+
return NULL;
1622+
}
1623+
1624+
/* parse output */
1625+
p = strstr(buf.buf, "Currently defined functions:\n");
1626+
if (!p) {
1627+
warning("Could not parse output of busybox --help");
1628+
string_list_append(&applets, "");
1629+
return NULL;
1630+
}
1631+
p = strchrnul(p, '\n');
1632+
for (;;) {
1633+
size_t len;
1634+
1635+
p += strspn(p, "\n\t ,");
1636+
len = strcspn(p, "\n\t ,");
1637+
if (!len)
1638+
break;
1639+
p[len] = '\0';
1640+
string_list_insert(&applets, p);
1641+
p = p + len + 1;
1642+
}
1643+
}
1644+
1645+
return string_list_has_string(&applets, cmd) ?
1646+
xstrdup(busybox_path) : NULL;
1647+
}
1648+
15891649
/*
15901650
* Determines the absolute path of cmd using the split path in path.
15911651
* If cmd contains a slash or backslash, no lookup is performed.
@@ -1614,6 +1674,9 @@ static char *path_lookup(const char *cmd, int exe_only)
16141674
path = sep + 1;
16151675
}
16161676

1677+
if (!prog && !isexe)
1678+
prog = is_busybox_applet(cmd);
1679+
16171680
return prog;
16181681
}
16191682

@@ -1813,8 +1876,8 @@ static int is_msys2_sh(const char *cmd)
18131876
}
18141877

18151878
static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaenv,
1816-
const char *dir,
1817-
int prepend_cmd, int fhin, int fhout, int fherr)
1879+
const char *dir, const char *prepend_cmd,
1880+
int fhin, int fhout, int fherr)
18181881
{
18191882
static int restrict_handle_inheritance = -1;
18201883
STARTUPINFOEXW si;
@@ -1905,9 +1968,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
19051968
/* concatenate argv, quoting args as we go */
19061969
strbuf_init(&args, 0);
19071970
if (prepend_cmd) {
1908-
char *quoted = (char *)quote_arg(cmd);
1971+
char *quoted = (char *)quote_arg(prepend_cmd);
19091972
strbuf_addstr(&args, quoted);
1910-
if (quoted != cmd)
1973+
if (quoted != prepend_cmd)
19111974
free(quoted);
19121975
}
19131976
for (; *argv; argv++) {
@@ -2066,7 +2129,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
20662129
return (pid_t)pi.dwProcessId;
20672130
}
20682131

2069-
static pid_t mingw_spawnv(const char *cmd, const char **argv, int prepend_cmd)
2132+
static pid_t mingw_spawnv(const char *cmd, const char **argv,
2133+
const char *prepend_cmd)
20702134
{
20712135
return mingw_spawnve_fd(cmd, argv, NULL, NULL, prepend_cmd, 0, 1, 2);
20722136
}
@@ -2094,14 +2158,14 @@ pid_t mingw_spawnvpe(const char *cmd, const char **argv, char **deltaenv,
20942158
pid = -1;
20952159
}
20962160
else {
2097-
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, 1,
2161+
pid = mingw_spawnve_fd(iprog, argv, deltaenv, dir, interpr,
20982162
fhin, fhout, fherr);
20992163
free(iprog);
21002164
}
21012165
argv[0] = argv0;
21022166
}
21032167
else
2104-
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, 0,
2168+
pid = mingw_spawnve_fd(prog, argv, deltaenv, dir, NULL,
21052169
fhin, fhout, fherr);
21062170
free(prog);
21072171
}
@@ -2129,7 +2193,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
21292193
argv2[0] = (char *)cmd; /* full path to the script file */
21302194
COPY_ARRAY(&argv2[1], &argv[1], argc);
21312195
exec_id = trace2_exec(prog, argv2);
2132-
pid = mingw_spawnv(prog, argv2, 1);
2196+
pid = mingw_spawnv(prog, argv2, interpr);
21332197
if (pid >= 0) {
21342198
int status;
21352199
if (waitpid(pid, &status, 0) < 0)
@@ -2153,7 +2217,7 @@ int mingw_execv(const char *cmd, char *const *argv)
21532217
int exec_id;
21542218

21552219
exec_id = trace2_exec(cmd, (const char **)argv);
2156-
pid = mingw_spawnv(cmd, (const char **)argv, 0);
2220+
pid = mingw_spawnv(cmd, (const char **)argv, NULL);
21572221
if (pid < 0) {
21582222
trace2_exec_result(exec_id, -1);
21592223
return -1;

config.mak.uname

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

git-sh-setup.sh

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