Merge branch 'pc/remove-warn' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 22 Jun 2010 15:30:38 +0000 (08:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 22 Jun 2010 15:30:38 +0000 (08:30 -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
unpack-trees.c
wrapper.c
diff --combined builtin/apply.c
index f669157b42e658b3769ec775f7aa4dafea634db8,65a594c9851689b724cd6a243476679e724fb590..59bbcdb1323cb70432e90ccc2d6a1c60a562c706
@@@ -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 c9e711872f1a2380d273f7149b4795a4a9852c06,3ebf96690aa20eca0f7147d14826a6a4c4bdf777..c0198dde4c2c6a61718228ca2ade463c22e0bec3
@@@ -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 <paths.h>
 +#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 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);
  
diff --combined unpack-trees.c
index 1a8030ced0b7923d44d6b891133458e98ce969c7,c29a9e067ff362063d6626e8e4d1e4466d63b8af..490cd5f6f4779cbff68405722b98e522cbeb3cde
@@@ -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 62edb57338ccd1ae56b86649ec07d88c251576da,10a6750795b287beabd50561402ffa8867f3e283..58201b6bcb8d362cffd1222bcb8cd77072c34cf5
+++ 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);
+ }