show-branch: show all local heads when only giving one rev along --topics
[gitweb.git] / run-command.c
index 46be513c480abf200148f7dcfc08c1c021410f7c..0b432cc9713251b4d116bedf52ae1f51bd9d80cf 100644 (file)
@@ -626,6 +626,45 @@ static int async_die_is_recursing(void)
        return ret != NULL;
 }
 
+#else
+
+static struct {
+       void (**handlers)(void);
+       size_t nr;
+       size_t alloc;
+} git_atexit_hdlrs;
+
+static int git_atexit_installed;
+
+static void git_atexit_dispatch(void)
+{
+       size_t i;
+
+       for (i=git_atexit_hdlrs.nr ; i ; i--)
+               git_atexit_hdlrs.handlers[i-1]();
+}
+
+static void git_atexit_clear(void)
+{
+       free(git_atexit_hdlrs.handlers);
+       memset(&git_atexit_hdlrs, 0, sizeof(git_atexit_hdlrs));
+       git_atexit_installed = 0;
+}
+
+#undef atexit
+int git_atexit(void (*handler)(void))
+{
+       ALLOC_GROW(git_atexit_hdlrs.handlers, git_atexit_hdlrs.nr + 1, git_atexit_hdlrs.alloc);
+       git_atexit_hdlrs.handlers[git_atexit_hdlrs.nr++] = handler;
+       if (!git_atexit_installed) {
+               if (atexit(&git_atexit_dispatch))
+                       return -1;
+               git_atexit_installed = 1;
+       }
+       return 0;
+}
+#define atexit git_atexit
+
 #endif
 
 int start_async(struct async *async)
@@ -684,6 +723,7 @@ int start_async(struct async *async)
                        close(fdin[1]);
                if (need_out)
                        close(fdout[0]);
+               git_atexit_clear();
                exit(!!async->proc(proc_in, proc_out, async->data));
        }
 
@@ -793,20 +833,3 @@ int run_hook_le(const char *const *env, const char *name, ...)
 
        return ret;
 }
-
-int run_hook_with_custom_index(const char *index_file, const char *name, ...)
-{
-       const char *hook_env[3] =  { NULL };
-       char index[PATH_MAX];
-       va_list args;
-       int ret;
-
-       snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
-       hook_env[0] = index;
-
-       va_start(args, name);
-       ret = run_hook_ve(hook_env, name, args);
-       va_end(args);
-
-       return ret;
-}