From: Junio C Hamano Date: Fri, 24 Oct 2014 21:59:10 +0000 (-0700) Subject: Merge branch 'eb/no-pthreads' X-Git-Tag: v2.2.0-rc0~19 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e4da4fbe0eea55c26f042f76df58bfc529b46ae0?ds=inline;hp=-c Merge branch 'eb/no-pthreads' Allow us build with NO_PTHREADS=NoThanks compilation option. * eb/no-pthreads: Handle atexit list internaly for unthreaded builds pack-objects: set number of threads before checking and warning index-pack: fix compilation with NO_PTHREADS --- e4da4fbe0eea55c26f042f76df58bfc529b46ae0 diff --combined builtin/clone.c index 7f509d06a8,4340477925..d5e7532105 --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -9,7 -9,6 +9,7 @@@ */ #include "builtin.h" +#include "lockfile.h" #include "parse-options.h" #include "fetch-pack.h" #include "refs.h" @@@ -391,7 -390,6 +391,6 @@@ static void clone_local(const char *src static const char *junk_work_tree; static const char *junk_git_dir; - static pid_t junk_pid; static enum { JUNK_LEAVE_NONE, JUNK_LEAVE_REPO, @@@ -418,8 -416,6 +417,6 @@@ static void remove_junk(void break; } - if (getpid() != junk_pid) - return; if (junk_git_dir) { strbuf_addstr(&sb, junk_git_dir); remove_dir_recursively(&sb, 0); @@@ -623,7 -619,7 +620,7 @@@ static int checkout(void if (option_no_checkout) return 0; - head = resolve_refdup("HEAD", sha1, 1, NULL); + head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL); if (!head) { warning(_("remote HEAD refers to nonexistent ref, " "unable to checkout.\n")); @@@ -760,8 -756,6 +757,6 @@@ int cmd_clone(int argc, const char **ar struct refspec *refspec; const char *fetch_pattern; - junk_pid = getpid(); - packet_trace_identity("clone"); argc = parse_options(argc, argv, prefix, builtin_clone_options, builtin_clone_usage, 0); diff --combined builtin/pack-objects.c index a4022a78d0,a71523706a..78c659a6b4 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@@ -811,7 -811,6 +811,7 @@@ static void write_pack_file(void fixup_pack_header_footer(fd, sha1, pack_tmp_name, nr_written, sha1, offset); close(fd); + write_bitmap_index = 0; } if (!pack_to_stdout) { @@@ -1973,8 -1972,6 +1973,6 @@@ static void ll_find_deltas(struct objec init_threaded_search(); - if (!delta_search_threads) /* --threads=0 means autodetect */ - delta_search_threads = online_cpus(); if (delta_search_threads <= 1) { find_deltas(list, &list_size, window, depth, processed); cleanup_threaded_search(); @@@ -2686,6 -2683,10 +2684,10 @@@ int cmd_pack_objects(int argc, const ch pack_compression_level = Z_DEFAULT_COMPRESSION; else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION) die("bad pack compression level %d", pack_compression_level); + + if (!delta_search_threads) /* --threads=0 means autodetect */ + delta_search_threads = online_cpus(); + #ifdef NO_PTHREADS if (delta_search_threads != 1) warning("no threads support, ignoring --threads"); diff --combined git-compat-util.h index 59ecf218cb,ffbedd8fb9..210712728d --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -326,8 -326,6 +326,8 @@@ static inline char *git_find_last_dir_s #include "wildmatch.h" +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); @@@ -596,6 -594,11 +596,11 @@@ int inet_pton(int af, const char *src, const char *inet_ntop(int af, const void *src, char *dst, size_t size); #endif + #ifdef NO_PTHREADS + #define atexit git_atexit + extern int git_atexit(void (*handler)(void)); + #endif + extern void release_pack_memory(size_t); typedef void (*try_to_free_t)(size_t); @@@ -779,21 -782,11 +784,21 @@@ void git_qsort(void *base, size_t nmemb /* * Preserves errno, prints a message, but gives no warning for ENOENT. - * Always returns the return value of unlink(2). + * Returns 0 on success, which includes trying to unlink an object that does + * not exist. */ int unlink_or_warn(const char *path); + /* + * Tries to unlink file. Returns 0 if unlink succeeded + * or the file already didn't exist. Returns -1 and + * appends a message to err suitable for + * 'error("%s", err->buf)' on error. + */ +int unlink_or_msg(const char *file, struct strbuf *err); /* - * Likewise for rmdir(2). + * Preserves errno, prints a message, but gives no warning for ENOENT. + * Returns 0 on success, which includes trying to remove a directory that does + * not exist. */ int rmdir_or_warn(const char *path); /* diff --combined run-command.c index 46be513c48,41d94c111e..79a0a763ec --- a/run-command.c +++ b/run-command.c @@@ -12,7 -12,6 +12,7 @@@ void child_process_init(struct child_pr { memset(child, 0, sizeof(*child)); argv_array_init(&child->args); + argv_array_init(&child->env_array); } struct child_to_clean { @@@ -288,8 -287,6 +288,8 @@@ int start_command(struct child_process if (!cmd->argv) cmd->argv = cmd->args.argv; + if (!cmd->env) + cmd->env = cmd->env_array.argv; /* * In case of errors we must keep the promise to close FDs @@@ -341,7 -338,6 +341,7 @@@ fail_pipe error("cannot create %s pipe for %s: %s", str, cmd->argv[0], strerror(failed_errno)); argv_array_clear(&cmd->args); + argv_array_clear(&cmd->env_array); errno = failed_errno; return -1; } @@@ -528,7 -524,6 +528,7 @@@ else if (cmd->err) close(cmd->err); argv_array_clear(&cmd->args); + argv_array_clear(&cmd->env_array); errno = failed_errno; return -1; } @@@ -555,7 -550,6 +555,7 @@@ int finish_command(struct child_proces { int ret = wait_or_whine(cmd->pid, cmd->argv[0]); argv_array_clear(&cmd->args); + argv_array_clear(&cmd->env_array); return ret; } @@@ -626,6 -620,45 +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() + { + size_t i; + + for (i=git_atexit_hdlrs.nr ; i ; i--) + git_atexit_hdlrs.handlers[i-1](); + } + + static void git_atexit_clear() + { + 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 -717,7 +723,7 @@@ close(fdin[1]); if (need_out) close(fdout[0]); + git_atexit_clear(); exit(!!async->proc(proc_in, proc_out, async->data)); } diff --combined shallow.c index bd7569e815,0cc3d47634..cdd0775146 --- a/shallow.c +++ b/shallow.c @@@ -1,5 -1,4 +1,5 @@@ #include "cache.h" +#include "lockfile.h" #include "commit.h" #include "tag.h" #include "pkt-line.h" @@@ -227,7 -226,6 +227,6 @@@ static void remove_temporary_shallow_on const char *setup_temporary_shallow(const struct sha1_array *extra) { - static int installed_handler; struct strbuf sb = STRBUF_INIT; int fd; @@@ -238,10 -236,8 +237,8 @@@ strbuf_addstr(&temporary_shallow, git_path("shallow_XXXXXX")); fd = xmkstemp(temporary_shallow.buf); - if (!installed_handler) { - atexit(remove_temporary_shallow); - sigchain_push_common(remove_temporary_shallow_on_signal); - } + atexit(remove_temporary_shallow); + sigchain_push_common(remove_temporary_shallow_on_signal); if (write_in_full(fd, sb.buf, sb.len) != sb.len) die_errno("failed to write to %s", @@@ -270,8 -266,8 +267,8 @@@ void setup_alternate_shallow(struct loc if (write_shallow_commits(&sb, 0, extra)) { if (write_in_full(fd, sb.buf, sb.len) != sb.len) die_errno("failed to write to %s", - shallow_lock->filename); - *alternate_shallow_file = shallow_lock->filename; + shallow_lock->filename.buf); + *alternate_shallow_file = shallow_lock->filename.buf; } else /* * is_repository_shallow() sees empty string as "no @@@ -317,7 -313,7 +314,7 @@@ void prune_shallow(int show_only if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) { if (write_in_full(fd, sb.buf, sb.len) != sb.len) die_errno("failed to write to %s", - shallow_lock.filename); + shallow_lock.filename.buf); commit_lock_file(&shallow_lock); } else { unlink(git_path("shallow"));