Skip to content

Commit 62278b3

Browse files
committed
Merge 'git-wrapper' into HEAD
Use msysGit's `git-wrapper` instead of the builtins. This works around two issues: - when the file system does not allow hard links, we would waste over 800 megabyte by having 109 copies of a multi-megabyte executable - even when the file system allows hard links, the Windows Explorer counts the disk usage as if it did not. Many users complained about Git for Windows using too much space (when it actually did not). We can easily avoid those user complaints by merging this branch. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents dd94d48 + d537349 commit 62278b3

File tree

4 files changed

+558
-8
lines changed

4 files changed

+558
-8
lines changed

Makefile

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,11 +1655,17 @@ version.sp version.s version.o: EXTRA_CPPFLAGS = \
16551655
'-DGIT_VERSION="$(GIT_VERSION)"' \
16561656
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
16571657

1658+
ifeq (,$(BUILT_IN_WRAPPER))
16581659
$(BUILT_INS): git$X
16591660
$(QUIET_BUILT_IN)$(RM) $@ && \
16601661
ln $< $@ 2>/dev/null || \
16611662
ln -s $< $@ 2>/dev/null || \
16621663
cp $< $@
1664+
else
1665+
$(BUILT_INS): $(BUILT_IN_WRAPPER)
1666+
$(QUIET_BUILT_IN)$(RM) $@ && \
1667+
cp $< $@
1668+
endif
16631669

16641670
common-cmds.h: ./generate-cmdlist.sh command-list.txt
16651671

@@ -2222,6 +2228,24 @@ profile-install: profile
22222228
profile-fast-install: profile-fast
22232229
$(MAKE) install
22242230

2231+
ifeq (,$(BUILT_IN_WRAPPER))
2232+
LN_OR_CP_BUILT_IN_BINDIR = \
2233+
test -z "$(NO_INSTALL_HARDLINKS)" && \
2234+
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
2235+
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
2236+
cp "$$bindir/git$X" "$$bindir/$$p" || exit;
2237+
LN_OR_CP_BUILT_IN_EXECDIR = \
2238+
test -z "$(NO_INSTALL_HARDLINKS)" && \
2239+
ln "$$exectir/git$X" "$$exectir/$$p" 2>/dev/null || \
2240+
ln -s "git$X" "$$exectir/$$p" 2>/dev/null || \
2241+
cp "$$exectir/git$X" "$$exectir/$$p" || exit;
2242+
else
2243+
LN_OR_CP_BUILT_IN_BINDIR = \
2244+
cp "$(BUILT_IN_WRAPPER)" "$$bindir/$$p" || exit;
2245+
LN_OR_CP_BUILT_IN_EXECDIR = \
2246+
cp "$(BUILT_IN_WRAPPER)" "$$execdir/$$p" || exit;
2247+
endif
2248+
22252249
install: all
22262250
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
22272251
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
@@ -2260,17 +2284,11 @@ endif
22602284
} && \
22612285
for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
22622286
$(RM) "$$bindir/$$p" && \
2263-
test -z "$(NO_INSTALL_HARDLINKS)" && \
2264-
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
2265-
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
2266-
cp "$$bindir/git$X" "$$bindir/$$p" || exit; \
2287+
$(LN_OR_CP_BUILT_IN_BINDIR) \
22672288
done && \
22682289
for p in $(BUILT_INS); do \
22692290
$(RM) "$$execdir/$$p" && \
2270-
test -z "$(NO_INSTALL_HARDLINKS)" && \
2271-
ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
2272-
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
2273-
cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
2291+
$(LN_OR_CP_BUILT_IN_EXECDIR) \
22742292
done && \
22752293
remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
22762294
for p in $$remote_curl_aliases; do \

compat/terminal.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#include <inttypes.h>
12
#include "git-compat-util.h"
3+
#include "run-command.h"
24
#include "compat/terminal.h"
35
#include "sigchain.h"
46
#include "strbuf.h"
@@ -91,6 +93,53 @@ static int disable_echo(void)
9193
return 0;
9294
}
9395

96+
static char *xterm_prompt(const char *prompt, int echo)
97+
{
98+
const char *env = getenv("MSYS_TTY_HANDLES");
99+
const char *echo_off[] = { "sh", "-c", "stty -echo </dev/tty", NULL };
100+
const char *echo_on[] = { "sh", "-c", "stty echo </dev/tty", NULL };
101+
static char buffer[1024];
102+
DWORD len, dummy;
103+
size_t tty0, tty1, tty2;
104+
HANDLE in_handle, out_handle;
105+
106+
if (!env || 3 != sscanf(env,
107+
" %" SCNuPTR " %" SCNuPTR " %" SCNuPTR " ",
108+
&tty0, &tty1, &tty2)) {
109+
warning("Cannot read from xterm");
110+
return NULL;
111+
}
112+
113+
in_handle = (HANDLE)tty0;
114+
out_handle = (HANDLE)tty1;
115+
116+
if (!echo && run_command_v_opt(echo_off, 0))
117+
warning("Could not disable echo on xterm");
118+
119+
if (!WriteFile(out_handle, prompt, strlen(prompt), &dummy, NULL)) {
120+
warning("Could not write to xterm");
121+
return NULL;
122+
}
123+
124+
if (!ReadFile(in_handle, buffer, 1024, &len, NULL)) {
125+
warning("Could not read from xterm");
126+
return NULL;
127+
}
128+
129+
if (len && buffer[len - 1] == '\n')
130+
buffer[--len] = '\0';
131+
if (len && buffer[len - 1] == '\r')
132+
buffer[--len] = '\0';
133+
134+
if (!echo) {
135+
if(run_command_v_opt(echo_on, 0))
136+
warning("Could not re-enable echo on xterm");
137+
WriteFile(out_handle, "\n", 1, &dummy, NULL);
138+
}
139+
140+
return len == 0 ? NULL : buffer;
141+
}
142+
94143
#endif
95144

96145
#ifndef FORCE_TEXT
@@ -102,6 +151,12 @@ char *git_terminal_prompt(const char *prompt, int echo)
102151
static struct strbuf buf = STRBUF_INIT;
103152
int r;
104153
FILE *input_fh, *output_fh;
154+
#ifdef GIT_WINDOWS_NATIVE
155+
const char *term = getenv("TERM");
156+
157+
if (term && starts_with(term, "xterm"))
158+
return xterm_prompt(prompt, echo);
159+
#endif
105160

106161
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
107162
if (!input_fh)

0 commit comments

Comments
 (0)