From: Junio C Hamano Date: Tue, 22 Jun 2010 15:30:38 +0000 (-0700) Subject: Merge branch 'pc/remove-warn' into maint X-Git-Tag: v1.7.2-rc0~18^2~13 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/21919d396a3a05ccb8d6b538b246500f01585bb7?hp=-c Merge branch 'pc/remove-warn' into maint * pc/remove-warn: Remove a redundant errno test in a usage of remove_path Introduce remove_or_warn function Implement the rmdir_or_warn function Generalise the unlink_or_warn function --- 21919d396a3a05ccb8d6b538b246500f01585bb7 diff --combined builtin/apply.c index f669157b42,65a594c985..59bbcdb132 --- a/builtin/apply.c +++ b/builtin/apply.c @@@ -1864,13 -1864,13 +1864,13 @@@ static int match_fragment(struct image if (match_end && (preimage->nr + try_lno != img->nr)) return 0; } else if (ws_error_action == correct_ws_error && - (ws_rule & WS_BLANK_AT_EOF) && match_end) { + (ws_rule & WS_BLANK_AT_EOF)) { /* - * This hunk that matches at the end extends beyond - * the end of img, and we are removing blank lines - * at the end of the file. This many lines from the - * beginning of the preimage must match with img, and - * the remainder of the preimage must be blank. + * This hunk extends beyond the end of img, and we are + * removing blank lines at the end of the file. This + * many lines from the beginning of the preimage must + * match with img, and the remainder of the preimage + * must be blank. */ preimage_limit = img->nr - try_lno; } else { @@@ -2824,8 -2824,11 +2824,8 @@@ static int check_preimage(struct patch if (stat_ret < 0) { struct checkout costate; /* checkout */ + memset(&costate, 0, sizeof(costate)); costate.base_dir = ""; - costate.base_dir_len = 0; - costate.force = 0; - costate.quiet = 0; - costate.not_new = 0; costate.refresh_cache = 1; if (checkout_entry(*ce, &costate, NULL) || lstat(old_name, st)) @@@ -3141,11 -3144,7 +3141,7 @@@ static void remove_file(struct patch *p die("unable to remove %s from index", patch->old_name); } if (!cached) { - if (S_ISGITLINK(patch->old_mode)) { - if (rmdir(patch->old_name)) - warning("unable to remove submodule %s", - patch->old_name); - } else if (!unlink_or_warn(patch->old_name) && rmdir_empty) { + if (!remove_or_warn(patch->old_mode, patch->old_name) && rmdir_empty) { remove_path(patch->old_name); } } diff --combined git-compat-util.h index c9e711872f,3ebf96690a..c0198dde4c --- a/git-compat-util.h +++ b/git-compat-util.h @@@ -55,8 -55,7 +55,8 @@@ # else # define _XOPEN_SOURCE 500 # endif -#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && !defined(_M_UNIX) && !defined(sgi) +#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && \ + !defined(_M_UNIX) && !defined(__sgi) && !defined(__DragonFly__) #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */ #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif @@@ -164,13 -163,6 +164,13 @@@ extern char *gitbasename(char *) #define PATH_SEP ':' #endif +#ifdef HAVE_PATHS_H +#include +#endif +#ifndef _PATH_DEFPATH +#define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin" +#endif + #ifndef STRIP_EXTENSION #define STRIP_EXTENSION "" #endif @@@ -339,7 -331,6 +339,7 @@@ extern int git_vsnprintf(char *str, siz #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL +#define HAVE_MEMPCPY #endif #endif @@@ -353,18 -344,8 +353,18 @@@ static inline char *gitstrchrnul(const } #endif +#ifndef HAVE_MEMPCPY +#define mempcpy gitmempcpy +static inline void *gitmempcpy(void *dest, const void *src, size_t n) +{ + return (char *)memcpy(dest, src, n) + n; +} +#endif + extern void release_pack_memory(size_t, int); +extern void set_try_to_free_routine(void (*routine)(size_t)); + extern char *xstrdup(const char *str); extern void *xmalloc(size_t size); extern void *xmallocz(size_t size); @@@ -488,5 -469,14 +488,14 @@@ void git_qsort(void *base, size_t nmemb * Always returns the return value of unlink(2). */ int unlink_or_warn(const char *path); + /* + * Likewise for rmdir(2). + */ + int rmdir_or_warn(const char *path); + /* + * Calls the correct function out of {unlink,rmdir}_or_warn based on + * the supplied file mode. + */ + int remove_or_warn(unsigned int mode, const char *path); #endif diff --combined merge-recursive.c index 917397ca7a,87232b899d..206c103635 --- a/merge-recursive.c +++ b/merge-recursive.c @@@ -409,7 -409,7 +409,7 @@@ static int remove_file(struct merge_opt return -1; } if (update_working_directory) { - if (remove_path(path) && errno != ENOENT) + if (remove_path(path)) return -1; } return 0; @@@ -608,7 -608,7 +608,7 @@@ static int merge_3way(struct merge_opti const char *branch2) { mmfile_t orig, src1, src2; - char *name1, *name2; + char *base_name, *name1, *name2; int merge_status; int favor; @@@ -628,15 -628,10 +628,15 @@@ } } - if (strcmp(a->path, b->path)) { + if (strcmp(a->path, b->path) || + (o->ancestor != NULL && strcmp(a->path, one->path) != 0)) { + base_name = o->ancestor == NULL ? NULL : + xstrdup(mkpath("%s:%s", o->ancestor, one->path)); name1 = xstrdup(mkpath("%s:%s", branch1, a->path)); name2 = xstrdup(mkpath("%s:%s", branch2, b->path)); } else { + base_name = o->ancestor == NULL ? NULL : + xstrdup(mkpath("%s", o->ancestor)); name1 = xstrdup(mkpath("%s", branch1)); name2 = xstrdup(mkpath("%s", branch2)); } @@@ -645,7 -640,7 +645,7 @@@ read_mmblob(&src1, a->sha1); read_mmblob(&src2, b->sha1); - merge_status = ll_merge(result_buf, a->path, &orig, + merge_status = ll_merge(result_buf, a->path, &orig, base_name, &src1, name1, &src2, name2, (!!o->call_depth) | (favor << 1)); @@@ -1347,7 -1342,6 +1347,7 @@@ int merge_recursive(struct merge_option if (!o->call_depth) read_cache(); + o->ancestor = "merged common ancestors"; clean = merge_trees(o, h1->tree, h2->tree, merged_common_ancestors->tree, &mrtree); diff --combined unpack-trees.c index 1a8030ced0,c29a9e067f..490cd5f6f4 --- a/unpack-trees.c +++ b/unpack-trees.c @@@ -67,16 -67,8 +67,8 @@@ static void unlink_entry(struct cache_e { if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce))) return; - if (S_ISGITLINK(ce->ce_mode)) { - if (rmdir(ce->name)) { - warning("unable to rmdir %s: %s", - ce->name, strerror(errno)); - return; - } - } - else - if (unlink_or_warn(ce->name)) - return; + if (remove_or_warn(ce->ce_mode, ce->name)) + return; schedule_dir_for_removal(ce->name, ce_namelen(ce)); } @@@ -862,7 -854,7 +854,7 @@@ static int verify_uptodate_1(struct cac { struct stat st; - if (o->index_only || (!ce_skip_worktree(ce) && (o->reset || ce_uptodate(ce)))) + if (o->index_only || (!((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) && (o->reset || ce_uptodate(ce)))) return 0; if (!lstat(ce->name, &st)) { diff --combined wrapper.c index 62edb57338,10a6750795..58201b6bcb --- a/wrapper.c +++ b/wrapper.c @@@ -3,23 -3,11 +3,23 @@@ */ #include "cache.h" +static void try_to_free_builtin(size_t size) +{ + release_pack_memory(size, -1); +} + +static void (*try_to_free_routine)(size_t size) = try_to_free_builtin; + +void set_try_to_free_routine(void (*routine)(size_t)) +{ + try_to_free_routine = (routine) ? routine : try_to_free_builtin; +} + char *xstrdup(const char *str) { char *ret = strdup(str); if (!ret) { - release_pack_memory(strlen(str) + 1, -1); + try_to_free_routine(strlen(str) + 1); ret = strdup(str); if (!ret) die("Out of memory, strdup failed"); @@@ -33,7 -21,7 +33,7 @@@ void *xmalloc(size_t size if (!ret && !size) ret = malloc(1); if (!ret) { - release_pack_memory(size, -1); + try_to_free_routine(size); ret = malloc(size); if (!ret && !size) ret = malloc(1); @@@ -79,7 -67,7 +79,7 @@@ void *xrealloc(void *ptr, size_t size if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { - release_pack_memory(size, -1); + try_to_free_routine(size); ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); @@@ -95,7 -83,7 +95,7 @@@ void *xcalloc(size_t nmemb, size_t size if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) { - release_pack_memory(nmemb * size, -1); + try_to_free_routine(nmemb * size); ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); @@@ -323,18 -311,30 +323,30 @@@ int odb_pack_keep(char *name, size_t na return open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } - int unlink_or_warn(const char *file) + static int warn_if_unremovable(const char *op, const char *file, int rc) { - int rc = unlink(file); - if (rc < 0) { int err = errno; if (ENOENT != err) { - warning("unable to unlink %s: %s", - file, strerror(errno)); + warning("unable to %s %s: %s", + op, file, strerror(errno)); errno = err; } } return rc; } + int unlink_or_warn(const char *file) + { + return warn_if_unremovable("unlink", file, unlink(file)); + } + + int rmdir_or_warn(const char *file) + { + return warn_if_unremovable("rmdir", file, rmdir(file)); + } + + int remove_or_warn(unsigned int mode, const char *file) + { + return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file); + }