From: Junio C Hamano Date: Sun, 2 Nov 2008 21:37:13 +0000 (-0800) Subject: Merge branch 'jk/maint-ls-files-other' into maint X-Git-Tag: v1.6.0.4~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=86e67a088c581da4da36acf0edd8c27b1033e51e;p=git.git Merge branch 'jk/maint-ls-files-other' into maint * jk/maint-ls-files-other: refactor handling of "other" files in ls-files and status --- 86e67a088c581da4da36acf0edd8c27b1033e51e diff --cc read-cache.c index 15e1a9d47,4e067e489..967f483f7 --- a/read-cache.c +++ b/read-cache.c @@@ -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; + }