1. 24 8月, 2016 1 次提交
    • B
      mingw: ensure temporary file handles are not inherited by child processes · 05d1ed61
      Ben Wijen 提交于
      When the index is locked and child processes inherit the handle to
      said lock and the parent process wants to remove the lock before the
      child process exits, on Windows there is a problem: it won't work
      because files cannot be deleted if a process holds a handle on them.
      The symptom:
      
          Rename from 'xxx/.git/index.lock' to 'xxx/.git/index' failed.
          Should I try again? (y/n)
      
      Spawning child processes with bInheritHandles==FALSE would not work
      because no file handles would be inherited, not even the hStdXxx
      handles in STARTUPINFO (stdin/stdout/stderr).
      
      Opening every file with O_NOINHERIT does not work, either, as e.g.
      git-upload-pack expects inherited file handles.
      
      This leaves us with the only way out: creating temp files with the
      O_NOINHERIT flag. This flag is Windows-specific, however. For our
      purposes, it is equivalent to O_CLOEXEC (which does not exist on
      Windows), so let's just open temporary files with the O_CLOEXEC flag and
      map that flag to O_NOINHERIT on Windows.
      
      As Eric Wong pointed out, we need to be careful to handle the case where
      the Linux headers used to compile Git support O_CLOEXEC but the Linux
      kernel used to run Git does not: it returns an EINVAL.
      
      This fixes the test that we just introduced to demonstrate the problem.
      Signed-off-by: NBen Wijen <ben@wijen.net>
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      05d1ed61
  2. 20 8月, 2016 1 次提交
  3. 23 7月, 2016 1 次提交
  4. 06 7月, 2016 1 次提交
  5. 21 6月, 2016 1 次提交
  6. 12 5月, 2016 1 次提交
  7. 03 5月, 2016 1 次提交
    • J
      Windows: add pthread_sigmask() that does nothing · f924b52a
      Johannes Sixt 提交于
      A previous change introduced a call to pthread_sigmask() in order to block
      SIGPIPE in a thread. Since there are no signal facilities on Windows that
      are similar to POSIX signals, just ignore the request to block the signal.
      In the particular case, the effect of blocking SIGPIPE on POSIX is that
      write() calls return EPIPE when the reader closes the pipe. This is how
      write() behaves on Windows.
      Signed-off-by: NJohannes Sixt <j6t@kdbg.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      f924b52a
  8. 31 3月, 2016 1 次提交
  9. 24 3月, 2016 1 次提交
  10. 26 1月, 2016 1 次提交
    • J
      mingw: avoid linking to the C library's isalpha() · e7d5ce81
      Johannes Sixt 提交于
      The implementation of mingw_skip_dos_drive_prefix() calls isalpha() via
      has_dos_drive_prefix(). Since the definition occurs long before isalpha()
      is defined in git-compat-util.h, my build environment reports:
      
          CC alloc.o
      In file included from git-compat-util.h:186,
                       from cache.h:4,
                       from alloc.c:12:
      compat/mingw.h: In function 'mingw_skip_dos_drive_prefix':
      compat/mingw.h:365: warning: implicit declaration of function 'isalpha'
      
      Dscho does not see a similar warning in his build and suspects that
      ctype.h is included somehow behind the scenes. This implies that his build
      links to the C library's isalpha() and does not use git's isalpha().
      
      To fix both the warning in my build and the inconsistency in Dscho's
      build, move the function definition to mingw.c. Then it picks up git's
      isalpha() because git-compat-util.h is included at the top of the file.
      Signed-off-by: NJohannes Sixt <j6t@kdbg.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e7d5ce81
  11. 16 1月, 2016 1 次提交
  12. 15 1月, 2016 1 次提交
  13. 13 1月, 2016 1 次提交
    • J
      Refactor skipping DOS drive prefixes · 2f36eed9
      Johannes Schindelin 提交于
      Junio noticed that there is an implicit assumption in pretty much
      all the code calling has_dos_drive_prefix(): it forces all of its
      callsites to hardcode the knowledge that the DOS drive prefix is
      always two bytes long.
      
      While this assumption is pretty safe, we can still make the code
      more readable and less error-prone by introducing a function that
      skips the DOS drive prefix safely.
      
      While at it, we change the has_dos_drive_prefix() return value: it
      now returns the number of bytes to be skipped if there is a DOS
      drive prefix.
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      2f36eed9
  14. 22 12月, 2015 1 次提交
  15. 16 4月, 2015 1 次提交
  16. 13 3月, 2015 1 次提交
  17. 23 9月, 2014 1 次提交
  18. 22 7月, 2014 3 次提交
    • K
      Win32: don't copy the environment twice when spawning child processes · 77734da2
      Karsten Blees 提交于
      When spawning child processes via start_command(), the environment and all
      environment entries are copied twice. First by make_augmented_environ /
      copy_environ to merge with child_process.env. Then a second time by
      make_environment_block to create a sorted environment block string as
      required by CreateProcess.
      
      Move the merge logic to make_environment_block so that we only need to copy
      the environment once. This changes semantics of the env parameter: it now
      expects a delta (such as child_process.env) rather than a full environment.
      This is not a problem as the parameter is only used by start_command()
      (all other callers previously passed char **environ, and now pass NULL).
      
      The merge logic no longer xstrdup()s the environment strings, so do_putenv
      must not free them. Add a parameter to distinguish this from normal putenv.
      
      Remove the now unused make_augmented_environ / free_environ API.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      77734da2
    • K
      Win32: fix environment memory leaks · e96942e8
      Karsten Blees 提交于
      All functions that modify the environment have memory leaks.
      
      Disable gitunsetenv in the Makefile and use env_setenv (via mingw_putenv)
      instead (this frees removed environment entries).
      
      Move xstrdup from env_setenv to make_augmented_environ, so that
      mingw_putenv no longer copies the environment entries (according to POSIX
      [1], "the string [...] shall become part of the environment"). This also
      fixes the memory leak in gitsetenv, which expects a POSIX compliant putenv.
      
      [1] http://pubs.opengroup.org/onlinepubs/009695399/functions/putenv.html
      
      Note: This patch depends on taking control of char **environ and having
      our own mingw_putenv (both introduced in "Win32: Unicode environment
      (incoming)").
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e96942e8
    • K
      Win32: Unicode environment (incoming) · b729f98f
      Karsten Blees 提交于
      Convert environment from UTF-16 to UTF-8 on startup.
      
      No changes to getenv() are necessary, as the MSVCRT version is implemented
      on top of char **environ.
      
      However, putenv / _wputenv from MSVCRT no longer work, for two reasons:
      1. they try to keep environ, _wenviron and the Win32 process environment
      in sync, using the default system encoding instead of UTF-8 to convert
      between charsets
      2. msysgit and MSVCRT use different allocators, memory allocated in git
      cannot be freed by the CRT and vice versa
      
      Implement mingw_putenv using the env_setenv helper function from the
      environment merge code.
      
      Note that in case of memory allocation failure, putenv now dies with error
      message (due to xrealloc) instead of failing with ENOMEM. As git assumes
      setenv / putenv to always succeed, this prevents it from continuing with
      incorrect settings.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      b729f98f
  19. 17 7月, 2014 1 次提交
  20. 16 7月, 2014 1 次提交
    • K
      Win32: Unicode file name support (except dirent) · 85faec9d
      Karsten Blees 提交于
      Replaces Windows "ANSI" APIs dealing with file- or path names with their
      Unicode equivalent, adding UTF-8/UTF-16LE conversion as necessary.
      
      The dirent API (opendir/readdir/closedir) is updated in a separate commit.
      
      Adds trivial wrappers for access, chmod and chdir.
      
      Adds wrapper for mktemp (needed for both mkstemp and mkdtemp).
      
      The simplest way to convert a repository with legacy-encoded (e.g. Cp1252)
      file names to UTF-8 ist to checkout with an old msysgit version and
      "git add --all & git commit" with the new version.
      
      Includes a fix for bug reported by John Chen:
      On Windows XP (not Win7), directories cannot be deleted while a find handle
      is open, causing "Deletion of directory '...' failed. Should I try again?"
      prompts.
      
      Prior to this commit, these failures were silently ignored due to
      strbuf_free in is_dir_empty resetting GetLastError to ERROR_SUCCESS.
      
      Close the find handle in is_dir_empty so that git doesn't block deletion
      of the directory even after all other applications have released it.
      Reported-by: NJohn Chen <john0312@gmail.com>
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      85faec9d
  21. 11 6月, 2014 7 次提交
    • K
      Win32: fix broken pipe detection · fcd428f4
      Karsten Blees 提交于
      As of "Win32: Thread-safe windows console output", git-log no longer
      terminates when the pager process dies. This is due to disabling buffering
      for the replaced stdout / stderr streams. Git-log will periodically fflush
      stdout (see write_or_die.c/mayble_flush_or_die()), but with no buffering,
      this is a NOP that always succeeds (so we never detect the EPIPE error).
      
      Exchange the original console handles with our console thread pipe handles
      by accessing the internal MSVCRT data structures directly (which are
      exposed via __pioinfo for some reason).
      
      Implement this with minimal assumptions about the actual data structure to
      make it work with different (hopefully even future) MSVCRT versions.
      
      While messing with internal data structures is ugly, this patch solves the
      problem at the source instead of adding more workarounds. We no longer need
      the special winansi_isatty override, and the limitations documented in
      "Win32: Thread-safe windows console output" are gone (i.e. fdopen(1/2)
      returns unbuffered streams now, and isatty() for duped console file
      descriptors works as expected).
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      fcd428f4
    • K
      Win32: Thread-safe windows console output · eac14f89
      Karsten Blees 提交于
      Winansi.c has many static variables that are accessed and modified from
      the [v][f]printf / fputs functions overridden in the file. This may cause
      multi threaded git commands that print to the console to produce corrupted
      output or even crash.
      
      Additionally, winansi.c doesn't override all functions that can be used to
      print to the console (e.g. fwrite, write, fputc are missing), so that ANSI
      escapes don't work properly for some git commands (e.g. git-grep).
      
      Instead of doing ANSI emulation in just a few wrapped functions on top of
      the IO API, let's plug into the IO system and take advantage of the thread
      safety inherent to the IO system.
      
      Redirect stdout and stderr to a pipe if they point to the console. A
      background thread reads from the pipe, handles ANSI escape sequences and
      UTF-8 to UTF-16 conversion, then writes to the console.
      
      The pipe-based stdout and stderr replacements must be set to unbuffered, as
      MSVCRT doesn't support line buffering and fully buffered streams are
      inappropriate for console output.
      
      Due to the byte-oriented pipe, ANSI escape sequences and multi-byte UTF-8
      sequences can no longer be expected to arrive in one piece. Replace the
      string-based ansi_emulate() with a simple stateful parser (this also fixes
      colored diff hunk headers, which were broken as of commit 2efcc977).
      
      Override isatty to return true for the pipes redirecting to the console.
      
      Exec/spawn obtain the original console handle to pass to the next process
      via winansi_get_osfhandle().
      
      All other overrides are gone, the default stdio implementations work as
      expected with the piped stdout/stderr descriptors.
      
      Global variables are either initialized on startup (single threaded) or
      exclusively modified by the background thread. Threads communicate through
      the pipe, no further synchronization is necessary.
      
      The background thread is terminated by disonnecting the pipe after flushing
      the stdio and pipe buffers. This doesn't work for anonymous pipes (created
      via CreatePipe), as DisconnectNamedPipe only works on the read end, which
      discards remaining data. Thus we have to setup the pipe manually, with the
      write end beeing the server (opened with CreateNamedPipe) and the read end
      the client (opened with CreateFile).
      
      Limitations: doesn't track reopened or duped file descriptors, i.e.:
      - fdopen(1/2) returns fully buffered streams
      - dup(1/2), dup2(1/2) returns normal pipe descriptors (i.e. isatty() =
        false, winansi_get_osfhandle won't return the original console handle)
      
      Currently, only the git-format-patch command uses xfdopen(xdup(1)) (see
      "realstdout" in builtin/log.c), but works well with these limitations.
      
      Many thanks to Atsushi Nakagawa <atnak@chejz.com> for suggesting and
      reviewing the thread-exit-mechanism.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      eac14f89
    • K
      Win32: add Unicode conversion functions · 1c950a59
      Karsten Blees 提交于
      Add Unicode conversion functions to convert between Windows native UTF-16LE
      encoding to UTF-8 and back.
      
      To support repositories with legacy-encoded file names, the UTF-8 to UTF-16
      conversion function tries to create valid, unique file names even for
      invalid UTF-8 byte sequences, so that these repositories can be checked out
      without error.
      
      The current implementation leaves invalid UTF-8 bytes in range 0xa0 - 0xff
      as is (producing printable Unicode chars \u00a0 - \u00ff, equivalent to
      ISO-8859-1), and converts 0x80 - 0x9f to hex-code (\u0080 - \u009f are
      control chars).
      
      The Windows MultiByteToWideChar API was not used as it either drops invalid
      UTF-8 sequences (on Win2k/XP; producing non-unique or even empty file
      names) or converts them to the replacement char \ufffd (Vista/7; causing
      ERROR_INVALID_NAME in subsequent calls to file system APIs).
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1c950a59
    • K
      Win32: support Unicode console output · 617ce965
      Karsten Blees 提交于
      WriteConsoleW seems to be the only way to reliably print unicode to the
      console (without weird code page conversions).
      
      Also redirects vfprintf to the winansi.c version.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      617ce965
    • S
      mingw: avoid const warning · a15d4af4
      Stepan Kasal 提交于
      Fix const warnings in http-fetch.c and remote-curl.c main() where is
      argv declared as const.
      
      The fix should work for all future declarations of main, no matter
      whether the second parameter's type is "char**", "const char**", or
      "char *[]".
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      a15d4af4
    • K
      Win32: move main macro to a function · 13f1df43
      Karsten Blees 提交于
      The code in the MinGW main macro is getting more and more complex, move to
      a separate initialization function for readabiliy and extensibility.
      Signed-off-by: NKarsten Blees <blees@dcon.de>
      Signed-off-by: NErik Faye-Lund <kusmabite@gmail.com>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      13f1df43
    • C
      Windows: allow using UNC path for git repository · c2369bdf
      Cezary Zawadka 提交于
      [efl: moved MinGW-specific part to compat/]
      [jes: fixed compilation on non-Windows]
      
      Eric Sunshine fixed mingw_offset_1st_component() to return
      consistently "foo" for UNC "//machine/share/foo", cf
      
      http://groups.google.com/group/msysgit/browse_thread/thread/c0af578549b5dda0
      
      Author: Eric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NCezary Zawadka <czawadka@gmail.com>
      Signed-off-by: NEric Sunshine <sunshine@sunshineco.com>
      Signed-off-by: NErik Faye-Lund <kusmabite@gmail.com>
      Signed-off-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
      Signed-off-by: NStepan Kasal <kasal@ucw.cz>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      c2369bdf
  22. 18 1月, 2014 1 次提交
  23. 20 9月, 2013 1 次提交
  24. 12 9月, 2013 3 次提交
  25. 29 4月, 2013 2 次提交
    • R
      sparse: Fix mingw_main() argument number/type errors · 84d32bf7
      Ramsay Jones 提交于
      Sparse issues 68 errors (two errors for each main() function) such
      as the following:
      
            SP git.c
        git.c:510:5: error: too many arguments for function mingw_main
        git.c:510:5: error: symbol 'mingw_main' redeclared with different type \
          (originally declared at git.c:510) - different argument counts
      
      The errors are caused by the 'main' macro used by the MinGW build
      to provide a replacement main() function. The original main function
      is effectively renamed to 'mingw_main' and is called from the new
      main function. The replacement main is used to execute certain actions
      common to all git programs on MinGW (e.g. ensure the standard I/O
      streams are in binary mode).
      
      In order to suppress the errors, we change the macro to include the
      parameters in the declaration of the mingw_main function.
      
      Unfortunately, this change provokes both sparse and gcc to complain
      about 9 calls to mingw_main(), such as the following:
      
            CC git.o
        git.c: In function 'main':
        git.c:510: warning: passing argument 2 of 'mingw_main' from \
          incompatible pointer type
        git.c:510: note: expected 'const char **' but argument is of \
          type 'char **'
      
      In order to suppress these warnings, since both of the main
      functions need to be declared with the same prototype, we
      change the declaration of the 9 main functions, thus:
      
          int main(int argc, char **argv)
      Signed-off-by: NRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      84d32bf7
    • R
      compat/mingw.c: Fix some sparse warnings · 657b35f4
      Ramsay Jones 提交于
      Sparse issues the following warnings:
      
              SP compat/mingw.c
          compat/mingw.c:795:3: warning: symbol 'pinfo_t' was not declared. \
              Should it be static?
          compat/mingw.c:796:16: warning: symbol 'pinfo' was not declared. \
              Should it be static?
          compat/mingw.c:797:18: warning: symbol 'pinfo_cs' was not declared. \
              Should it be static?
          compat/mingw.c:1207:23: warning: Using plain integer as NULL pointer
      
      In 'pinfo_t' variable, defined on line 795, seems to have been a
      mistake (a missing typedef keyword?), so we simply remove it.
      
      The 'pinfo' variable does not require more than file scope, so we
      simply add the static modifier to the declaration.
      
      The 'pinfo_cs' variable, in contrast, requires initialisation in the
      mingw replacement main() function, so we add an extern declaration to
      the compat/mingw.h header file.
      
      The remaining warning is suppressed by replacing the rhs of the
      pointer assignment with the NULL pointer literal.
      Signed-off-by: NRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      657b35f4
  26. 05 12月, 2012 2 次提交
  27. 17 10月, 2012 1 次提交
  28. 19 4月, 2012 1 次提交
    • R
      compat/mingw.h: Set S_ISUID to prevent a fast-import test failure · 90110d76
      Ramsay Jones 提交于
      The current t9300-fast-import.sh test number 62 ("L: nested tree
      copy does not corrupt deltas") was introduced in commit 9a0edb79
      ("fast-import: add a test for tree delta base corruption",
      15-08-2011). A fix for the demonstrated problem was introduced
      by commit 8fb3ad76 ("fast-import: prevent producing bad delta",
      15-08-2011). However, this fix didn't work on MinGW and so this
      test has always failed on MinGW.
      
      Part of the solution in commit 8fb3ad76 was to add an NO_DELTA
      preprocessor constant which was defined as follows:
      
        +/*
        + * We abuse the setuid bit on directories to mean "do not delta".
        + */
        +#define NO_DELTA S_ISUID
        +
      
      Unfortunately, the S_ISUID constant on MinGW is defined as zero.
      
      In order to fix the problem, we simply alter the definition of
      S_ISUID in the mingw header file to a more appropriate value.
      Also, we take the opportunity to similarly define S_ISGID and
      S_ISVTX.
      Signed-off-by: NRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      90110d76