Merge branch 'jc/reupdate' into next
authorJunio C Hamano <junkio@cox.net>
Sun, 7 May 2006 04:47:07 +0000 (21:47 -0700)
committerJunio C Hamano <junkio@cox.net>
Sun, 7 May 2006 04:47:07 +0000 (21:47 -0700)
* jc/reupdate:
Fix users of prefix_path() to free() only when necessary

1  2 
checkout-index.c
update-index.c
diff --combined checkout-index.c
index 64bdc3bd132288f9c130488446214b125d2cfb14,cc3a745c149b38ae250ac5656bb4a4843a95f6a4..9876af6fd60a81d871e6be30060cc93d0e0259c7
@@@ -39,7 -39,6 +39,7 @@@
  #include "cache.h"
  #include "strbuf.h"
  #include "quote.h"
 +#include "cache-tree.h"
  
  #define CHECKOUT_ALL 4
  static const char *prefix;
@@@ -278,7 -277,7 +278,7 @@@ int main(int argc, char **argv
                        die("git-checkout-index: don't mix '--stdin' and explicit filenames");
                p = prefix_path(prefix, prefix_length, arg);
                checkout_file(p);
-               if (p != arg)
+               if (p < arg || p > arg + strlen(arg))
                        free((char*)p);
        }
  
                                path_name = buf.buf;
                        p = prefix_path(prefix, prefix_length, path_name);
                        checkout_file(p);
-                       if (p != path_name)
+                       if (p < path_name || p > path_name + strlen(path_name))
                                free((char *)p);
                        if (path_name != buf.buf)
                                free(path_name);
diff --combined update-index.c
index 7db67aacfedaa542b6f64175580ad5e4e4c15e8d,3d7e02db2cc37dd22952f0e86e844eac3f5c1cc4..f6b09a4800b01f3c1675e87a91ea458e7172f169
@@@ -6,7 -6,6 +6,7 @@@
  #include "cache.h"
  #include "strbuf.h"
  #include "quote.h"
 +#include "cache-tree.h"
  #include "tree-walk.h"
  
  /*
@@@ -72,7 -71,6 +72,7 @@@ static int mark_valid(const char *path
                        active_cache[pos]->ce_flags &= ~htons(CE_VALID);
                        break;
                }
 +              cache_tree_invalidate_path(active_cache_tree, path);
                active_cache_changed = 1;
                return 0;
        }
@@@ -86,12 -84,6 +86,12 @@@ static int add_file_to_cache(const cha
        struct stat st;
  
        status = lstat(path, &st);
 +
 +      /* We probably want to do this in remove_file_from_cache() and
 +       * add_cache_entry() instead...
 +       */
 +      cache_tree_invalidate_path(active_cache_tree, path);
 +
        if (status < 0 || S_ISDIR(st.st_mode)) {
                /* When we used to have "path" and now we want to add
                 * "path/file", we need a way to remove "path" before
@@@ -334,7 -326,6 +334,7 @@@ static int add_cacheinfo(unsigned int m
                return error("%s: cannot add to the index - missing --add option?",
                             path);
        report("add '%s'", path);
 +      cache_tree_invalidate_path(active_cache_tree, path);
        return 0;
  }
  
@@@ -359,7 -350,6 +359,7 @@@ static void chmod_path(int flip, const 
        default:
                goto fail;
        }
 +      cache_tree_invalidate_path(active_cache_tree, path);
        active_cache_changed = 1;
        report("chmod %cx '%s'", flip, path);
        return;
@@@ -381,7 -371,6 +381,7 @@@ static void update_one(const char *path
                        die("Unable to mark file %s", path);
                goto free_return;
        }
 +      cache_tree_invalidate_path(active_cache_tree, path);
  
        if (force_remove) {
                if (remove_file_from_cache(p))
                die("Unable to process file %s", path);
        report("add '%s'", path);
   free_return:
-       if (p != path)
+       if (p < path || p > path + strlen(path))
                free((char*)p);
  }
  
@@@ -460,7 -449,6 +460,7 @@@ static void read_index_info(int line_te
                                free(path_name);
                        continue;
                }
 +              cache_tree_invalidate_path(active_cache_tree, path_name);
  
                if (!mode) {
                        /* mode == 0 means there is no such path -- remove */
@@@ -567,7 -555,6 +567,7 @@@ static int unresolve_one(const char *pa
                goto free_return;
        }
  
 +      cache_tree_invalidate_path(active_cache_tree, path);
        remove_file_from_cache(path);
        if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) {
                error("%s: cannot add our version to the index.", path);
@@@ -609,7 -596,7 +609,7 @@@ static int do_unresolve(int ac, const c
                const char *arg = av[i];
                const char *p = prefix_path(prefix, prefix_length, arg);
                err |= unresolve_one(p);
-               if (p != arg)
+               if (p < arg || p > arg + strlen(arg))
                        free((char*)p);
        }
        return err;
@@@ -623,7 -610,7 +623,7 @@@ static int do_reupdate(int ac, const ch
         */
        int pos;
        int has_head = 1;
-       char **pathspec = get_pathspec(prefix, av + 1);
+       const char **pathspec = get_pathspec(prefix, av + 1);
  
        if (read_ref(git_path("HEAD"), head_sha1))
                /* If there is no HEAD, that means it is an initial
@@@ -815,7 -802,7 +815,7 @@@ int main(int argc, const char **argv
                        update_one(p, NULL, 0);
                        if (set_executable_bit)
                                chmod_path(set_executable_bit, p);
-                       if (p != path_name)
+                       if (p < path_name || p > path_name + strlen(path_name))
                                free((char*) p);
                        if (path_name != buf.buf)
                                free(path_name);