Skip to content

Commit

Permalink
Merge 'git-wrapper' into HEAD
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 29, 2015
2 parents a4b0473 + e48c937 commit 8195392
Show file tree
Hide file tree
Showing 4 changed files with 558 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1655,11 +1655,17 @@ version.sp version.s version.o: EXTRA_CPPFLAGS = \
'-DGIT_VERSION="$(GIT_VERSION)"' \
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'

ifeq (,$(BUILT_IN_WRAPPER))
$(BUILT_INS): git$X
$(QUIET_BUILT_IN)$(RM) $@ && \
ln $< $@ 2>/dev/null || \
ln -s $< $@ 2>/dev/null || \
cp $< $@
else
$(BUILT_INS): $(BUILT_IN_WRAPPER)
$(QUIET_BUILT_IN)$(RM) $@ && \
cp $< $@
endif

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

Expand Down Expand Up @@ -2222,6 +2228,24 @@ profile-install: profile
profile-fast-install: profile-fast
$(MAKE) install

ifeq (,$(BUILT_IN_WRAPPER))
LN_OR_CP_BUILT_IN_BINDIR = \
test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
cp "$$bindir/git$X" "$$bindir/$$p" || exit;
LN_OR_CP_BUILT_IN_EXECDIR = \
test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$exectir/git$X" "$$exectir/$$p" 2>/dev/null || \
ln -s "git$X" "$$exectir/$$p" 2>/dev/null || \
cp "$$exectir/git$X" "$$exectir/$$p" || exit;
else
LN_OR_CP_BUILT_IN_BINDIR = \
cp "$(BUILT_IN_WRAPPER)" "$$bindir/$$p" || exit;
LN_OR_CP_BUILT_IN_EXECDIR = \
cp "$(BUILT_IN_WRAPPER)" "$$execdir/$$p" || exit;
endif

install: all
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
Expand Down Expand Up @@ -2260,17 +2284,11 @@ endif
} && \
for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \
$(RM) "$$bindir/$$p" && \
test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \
ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \
cp "$$bindir/git$X" "$$bindir/$$p" || exit; \
$(LN_OR_CP_BUILT_IN_BINDIR) \
done && \
for p in $(BUILT_INS); do \
$(RM) "$$execdir/$$p" && \
test -z "$(NO_INSTALL_HARDLINKS)" && \
ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \
ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \
cp "$$execdir/git$X" "$$execdir/$$p" || exit; \
$(LN_OR_CP_BUILT_IN_EXECDIR) \
done && \
remote_curl_aliases="$(REMOTE_CURL_ALIASES)" && \
for p in $$remote_curl_aliases; do \
Expand Down
55 changes: 55 additions & 0 deletions compat/terminal.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <inttypes.h>
#include "git-compat-util.h"
#include "run-command.h"
#include "compat/terminal.h"
#include "sigchain.h"
#include "strbuf.h"
Expand Down Expand Up @@ -91,6 +93,53 @@ static int disable_echo(void)
return 0;
}

static char *xterm_prompt(const char *prompt, int echo)
{
const char *env = getenv("MSYS_TTY_HANDLES");
const char *echo_off[] = { "sh", "-c", "stty -echo </dev/tty", NULL };
const char *echo_on[] = { "sh", "-c", "stty echo </dev/tty", NULL };
static char buffer[1024];
DWORD len, dummy;
size_t tty0, tty1, tty2;
HANDLE in_handle, out_handle;

if (!env || 3 != sscanf(env,
" %" SCNuPTR " %" SCNuPTR " %" SCNuPTR " ",
&tty0, &tty1, &tty2)) {
warning("Cannot read from xterm");
return NULL;
}

in_handle = (HANDLE)tty0;
out_handle = (HANDLE)tty1;

if (!echo && run_command_v_opt(echo_off, 0))
warning("Could not disable echo on xterm");

if (!WriteFile(out_handle, prompt, strlen(prompt), &dummy, NULL)) {
warning("Could not write to xterm");
return NULL;
}

if (!ReadFile(in_handle, buffer, 1024, &len, NULL)) {
warning("Could not read from xterm");
return NULL;
}

if (len && buffer[len - 1] == '\n')
buffer[--len] = '\0';
if (len && buffer[len - 1] == '\r')
buffer[--len] = '\0';

if (!echo) {
if(run_command_v_opt(echo_on, 0))
warning("Could not re-enable echo on xterm");
WriteFile(out_handle, "\n", 1, &dummy, NULL);
}

return len == 0 ? NULL : buffer;
}

#endif

#ifndef FORCE_TEXT
Expand All @@ -102,6 +151,12 @@ char *git_terminal_prompt(const char *prompt, int echo)
static struct strbuf buf = STRBUF_INIT;
int r;
FILE *input_fh, *output_fh;
#ifdef GIT_WINDOWS_NATIVE
const char *term = getenv("TERM");

if (term && starts_with(term, "xterm"))
return xterm_prompt(prompt, echo);
#endif

input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
if (!input_fh)
Expand Down
Loading

0 comments on commit 8195392

Please sign in to comment.