Merge branch 'jk/long-error-messages'
authorJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 21:57:06 +0000 (14:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 Aug 2015 21:57:06 +0000 (14:57 -0700)
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

1  2 
git-compat-util.h
run-command.c
diff --combined git-compat-util.h
index 392da79029f15e4e56f419e7781d5aabb991bec7,076461e8c8d3cd2051e84060c2ca405c3a3577ac..f649e81f1107722f4c7d051201920ae2a0e7846a
@@@ -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 28e1d55cb934d083eaf6ba6bed04d0716da5db08,0d01671c1ff26ccfe04481713a4071c321d8ab11..3277cf797ed41e5834b3b94fa8d2e9e9d5b4a317
@@@ -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)
         */
        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)