diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-10-21 17:57:56 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-10-21 17:57:56 -0700 |
commit | d67dd17b336a1f39760324b6cc05eaee17b5f124 (patch) | |
tree | 2b3353aa25ac10ef9865b59025adf9e1f7e8b9f5 /read-cache.c | |
parent | 500ac7f42e7f2ae42e33be3bbb7120b788175b1d (diff) | |
parent | e845e16ee6de99a203db47eeb840daf3b1914ec9 (diff) | |
download | git-d67dd17b336a1f39760324b6cc05eaee17b5f124.tar.gz git-d67dd17b336a1f39760324b6cc05eaee17b5f124.tar.xz |
Merge branch 'jk/fix-ls-files-other'
* jk/fix-ls-files-other:
refactor handling of "other" files in ls-files and status
Diffstat (limited to 'read-cache.c')
-rw-r--r-- | read-cache.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c index 8160022b2..fdb41b872 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1570,3 +1570,30 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags) return !!data.add_errors; } +/* + * 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; +} |