From: Junio C Hamano Date: Tue, 25 Aug 2015 21:57:06 +0000 (-0700) Subject: Merge branch 'jk/long-error-messages' X-Git-Tag: v2.6.0-rc0~51 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/1302c9f514686e32065130ec9a80eb0db224e819?ds=inline;hp=-c Merge branch 'jk/long-error-messages' The codepath to produce error messages had a hard-coded limit to the size of the message, primarily to avoid memory allocation while calling die(). * jk/long-error-messages: vreportf: avoid intermediate buffer vreportf: report to arbitrary filehandles --- 1302c9f514686e32065130ec9a80eb0db224e819 diff --combined git-compat-util.h index 392da79029,076461e8c8..f649e81f11 --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -389,7 -389,6 +389,6 @@@ struct strbuf /* General helper functions */ extern void vreportf(const char *prefix, const char *err, va_list params); - extern void vwritef(int fd, const char *prefix, const char *err, va_list params); extern NORETURN void usage(const char *err); extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); @@@ -425,6 -424,7 +424,7 @@@ static inline int const_error(void extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern void set_die_is_recursing_routine(int (*routine)(void)); + extern void set_error_handle(FILE *); extern int starts_with(const char *str, const char *prefix); @@@ -717,12 -717,10 +717,12 @@@ extern void *xrealloc(void *ptr, size_ extern void *xcalloc(size_t nmemb, size_t size); extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); extern void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset); +extern int xopen(const char *path, int flags, ...); extern ssize_t xread(int fd, void *buf, size_t len); extern ssize_t xwrite(int fd, const void *buf, size_t len); extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset); extern int xdup(int fd); +extern FILE *xfopen(const char *path, const char *mode); extern FILE *xfdopen(int fd, const char *mode); extern int xmkstemp(char *template); extern int xmkstemp_mode(char *template, int mode); diff --combined run-command.c index 28e1d55cb9,0d01671c1f..3277cf797e --- a/run-command.c +++ b/run-command.c @@@ -200,7 -200,6 +200,6 @@@ static int execv_shell_cmd(const char * #endif #ifndef GIT_WINDOWS_NATIVE - static int child_err = 2; static int child_notifier = -1; static void notify_parent(void) @@@ -212,17 -211,6 +211,6 @@@ */ xwrite(child_notifier, "", 1); } - - static NORETURN void die_child(const char *err, va_list params) - { - vwritef(child_err, "fatal: ", err, params); - exit(128); - } - - static void error_child(const char *err, va_list params) - { - vwritef(child_err, "error: ", err, params); - } #endif static inline void set_cloexec(int fd) @@@ -362,11 -350,10 +350,10 @@@ fail_pipe * in subsequent call paths use the parent's stderr. */ if (cmd->no_stderr || need_err) { - child_err = dup(2); + int child_err = dup(2); set_cloexec(child_err); + set_error_handle(fdopen(child_err, "w")); } - set_die_routine(die_child); - set_error_routine(error_child); close(notify_pipe[0]); set_cloexec(notify_pipe[1]); @@@ -797,13 -784,11 +784,13 @@@ int finish_async(struct async *async const char *find_hook(const char *name) { - const char *path = git_path("hooks/%s", name); - if (access(path, X_OK) < 0) - path = NULL; + static struct strbuf path = STRBUF_INIT; - return path; + strbuf_reset(&path); + strbuf_git_path(&path, "hooks/%s", name); + if (access(path.buf, X_OK) < 0) + return NULL; + return path.buf; } int run_hook_ve(const char *const *env, const char *name, va_list args)