1. 02 7月, 2016 3 次提交
    • J
      common-main: call git_setup_gettext() · 5ce5f5fa
      Jeff King 提交于
      This should be part of every program, as otherwise users do
      not get translated error messages. However, some external
      commands forgot to do so (e.g., git-credential-store). This
      fixes them, and eliminates the repeated code in programs
      that did remember to use it.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      5ce5f5fa
    • J
      common-main: call git_extract_argv0_path() · 650c4492
      Jeff King 提交于
      Every program which links against libgit.a must call this
      function, or risk hitting an assert() in system_path() that
      checks whether we have configured argv0_path (though only
      when RUNTIME_PREFIX is defined, so essentially only on
      Windows).
      
      Looking at the diff, you can see that putting it into the
      common main() saves us having to do it individually in each
      of the external commands. But what you can't see are the
      cases where we _should_ have been doing so, but weren't
      (e.g., git-credential-store, and all of the t/helper test
      programs).
      
      This has been an accident-waiting-to-happen for a long time,
      but wasn't triggered until recently because it involves one
      of those programs actually calling system_path(). That
      happened with git-credential-store in v2.8.0 with ae5f6776
      (lazily load core.sharedrepository, 2016-03-11). The
      program:
      
        - takes a lock file, which...
      
        - opens a tempfile, which...
      
        - calls adjust_shared_perm to fix permissions, which...
      
        - lazy-loads the config (as of ae5f6776), which...
      
        - calls system_path() to find the location of
          /etc/gitconfig
      
      On systems with RUNTIME_PREFIX, this means credential-store
      reliably hits that assert() and cannot be used.
      
      We never noticed in the test suite, because we set
      GIT_CONFIG_NOSYSTEM there, which skips the system_path()
      lookup entirely.  But if we were to tweak git_config() to
      find /etc/gitconfig even when we aren't going to open it,
      then the test suite shows multiple failures (for
      credential-store, and for some other test helpers). I didn't
      include that tweak here because it's way too specific to
      this particular call to be worth carrying around what is
      essentially dead code.
      
      The implementation is fairly straightforward, with one
      exception: there is exactly one caller (git.c) that actually
      cares about the result of the function, and not the
      side-effect of setting up argv0_path. We can accommodate
      that by simply replacing the value of argv[0] in the array
      we hand down to cmd_main().
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      650c4492
    • J
      add an extra level of indirection to main() · 3f2e2297
      Jeff King 提交于
      There are certain startup tasks that we expect every git
      process to do. In some cases this is just to improve the
      quality of the program (e.g., setting up gettext()). In
      others it is a requirement for using certain functions in
      libgit.a (e.g., system_path() expects that you have called
      git_extract_argv0_path()).
      
      Most commands are builtins and are covered by the git.c
      version of main(). However, there are still a few external
      commands that use their own main(). Each of these has to
      remember to include the correct startup sequence, and we are
      not always consistent.
      
      Rather than just fix the inconsistencies, let's make this
      harder to get wrong by providing a common main() that can
      run this standard startup.
      
      We basically have two options to do this:
      
       - the compat/mingw.h file already does something like this by
         adding a #define that replaces the definition of main with a
         wrapper that calls mingw_startup().
      
         The upside is that the code in each program doesn't need
         to be changed at all; it's rewritten on the fly by the
         preprocessor.
      
         The downside is that it may make debugging of the startup
         sequence a bit more confusing, as the preprocessor is
         quietly inserting new code.
      
       - the builtin functions are all of the form cmd_foo(),
         and git.c's main() calls them.
      
         This is much more explicit, which may make things more
         obvious to somebody reading the code. It's also more
         flexible (because of course we have to figure out _which_
         cmd_foo() to call).
      
         The downside is that each of the builtins must define
         cmd_foo(), instead of just main().
      
      This patch chooses the latter option, preferring the more
      explicit approach, even though it is more invasive. We
      introduce a new file common-main.c, with the "real" main. It
      expects to call cmd_main() from whatever other objects it is
      linked against.
      
      We link common-main.o against anything that links against
      libgit.a, since we know that such programs will need to do
      this setup. Note that common-main.o can't actually go inside
      libgit.a, as the linker would not pick up its main()
      function automatically (it has no callers).
      
      The rest of the patch is just adjusting all of the various
      external programs (mostly in t/helper) to use cmd_main().
      I've provided a global declaration for cmd_main(), which
      means that all of the programs also need to match its
      signature. In particular, many functions need to switch to
      "const char **" instead of "char **" for argv. This effect
      ripples out to a few other variables and functions, as well.
      
      This makes the patch even more invasive, but the end result
      is much better. We should be treating argv strings as const
      anyway, and now all programs conform to the same signature
      (which also matches the way builtins are defined).
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3f2e2297
  2. 25 5月, 2016 1 次提交
  3. 14 4月, 2016 2 次提交
  4. 09 4月, 2016 3 次提交
  5. 23 2月, 2016 1 次提交
    • J
      use xmallocz to avoid size arithmetic · 3733e694
      Jeff King 提交于
      We frequently allocate strings as xmalloc(len + 1), where
      the extra 1 is for the NUL terminator. This can be done more
      simply with xmallocz, which also checks for integer
      overflow.
      
      There's no case where switching xmalloc(n+1) to xmallocz(n)
      is wrong; the result is the same length, and malloc made no
      guarantees about what was in the buffer anyway. But in some
      cases, we can stop manually placing NUL at the end of the
      allocated buffer. But that's only safe if it's clear that
      the contents will always fill the buffer.
      
      In each case where this patch does so, I manually examined
      the control flow, and I tried to err on the side of caution.
      Signed-off-by: NJeff King <peff@peff.net>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      3733e694
  6. 27 10月, 2015 1 次提交
  7. 26 9月, 2015 1 次提交
  8. 11 3月, 2015 1 次提交
  9. 07 1月, 2015 2 次提交
    • K
      imap-send.c: set CURLOPT_USE_SSL to CURLUSESSL_TRY · 230c09c0
      Kyle J. McKay 提交于
      According to the cURL documentation for the CURLOPT_USE_SSL option,
      it is only used with plain text protocols that get upgraded to SSL
      using the STARTTLS command.
      
      The server.use_ssl variable is only set when we are using a protocol
      that is already SSL/TLS (i.e. imaps), so setting CURLOPT_USE_SSL
      when the server.use_ssl variable is set has no effect whatsoever.
      
      Instead, set CURLOPT_USE_SSL to CURLUSESSL_TRY when the server.use_ssl
      variable is NOT set so that cURL will attempt to upgrade the plain
      text connection to SSL/TLS using STARTTLS in that case.
      
      This much more closely matches the behavior of the non-cURL code path.
      Signed-off-by: NKyle J. McKay <mackyle@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      230c09c0
    • K
      imap-send.c: support GIT_CURL_VERBOSE · d47e55da
      Kyle J. McKay 提交于
      When using git-imap-send to send via cURL, support setting
      the GIT_CURL_VERBOSE environment variable to enable cURL's
      verbose mode.
      
      The existing http.c code already supports this and does
      it by simply checking to see whether or not the environment
      variable exists -- it does not examine the value at all.
      
      For consistency, enable CURLOPT_VERBOSE when GIT_CURL_VERBOSE
      is set by using the exact same test that http.c does.
      Signed-off-by: NKyle J. McKay <mackyle@gmail.com>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      d47e55da
  10. 11 11月, 2014 1 次提交
    • B
      git-imap-send: use libcurl for implementation · 1e16b255
      Bernhard Reiter 提交于
      Use libcurl's high-level API functions to implement git-imap-send
      instead of the previous low-level OpenSSL-based functions.
      
      Since version 7.30.0, libcurl's API has been able to communicate with
      IMAP servers. Using those high-level functions instead of the current
      ones would reduce imap-send.c by some 1200 lines of code. For now,
      the old ones are wrapped in #ifdefs, and the new functions are enabled
      by make if curl's version is >= 7.34.0, from which version on curl's
      CURLOPT_LOGIN_OPTIONS (enabling IMAP authentication) parameter has been
      available. The low-level functions will still be used for tunneling
      into the server for now.
      
      As I don't have access to that many IMAP servers, I haven't been able to
      test the new code with a wide variety of parameter combinations. I did
      test both secure and insecure (imaps:// and imap://) connections and
      values of "PLAIN" and "LOGIN" for the authMethod.
      
      In order to suppress a sparse warning about "using sizeof on a
      function", we use the same solution used in commit 9371322a
      ("sparse: suppress some "using sizeof on a function" warnings",
      06-10-2013) which solved exactly this problem for the other commands
      using libcurl.
      Helped-by: NRamsay Jones <ramsay@ramsay1.demon.co.uk>
      Signed-off-by: NBernhard Reiter <ockham@raz.or.at>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1e16b255
  11. 06 11月, 2014 1 次提交
  12. 04 9月, 2014 1 次提交
  13. 03 9月, 2014 1 次提交
  14. 26 8月, 2014 1 次提交
    • T
      imap-send: create target mailbox if it is missing · e0d8e308
      Tony Finch 提交于
      Some MUAs delete their "drafts" folder when it is empty, so
      git imap-send should be able to create it if necessary.
      
      This change checks that the folder exists immediately after
      login and tries to create it if it is missing.
      
      There was some vestigial code to handle a [TRYCREATE] response
      from the server when an APPEND target is missing. However this
      code never ran (the create and trycreate flags were never set)
      and when I tried to make it run I found that the code had already
      thrown away the contents of the message it was trying to append.
      Signed-off-by: NTony Finch <dot@dotat.at>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      e0d8e308
  15. 21 8月, 2014 2 次提交
  16. 19 8月, 2014 1 次提交
  17. 08 8月, 2014 1 次提交
  18. 21 6月, 2014 1 次提交
  19. 28 5月, 2014 1 次提交
  20. 30 4月, 2014 1 次提交
  21. 06 12月, 2013 1 次提交
    • C
      replace {pre,suf}fixcmp() with {starts,ends}_with() · 59556548
      Christian Couder 提交于
      Leaving only the function definitions and declarations so that any
      new topic in flight can still make use of the old functions, replace
      existing uses of the prefixcmp() and suffixcmp() with new API
      functions.
      
      The change can be recreated by mechanically applying this:
      
          $ git grep -l -e prefixcmp -e suffixcmp -- \*.c |
            grep -v strbuf\\.c |
            xargs perl -pi -e '
              s|!prefixcmp\(|starts_with\(|g;
              s|prefixcmp\(|!starts_with\(|g;
              s|!suffixcmp\(|ends_with\(|g;
              s|suffixcmp\(|!ends_with\(|g;
            '
      
      on the result of preparatory changes in this series.
      Signed-off-by: NChristian Couder <chriscool@tuxfamily.org>
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      59556548
  22. 30 7月, 2013 1 次提交
  23. 22 5月, 2013 1 次提交
  24. 21 2月, 2013 1 次提交
  25. 20 2月, 2013 2 次提交
  26. 19 2月, 2013 1 次提交
    • J
      imap-send: move #ifdef around · 1e1fe529
      Junio C Hamano 提交于
      Instead of adding an early return to the inside of the
      ssl_socket_connect() function for NO_OPENSSL compilation, split it
      into a separate stub function.
      
      No functional change, but the next change to extend ssl_socket_connect()
      will become easier to read this way.
      Signed-off-by: NJunio C Hamano <gitster@pobox.com>
      1e1fe529
  27. 16 1月, 2013 6 次提交