From: Junio C Hamano Date: Sun, 9 May 2010 05:32:59 +0000 (-0700) Subject: Merge branch 'pc/remove-warn' X-Git-Tag: v1.7.2-rc0~160 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/3ecaa3b6a5f707617ea610d727c696f43f8b2f0b?hp=-c Merge branch 'pc/remove-warn' * 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 --- 3ecaa3b6a5f707617ea610d727c696f43f8b2f0b diff --combined builtin/apply.c index 771c972c55,65a594c985..660cf92538 --- a/builtin/apply.c +++ b/builtin/apply.c @@@ -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 7e62b55270,3ebf96690a..6e25977289 --- 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 @@@ -332,7 -331,6 +332,7 @@@ extern int git_vsnprintf(char *str, siz #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 1) #define HAVE_STRCHRNUL +#define HAVE_MEMPCPY #endif #endif @@@ -346,14 -344,6 +346,14 @@@ 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 char *xstrdup(const char *str); @@@ -479,5 -469,14 +479,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);