Skip to content

Commit 385e171

Browse files
committed
Merge branch 'sk/mingw-uni-fix-more'
Most of these are battle-tested in msysgit and are needed to complete what has been merged to 'master' already. * sk/mingw-uni-fix-more: Win32: enable color output in Windows cmd.exe Win32: patch Windows environment on startup Win32: keep the environment sorted Win32: use low-level memory allocation during initialization Win32: reduce environment array reallocations Win32: don't copy the environment twice when spawning child processes Win32: factor out environment block creation Win32: unify environment function names Win32: unify environment case-sensitivity Win32: fix environment memory leaks Win32: Unicode environment (incoming) Win32: Unicode environment (outgoing) Revert "Windows: teach getenv to do a case-sensitive search" tests: do not pass iso8859-1 encoded parameter
2 parents 4b0c0e3 + baea068 commit 385e171

File tree

8 files changed

+184
-150
lines changed

8 files changed

+184
-150
lines changed

compat/mingw.c

Lines changed: 164 additions & 127 deletions
Large diffs are not rendered by default.

compat/mingw.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ char *mingw_getcwd(char *pointer, int len);
210210

211211
char *mingw_getenv(const char *name);
212212
#define getenv mingw_getenv
213+
int mingw_putenv(const char *namevalue);
214+
#define putenv mingw_putenv
215+
#define unsetenv mingw_putenv
213216

214217
int mingw_gethostname(char *host, int namelen);
215218
#define gethostname mingw_gethostname
@@ -357,12 +360,8 @@ int mingw_offset_1st_component(const char *path);
357360
void mingw_open_html(const char *path);
358361
#define open_html mingw_open_html
359362

360-
/*
361-
* helpers
362-
*/
363-
364-
char **make_augmented_environ(const char *const *vars);
365-
void free_environ(char **env);
363+
void mingw_mark_as_git_dir(const char *dir);
364+
#define mark_as_git_dir mingw_mark_as_git_dir
366365

367366
/**
368367
* Converts UTF-8 encoded string to UTF-16LE.

config.mak.uname

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ ifeq ($(uname_S),Windows)
327327
NO_IPV6 = YesPlease
328328
NO_UNIX_SOCKETS = YesPlease
329329
NO_SETENV = YesPlease
330-
NO_UNSETENV = YesPlease
331330
NO_STRCASESTR = YesPlease
332331
NO_STRLCPY = YesPlease
333332
NO_MEMMEM = YesPlease
@@ -480,7 +479,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
480479
NO_SYMLINK_HEAD = YesPlease
481480
NO_UNIX_SOCKETS = YesPlease
482481
NO_SETENV = YesPlease
483-
NO_UNSETENV = YesPlease
484482
NO_STRCASESTR = YesPlease
485483
NO_STRLCPY = YesPlease
486484
NO_MEMMEM = YesPlease

run-command.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ int start_command(struct child_process *cmd)
454454
{
455455
int fhin = 0, fhout = 1, fherr = 2;
456456
const char **sargv = cmd->argv;
457-
char **env = environ;
458457

459458
if (cmd->no_stdin)
460459
fhin = open("/dev/null", O_RDWR);
@@ -479,24 +478,19 @@ int start_command(struct child_process *cmd)
479478
else if (cmd->out > 1)
480479
fhout = dup(cmd->out);
481480

482-
if (cmd->env)
483-
env = make_augmented_environ(cmd->env);
484-
485481
if (cmd->git_cmd)
486482
cmd->argv = prepare_git_cmd(cmd->argv);
487483
else if (cmd->use_shell)
488484
cmd->argv = prepare_shell_cmd(cmd->argv);
489485

490-
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, env, cmd->dir,
491-
fhin, fhout, fherr);
486+
cmd->pid = mingw_spawnvpe(cmd->argv[0], cmd->argv, (char**) cmd->env,
487+
cmd->dir, fhin, fhout, fherr);
492488
failed_errno = errno;
493489
if (cmd->pid < 0 && (!cmd->silent_exec_failure || errno != ENOENT))
494490
error("cannot spawn %s: %s", cmd->argv[0], strerror(errno));
495491
if (cmd->clean_on_exit && cmd->pid >= 0)
496492
mark_child_for_cleanup(cmd->pid);
497493

498-
if (cmd->env)
499-
free_environ(env);
500494
if (cmd->git_cmd)
501495
free(cmd->argv);
502496

t/t4041-diff-submodule-option.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ add_file () {
2626
echo "$name" >"$name" &&
2727
git add "$name" &&
2828
test_tick &&
29-
msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) &&
30-
git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591"
29+
# "git commit -m" would break MinGW, as Windows refuse to pass
30+
# $test_encoding encoded parameter to git.
31+
echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
32+
git -c "i18n.commitEncoding=$test_encoding" commit -F -
3133
done >/dev/null &&
3234
git rev-parse --short --verify HEAD
3335
)

t/t4205-log-pretty-formats.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test_expect_success 'set up basic repos' '
3131
git add foo &&
3232
test_tick &&
3333
git config i18n.commitEncoding $test_encoding &&
34-
git commit -m "$(commit_msg $test_encoding)" &&
34+
commit_msg $test_encoding | git commit -F - &&
3535
git add bar &&
3636
test_tick &&
3737
git commit -m "add bar" &&

t/t6006-rev-list-format.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ test_expect_success 'setup' '
3535
: >foo &&
3636
git add foo &&
3737
git config i18n.commitEncoding $test_encoding &&
38-
git commit -m "$added_iso88591" &&
38+
echo "$added_iso88591" | git commit -F - &&
3939
head1=$(git rev-parse --verify HEAD) &&
4040
head1_short=$(git rev-parse --verify --short $head1) &&
4141
tree1=$(git rev-parse --verify HEAD:) &&
4242
tree1_short=$(git rev-parse --verify --short $tree1) &&
4343
echo "$changed" > foo &&
44-
git commit -a -m "$changed_iso88591" &&
44+
echo "$changed_iso88591" | git commit -a -F - &&
4545
head2=$(git rev-parse --verify HEAD) &&
4646
head2_short=$(git rev-parse --verify --short $head2) &&
4747
tree2=$(git rev-parse --verify HEAD:) &&

t/t7102-reset.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ test_expect_success 'creating initial files and commits' '
4444
4545
echo "1st line 2nd file" >secondfile &&
4646
echo "2nd line 2nd file" >>secondfile &&
47-
git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
47+
# "git commit -m" would break MinGW, as Windows refuse to pass
48+
# $test_encoding encoded parameter to git.
49+
commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - &&
4850
head5=$(git rev-parse --verify HEAD)
4951
'
5052
# git log --pretty=oneline # to see those SHA1 involved
@@ -334,7 +336,9 @@ test_expect_success 'redoing the last two commits should succeed' '
334336
335337
echo "1st line 2nd file" >secondfile &&
336338
echo "2nd line 2nd file" >>secondfile &&
337-
git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" &&
339+
# "git commit -m" would break MinGW, as Windows refuse to pass
340+
# $test_encoding encoded parameter to git.
341+
commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - &&
338342
check_changes $head5
339343
'
340344

0 commit comments

Comments
 (0)