Merge branch 'pc/remove-warn'
authorJunio C Hamano <gitster@pobox.com>
Sun, 9 May 2010 05:32:59 +0000 (22:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 9 May 2010 05:32:59 +0000 (22:32 -0700)
* 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

1  2 
builtin/apply.c
git-compat-util.h
merge-recursive.c
diff --combined builtin/apply.c
index 771c972c5506db4848e2c214fb617525bafdf335,65a594c9851689b724cd6a243476679e724fb590..660cf92538ce125a83d566f3ba2bb7f2c24f5671
@@@ -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 7e62b552700a580646dbb6a8921c40761d6b57a2,3ebf96690aa20eca0f7147d14826a6a4c4bdf777..6e259772895599b35d13564e62077b882f0de3a6
@@@ -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 917397ca7a0c3a702681e1c3e93eb385bb6f28fb,87232b899d8ab12c2f3c6704a9a1ca12d4a9f286..206c1036359ce7b1fc5a1f5734b2d0bc2a760d90
@@@ -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;
  
                }
        }
  
 -      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));
        }
        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);