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 | |
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
-rw-r--r-- | builtin-ls-files.c | 33 | ||||
-rw-r--r-- | cache.h | 2 | ||||
-rw-r--r-- | read-cache.c | 27 | ||||
-rwxr-xr-x | t/t7502-status.sh | 6 | ||||
-rw-r--r-- | wt-status.c | 15 |
5 files changed, 39 insertions, 44 deletions
diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 068f42469..b48327db9 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -91,39 +91,10 @@ static void show_other_files(struct dir_struct *dir) { int i; - - /* - * Skip matching and unmerged entries for the paths, - * since we want just "others". - * - * (Matching entries are normally pruned during - * the directory tree walk, but will show up for - * gitlinks because we don't necessarily have - * dir->show_other_directories set to suppress - * them). - */ for (i = 0; i < dir->nr; i++) { struct dir_entry *ent = dir->entries[i]; - int len, pos; - struct cache_entry *ce; - - /* - * Remove the '/' at the end that directory - * walking adds for directory entries. - */ - len = ent->len; - if (len && ent->name[len-1] == '/') - len--; - pos = cache_name_pos(ent->name, len); - if (0 <= pos) - continue; /* exact match */ - pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; - if (ce_namelen(ce) == len && - !memcmp(ce->name, ent->name, len)) - continue; /* Yup, this one exists unmerged */ - } + if (!cache_name_is_other(ent->name, ent->len)) + continue; show_dir_entry(tag_other, ent); } } @@ -277,6 +277,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) +#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #endif enum object_type { @@ -393,6 +394,7 @@ extern int add_to_index(struct index_state *, const char *path, struct stat *, i extern int add_file_to_index(struct index_state *, const char *path, int flags); extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); +extern int index_name_is_other(const struct index_state *, const char *, int); /* do stat comparison even if CE_VALID is true */ #define CE_MATCH_IGNORE_VALID 01 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; +} diff --git a/t/t7502-status.sh b/t/t7502-status.sh index 1905fb34c..93f875f50 100755 --- a/t/t7502-status.sh +++ b/t/t7502-status.sh @@ -292,6 +292,12 @@ test_expect_success 'status submodule summary is disabled by default' ' test_cmp expect output ' +# we expect the same as the previous test +test_expect_success 'status --untracked-files=all does not show submodule' ' + git status --untracked-files=all >output && + test_cmp expect output +' + head=$(cd sm && git rev-parse --short=7 --verify HEAD) cat >expect <<EOF diff --git a/wt-status.c b/wt-status.c index d2eac36ae..c3a9cab89 100644 --- a/wt-status.c +++ b/wt-status.c @@ -277,20 +277,9 @@ static void wt_status_print_untracked(struct wt_status *s) read_directory(&dir, ".", "", 0, NULL); for(i = 0; i < dir.nr; i++) { - /* check for matching entry, which is unmerged; lifted from - * builtin-ls-files:show_other_files */ struct dir_entry *ent = dir.entries[i]; - int pos = cache_name_pos(ent->name, ent->len); - struct cache_entry *ce; - if (0 <= pos) - die("bug in wt_status_print_untracked"); - pos = -pos - 1; - if (pos < active_nr) { - ce = active_cache[pos]; - if (ce_namelen(ce) == ent->len && - !memcmp(ce->name, ent->name, ent->len)) - continue; - } + if (!cache_name_is_other(ent->name, ent->len)) + continue; if (!shown_header) { s->workdir_untracked = 1; wt_status_print_untracked_header(s); |