Merge branch 'jk/maint-ls-files-other' into maint
authorJunio C Hamano <gitster@pobox.com>
Sun, 2 Nov 2008 21:37:13 +0000 (13:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 2 Nov 2008 21:37:13 +0000 (13:37 -0800)
* jk/maint-ls-files-other:
  refactor handling of "other" files in ls-files and status

1  2 
cache.h
read-cache.c

diff --cc cache.h
Simple merge
diff --cc read-cache.c
index 15e1a9d471daa2fd5c54a9f8562b1dfc52161213,4e067e489743aca27dc13e3d04d4e41f4ffec95b..967f483f783693eff4fd4e252dae7a0cc8b12ada
@@@ -1460,28 -1460,51 +1460,56 @@@ int write_index(const struct index_stat
  int read_index_unmerged(struct index_state *istate)
  {
        int i;
 -      struct cache_entry **dst;
 -      struct cache_entry *last = NULL;
 +      int unmerged = 0;
  
        read_index(istate);
 -      dst = istate->cache;
        for (i = 0; i < istate->cache_nr; i++) {
                struct cache_entry *ce = istate->cache[i];
 -              if (ce_stage(ce)) {
 -                      remove_name_hash(ce);
 -                      if (last && !strcmp(ce->name, last->name))
 -                              continue;
 -                      cache_tree_invalidate_path(istate->cache_tree, ce->name);
 -                      last = ce;
 +              struct cache_entry *new_ce;
 +              int size, len;
 +
 +              if (!ce_stage(ce))
                        continue;
 -              }
 -              *dst++ = ce;
 +              unmerged = 1;
 +              len = strlen(ce->name);
 +              size = cache_entry_size(len);
 +              new_ce = xcalloc(1, size);
 +              hashcpy(new_ce->sha1, ce->sha1);
 +              memcpy(new_ce->name, ce->name, len);
 +              new_ce->ce_flags = create_ce_flags(len, 0);
 +              new_ce->ce_mode = ce->ce_mode;
 +              if (add_index_entry(istate, new_ce, 0))
 +                      return error("%s: cannot drop to stage #0",
 +                                   ce->name);
 +              i = index_name_pos(istate, new_ce->name, len);
        }
 -      istate->cache_nr = dst - istate->cache;
 -      return !!last;
 +      return unmerged;
  }
+ /*
+  * Returns 1 if the path is an "other" path with respect to
+  * the index; that is, the path is not mentioned in the index at all,
+  * either as a file, a directory with some files in the index,
+  * or as an unmerged entry.
+  *
+  * We helpfully remove a trailing "/" from directories so that
+  * the output of read_directory can be used as-is.
+  */
+ int index_name_is_other(const struct index_state *istate, const char *name,
+               int namelen)
+ {
+       int pos;
+       if (namelen && name[namelen - 1] == '/')
+               namelen--;
+       pos = index_name_pos(istate, name, namelen);
+       if (0 <= pos)
+               return 0;       /* exact match */
+       pos = -pos - 1;
+       if (pos < istate->cache_nr) {
+               struct cache_entry *ce = istate->cache[pos];
+               if (ce_namelen(ce) == namelen &&
+                   !memcmp(ce->name, name, namelen))
+                       return 0; /* Yup, this one exists unmerged */
+       }
+       return 1;
+ }