summaryrefslogtreecommitdiff
path: root/imap-send.c
Commit message (Collapse)AuthorAgeFilesLines
* imap-send: include strbuf.hChristian Hesse2023-05-171-0/+1
| | | | | | | | | | We make liberal use of the strbuf API functions and types, but the inclusion of <strbuf.h> comes indirectly by including <http.h>, which does not happen if you build with NO_CURL. Signed-off-by: Christian Hesse <mail@eworm.de> Helped-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* setup.h: move declarations for setup.c functions from cache.hElijah Newren2023-03-211-0/+1
| | | | | Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* wrapper.h: move declarations for wrapper.c functions from cache.hElijah Newren2023-03-211-0/+1
| | | | | Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* treewide: be explicit about dependence on gettext.hElijah Newren2023-03-211-0/+1
| | | | | | | | | | | | | | Dozens of files made use of gettext functions, without explicitly including gettext.h. This made it more difficult to find which files could remove a dependence on cache.h. Make C files explicitly include gettext.h if they are using it. However, while compat/fsmonitor/fsm-ipc-darwin.c should also gain an include of gettext.h, it was left out to avoid conflicting with an in-flight topic. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* treewide: remove unnecessary cache.h includes in source filesElijah Newren2023-02-231-1/+1
| | | | | | | | | | | | | We had several C files include cache.h unnecessarily. Replace those with an include of "git-compat-util.h" instead. Much like the previous commit, these have all been verified via both ensuring that gcc -E $SOURCE_FILE | grep '"cache.h"' found no hits and that make DEVELOPER=1 ${OBJECT_FILE_FOR_SOURCE_FILE} successfully compiles without warnings. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'bc/csprng-mktemps'Junio C Hamano2022-04-061-1/+1
|\ | | | | | | | | | | | | Build fix. * bc/csprng-mktemps: git-compat-util: really support openssl as a source of entropy
| * git-compat-util: really support openssl as a source of entropyCarlo Marcelo Arenas Belón2022-04-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 05cd988dce5 (wrapper: add a helper to generate numbers from a CSPRNG, 2022-01-17), configure openssl as the source for entropy in NON-STOP but doesn't add the needed header or link options. Since the only system that is configured to use openssl as a source of entropy is NON-STOP, add the header unconditionally, and -lcrypto to the list of external libraries. An additional change is required to make sure a NO_OPENSSL=1 build will be able to work as well (tested on Linux with a modified value of CSPRNG_METHOD = openssl), and the more complex logic that allows for compatibility with APPLE_COMMON_CRYPTO or allowing for simpler ways to link (without libssl) has been punted for now. Reported-by: Randall Becker <rsbecker@nexbridge.com> Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap-send.c: use designated initializers for "struct imap_server_conf"Ævar Arnfjörð Bjarmason2022-02-241-11/+1
|/ | | | | | | | | Cut down a lot on the verbosity of the "server" assignment in imap-send.c using designated initializers, only the "ssl_verify" member was being set to a non-NULL non-0 value. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* http: centralize the accounting of libcurl dependenciesÆvar Arnfjörð Bjarmason2021-09-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As discussed in 644de29e220 (http: drop support for curl < 7.19.4, 2021-07-30) checking against LIBCURL_VERSION_NUM isn't as reliable as checking specific symbols present in curl, as some distros have been known to backport features. However, while some of the curl_easy_setopt() arguments we rely on are macros, others are enum, and we can't assume that those that are macros won't change into enums in the future. So we're still going to have to check LIBCURL_VERSION_NUM, but by doing that in one central place and using a macro definition of our own, anyone who's backporting features can define it themselves, and thus have access to more modern curl features that they backported, even if they didn't bump the LIBCURL_VERSION_NUM. More importantly, as shown in a preceding commit doing these version checks makes for hard to read and possibly buggy code, as shown by the bug fixed there where we were conflating base 10 for base 16 when comparing the version. By doing them all in one place we'll hopefully reduce the chances of such future mistakes, furthermore it now becomes easier to see at a glance what the oldest supported version is, which makes it easier to reason about any future deprecation similar to the recent e48a623dea0 (Merge branch 'ab/http-drop-old-curl', 2021-08-24). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'ab/http-drop-old-curl'Junio C Hamano2021-08-241-4/+0
|\ | | | | | | | | | | | | | | | | | | | | | | Support for ancient versions of cURL library (pre 7.19.4) has been dropped. * ab/http-drop-old-curl: http: rename CURLOPT_FILE to CURLOPT_WRITEDATA http: drop support for curl < 7.19.3 and < 7.17.0 (again) http: drop support for curl < 7.19.4 http: drop support for curl < 7.16.0 http: drop support for curl < 7.11.1
| * http: drop support for curl < 7.16.0Jeff King2021-07-301-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the last commit we dropped support for curl < 7.11.1, let's continue that and drop support for versions older than 7.16.0. This allows us to get rid of some now-obsolete #ifdefs. Choosing 7.16.0 is a somewhat arbitrary cutoff: 1. It came out in October of 2006, almost 15 years ago. Besides being a nice round number, around 10 years is a common end-of-life support period, even for conservative distributions. 2. That version introduced the curl_multi interface, which gives us a lot of bang for the buck in removing #ifdefs RHEL 5 came with curl 7.15.5[1] (released in August 2006). RHEL 5's extended life cycle program ended on 2020-11-30[1]. RHEL 6 comes with curl 7.19.7 (released in November 2009), and RHEL 7 comes with 7.29.0 (released in February 2013). 1. http://lore.kernel.org/git/873e1f31-2a96-5b72-2f20-a5816cad1b51@jupiterrise.com Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'ab/attribute-format'Junio C Hamano2021-07-281-0/+3
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many "printf"-like helper functions we have have been annotated with __attribute__() to catch placeholder/parameter mismatches. * ab/attribute-format: advice.h: add missing __attribute__((format)) & fix usage *.h: add a few missing __attribute__((format)) *.c static functions: add missing __attribute__((format)) sequencer.c: move static function to avoid forward decl *.c static functions: don't forward-declare __attribute__
| * | *.c static functions: add missing __attribute__((format))Ævar Arnfjörð Bjarmason2021-07-131-0/+3
| |/ | | | | | | | | | | | | | | Add missing __attribute__((format)) function attributes to various "static" functions that take printf arguments. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap-send.c: use less verbose strbuf_fread() idiomÆvar Arnfjörð Bjarmason2021-07-071-14/+2
|/ | | | | | | | | | | | | | | | When looking for things that hardcoded a non-zero "hint" parameter to strbuf_fread() I discovered that since f2561fda364 (Add git-imap-send, derived from isync 1.0.1., 2006-03-10) we've been passing a hardcoded 4096 in imap-send.c to read stdin. Since we're not doing anything unusual here let's use a less verbose pattern used in a lot of other places (the hint of "0" will default to 8192). We don't need to take a FILE * here either, so we can use "0" instead of "stdin". While we're at it improve the error message if we can't read the input to use error_errno(). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* use CALLOC_ARRAYRené Scharfe2021-03-131-2/+2
| | | | | | | | | Add and apply a semantic patch for converting code that open-codes CALLOC_ARRAY to use it instead. It shortens the code and infers the element size automatically. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* imap-send: parse default git configNicolas Morey-Chaisemartin2020-12-011-22/+30
| | | | | | | | | | git imap-send does not parse the default git config settings and thus ignore core.askpass value. Rewrite config parsing to support core settings. Reported-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* strvec: convert more callers away from argv_array nameJeff King2020-07-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | We eventually want to drop the argv_array name and just use strvec consistently. There's no particular reason we have to do it all at once, or care about interactions between converted and unconverted bits. Because of our preprocessor compat layer, the names are interchangeable to the compiler (so even a definition and declaration using different names is OK). This patch converts remaining files from the first half of the alphabet, to keep the diff to a manageable size. The conversion was done purely mechanically with: git ls-files '*.c' '*.h' | xargs perl -i -pe ' s/ARGV_ARRAY/STRVEC/g; s/argv_array/strvec/g; ' and then selectively staging files with "git add '[abcdefghjkl]*'". We'll deal with any indentation/style fallouts separately. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* http, imap-send: stop using CURLOPT_VERBOSEJonathan Tan2020-05-111-1/+1
| | | | | | | | | | | | | | | | | | Whenever GIT_CURL_VERBOSE is set, teach Git to behave as if GIT_TRACE_CURL=1 and GIT_TRACE_CURL_NO_DATA=1 is set, instead of setting CURLOPT_VERBOSE. This is to prevent inadvertent revelation of sensitive data. In particular, GIT_CURL_VERBOSE redacts neither the "Authorization" header nor any cookies specified by GIT_REDACT_COOKIES. Unifying the tracing mechanism also has the future benefit that any improvements to the tracing mechanism will benefit both users of GIT_CURL_VERBOSE and GIT_TRACE_CURL, and we do not need to remember to implement any improvement twice. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'nd/imap-send-typofix'Junio C Hamano2019-02-121-1/+1
|\ | | | | | | | | * nd/imap-send-typofix: imap-send.c: add a missing space in error message
| * imap-send.c: add a missing space in error messageNguyễn Thái Ngọc Duy2019-02-111-1/+1
| | | | | | | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | style: the opening '{' of a function is in a separate lineNguyễn Thái Ngọc Duy2018-12-101-1/+2
|/ | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Replace all die("BUG: ...") calls by BUG() onesJohannes Schindelin2018-05-061-1/+1
| | | | | | | | | | | | | | | | | | | | | In d8193743e08 (usage.c: add BUG() function, 2017-05-12), a new macro was introduced to use for reporting bugs instead of die(). It was then subsequently used to convert one single caller in 588a538ae55 (setup_git_env: convert die("BUG") to BUG(), 2017-05-12). The cover letter of the patch series containing this patch (cf 20170513032414.mfrwabt4hovujde2@sigill.intra.peff.net) is not terribly clear why only one call site was converted, or what the plan is for other, similar calls to die() to report bugs. Let's just convert all remaining ones in one fell swoop. This trick was performed by this invocation: sed -i 's/die("BUG: /BUG("/g' $(git grep -l 'die("BUG' \*.c) Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* exec_cmd: rename to use dash in file nameStefan Beller2018-04-111-1/+1
| | | | | | | This is more consistent with the project style. The majority of Git's source files use dashes in preference to underscores in their file names. Signed-off-by: Stefan Beller <sbeller@google.com>
* imap-send: rename 'new' variablesBrandon Williams2018-02-221-7/+7
| | | | | | | | Rename C++ keyword in order to bring the codebase closer to being able to be compiled with a C++ compiler. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* imap-send: URI encode server foldernm/imap-send-quote-server-folder-nameNicolas Morey-Chaisemartin2017-12-181-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to send a patch using 'imap-send' with 'curl' and the following configuration: [imap] folder = "[Gmail]/Drafts" host = imaps://imap.gmail.com port = 993 sslverify = false results in the following error, curl_easy_perform() failed: URL using bad/illegal format or missing URL This is a consequence of not URI-encoding the folder portion of the URL which contains characters such as '[' which are not allowed in a URI. According to RFC3986, these characters should be URI-encoded. So, URI-encode the folder before adding it to the URI to ensure it doesn't contain characters that aren't allowed in a URI. Reported-by: Doron Behar <doron.behar@gmail.com> Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com> Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'tz/fsf-address-update'Junio C Hamano2017-11-151-2/+1
|\ | | | | | | | | | | * tz/fsf-address-update: Replace Free Software Foundation address in license notices Replace Free Software Foundation address in license notices
| * Replace Free Software Foundation address in license noticesTodd Zullinger2017-11-091-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The mailing address for the FSF has changed over the years. Rather than updating the address across all files, refer readers to gnu.org, as the GNU GPL documentation now suggests for license notices. The mailing address is retained in the full license files (COPYING and LGPL-2.1). The old address is still present in t/diff-lib/COPYING. This is intentional, as the file is used in tests and the contents are not expected to change. Signed-off-by: Todd Zullinger <tmz@pobox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'rs/imap-send-next-arg-fix'Junio C Hamano2017-11-151-2/+13
|\ \ | |/ |/| | | | | | | | | | | | | Error checking in "git imap-send" for empty response has been improved. * rs/imap-send-next-arg-fix: imap-send: handle missing response codes gracefully imap-send: handle NULL return of next_arg()
| * imap-send: handle missing response codes gracefullyrs/imap-send-next-arg-fixRené Scharfe2017-11-031-1/+1
| | | | | | | | | | | | | | | | | | | | Response codes are optional. Exit parse_response_code() early if it's passed a NULL string, indicating that we reached the end of the reply. This avoids dereferencing said NULL pointer. Noticed-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * imap-send: handle NULL return of next_arg()René Scharfe2017-11-031-1/+12
| | | | | | | | | | | | | | | | | | | | | | next_arg() returns NULL if it runs out of arguments. Most call sites already handle that gracefully. Check in the remaining cases as well. Replace the NULL pointer with an empty string at the bottom of get_cmd_result() -- it's nicely reported as an unexpected response a few lines down. Error out explicitly at the remaining sites. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap-send: use curl by default when possiblenm/imap-send-with-curlNicolas Morey-Chaisemartin2017-09-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Set curl as the runtime default when it is available. When linked against older curl versions (< 7_34_0) or without curl, use the legacy imap implementation. The goal is to validate feature parity between the legacy and the curl implementation, deprecate the legacy implementation later on and in the long term, hopefully drop it altogether. Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap_send: setup_curl: retreive credentials if not set in config fileNicolas Morey-Chaisemartin2017-09-151-2/+17
| | | | | | | | | | | | | | | | | | Up to this point, the curl mode only supported getting the username and password from the gitconfig file while the legacy mode could also fetch them using the credential API. Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap-send: add wrapper to get server credentials if neededNicolas Morey-Chaisemartin2017-09-151-14/+20
| | | | | | | | | | Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | imap-send: return with error if curl failedNicolas Morey-Chaisemartin2017-09-151-1/+1
| | | | | | | | | | | | | | | | | | curl_append_msgs_to_imap always returned 0, whether curl failed or not. Return a proper status so git imap-send will exit with an error code if something wrong happened. Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'rs/use-div-round-up'Junio C Hamano2017-07-121-1/+1
|\ \ | | | | | | | | | | | | | | | | | | Code cleanup. * rs/use-div-round-up: use DIV_ROUND_UP
| * | use DIV_ROUND_UPrs/use-div-round-upRené Scharfe2017-07-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Convert code that divides and rounds up to use DIV_ROUND_UP to make the intent clearer and reduce the number of magic constants. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'ab/free-and-null'Junio C Hamano2017-06-241-2/+1
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common pattern to free a piece of memory and assign NULL to the pointer that used to point at it has been replaced with a new FREE_AND_NULL() macro. * ab/free-and-null: *.[ch] refactoring: make use of the FREE_AND_NULL() macro coccinelle: make use of the "expression" FREE_AND_NULL() rule coccinelle: add a rule to make "expression" code use FREE_AND_NULL() coccinelle: make use of the "type" FREE_AND_NULL() rule coccinelle: add a rule to make "type" code use FREE_AND_NULL() git-compat-util: add a FREE_AND_NULL() wrapper around free(ptr); ptr = NULL
| * | | coccinelle: make use of the "type" FREE_AND_NULL() ruleÆvar Arnfjörð Bjarmason2017-06-161-2/+1
| |/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | Apply the result of the just-added coccinelle rule. This manually excludes a few occurrences, mostly things that resulted in many FREE_AND_NULL() on one line, that'll be manually fixed in a subsequent change. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | config: don't include config.h by defaultBrandon Williams2017-06-151-0/+1
|/ / | | | | | | | | | | | | | | Stop including config.h by default in cache.h. Instead only include config.h in those files which require use of the config system. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | convert unchecked snprintf into xsnprintfJeff King2017-03-301-1/+1
|/ | | | | | | | | | | | | | | | | | | | | | These calls to snprintf should always succeed, because their input is small and fixed. Let's use xsnprintf to make sure this is the case (and to make auditing for actual truncation easier). These could be candidates for turning into heap buffers, but they fall into a few broad categories that make it not worth doing: - formatting single numbers is simple enough that we can see the result should fit - the size of a sha1 is likewise well-known, and I didn't want to cause unnecessary conflicts with the ongoing process to convert these constants to GIT_MAX_HEXSZ - the interface for curl_errorstr is dictated by curl Signed-off-by: Jeff King <peff@peff.net>
* Merge branch 'jc/cocci-xstrdup-or-null'Junio C Hamano2016-10-261-4/+2
|\ | | | | | | | | | | | | Code cleanup. * jc/cocci-xstrdup-or-null: cocci: refactor common patterns to use xstrdup_or_null()
| * cocci: refactor common patterns to use xstrdup_or_null()jc/cocci-xstrdup-or-nullJunio C Hamano2016-10-121-4/+2
| | | | | | | | | | | | | | | | | | d64ea0f83b ("git-compat-util: add xstrdup_or_null helper", 2015-01-12) added a handy wrapper that allows us to get a duplicate of a string or NULL if the original is NULL, but a handful of codepath predate its introduction or just weren't aware of it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'ak/curl-imap-send-explicit-scheme'Junio C Hamano2016-10-101-0/+1
|\ \ | |/ |/| | | | | | | | | | | | | | | When we started cURL to talk to imap server when a new enough version of cURL library is available, we forgot to explicitly add imap(s):// before the destination. To some folks, that didn't work and the library tried to make HTTP(s) requests instead. * ak/curl-imap-send-explicit-scheme: imap-send: Tell cURL to use imap:// or imaps://
| * imap-send: Tell cURL to use imap:// or imaps://ak/curl-imap-send-explicit-schemeAnders Kaseorg2016-08-171-0/+1
| | | | | | | | | | | | | | | | | | | | Right now the imap:// or imaps:// part of imap.host is not being passed on to cURL. Perhaps it was able to guess correctly under some circumstances, but I was not able to find one; it was just trying to make HTTP requests for me. It’s better to be explicit in any case. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | die("bug"): report bugs consistentlyJohannes Schindelin2016-07-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The vast majority of error messages in Git's source code which report a bug use the convention to prefix the message with "BUG:". As part of cleaning up merge-recursive to stop die()ing except in case of detected bugs, let's just make the remainder of the bug reports consistent with the de facto rule. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'jk/common-main'Junio C Hamano2016-07-191-5/+1
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are certain house-keeping tasks that need to be performed at the very beginning of any Git program, and programs that are not built-in commands had to do them exactly the same way as "git" potty does. It was easy to make mistakes in one-off standalone programs (like test helpers). A common "main()" function that calls cmd_main() of individual program has been introduced to make it harder to make mistakes. * jk/common-main: mingw: declare main()'s argv as const common-main: call git_setup_gettext() common-main: call restore_sigpipe_to_default() common-main: call sanitize_stdfds() common-main: call git_extract_argv0_path() add an extra level of indirection to main()
| * | common-main: call git_setup_gettext()Jeff King2016-07-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | common-main: call git_extract_argv0_path()Jeff King2016-07-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ae5f677 (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 ae5f677), 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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | add an extra level of indirection to main()Jeff King2016-07-011-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * Merge branch 'ky/imap-send-openssl-1.1.0' into maintJunio C Hamano2016-05-061-10/+10
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Upcoming OpenSSL 1.1.0 will break compilation b updating a few APIs we use in imap-send, which has been adjusted for the change. * ky/imap-send-openssl-1.1.0: configure: remove checking for HMAC_CTX_cleanup imap-send: avoid deprecated TLSv1_method() imap-send: check NULL return of SSL_CTX_new() imap-send: use HMAC() function provided by OpenSSL