Skip to content

Commit 86e67a0

Browse files
committed
Merge branch 'jk/maint-ls-files-other' into maint
* jk/maint-ls-files-other: refactor handling of "other" files in ls-files and status
2 parents d11ddaf + 98fa473 commit 86e67a0

File tree

5 files changed

+40
-44
lines changed

5 files changed

+40
-44
lines changed

builtin-ls-files.c

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,10 @@ static void show_other_files(struct dir_struct *dir)
9191
{
9292
int i;
9393

94-
95-
/*
96-
* Skip matching and unmerged entries for the paths,
97-
* since we want just "others".
98-
*
99-
* (Matching entries are normally pruned during
100-
* the directory tree walk, but will show up for
101-
* gitlinks because we don't necessarily have
102-
* dir->show_other_directories set to suppress
103-
* them).
104-
*/
10594
for (i = 0; i < dir->nr; i++) {
10695
struct dir_entry *ent = dir->entries[i];
107-
int len, pos;
108-
struct cache_entry *ce;
109-
110-
/*
111-
* Remove the '/' at the end that directory
112-
* walking adds for directory entries.
113-
*/
114-
len = ent->len;
115-
if (len && ent->name[len-1] == '/')
116-
len--;
117-
pos = cache_name_pos(ent->name, len);
118-
if (0 <= pos)
119-
continue; /* exact match */
120-
pos = -pos - 1;
121-
if (pos < active_nr) {
122-
ce = active_cache[pos];
123-
if (ce_namelen(ce) == len &&
124-
!memcmp(ce->name, ent->name, len))
125-
continue; /* Yup, this one exists unmerged */
126-
}
96+
if (!cache_name_is_other(ent->name, ent->len))
97+
continue;
12798
show_dir_entry(tag_other, ent);
12899
}
129100
}

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ static inline void remove_name_hash(struct cache_entry *ce)
270270
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
271271
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
272272
#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
273+
#define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen))
273274
#endif
274275

275276
enum object_type {
@@ -382,6 +383,7 @@ extern int add_to_index(struct index_state *, const char *path, struct stat *, i
382383
extern int add_file_to_index(struct index_state *, const char *path, int flags);
383384
extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh);
384385
extern int ce_same_name(struct cache_entry *a, struct cache_entry *b);
386+
extern int index_name_is_other(const struct index_state *, const char *, int);
385387

386388
/* do stat comparison even if CE_VALID is true */
387389
#define CE_MATCH_IGNORE_VALID 01

read-cache.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,3 +1485,31 @@ int read_index_unmerged(struct index_state *istate)
14851485
}
14861486
return unmerged;
14871487
}
1488+
1489+
/*
1490+
* Returns 1 if the path is an "other" path with respect to
1491+
* the index; that is, the path is not mentioned in the index at all,
1492+
* either as a file, a directory with some files in the index,
1493+
* or as an unmerged entry.
1494+
*
1495+
* We helpfully remove a trailing "/" from directories so that
1496+
* the output of read_directory can be used as-is.
1497+
*/
1498+
int index_name_is_other(const struct index_state *istate, const char *name,
1499+
int namelen)
1500+
{
1501+
int pos;
1502+
if (namelen && name[namelen - 1] == '/')
1503+
namelen--;
1504+
pos = index_name_pos(istate, name, namelen);
1505+
if (0 <= pos)
1506+
return 0; /* exact match */
1507+
pos = -pos - 1;
1508+
if (pos < istate->cache_nr) {
1509+
struct cache_entry *ce = istate->cache[pos];
1510+
if (ce_namelen(ce) == namelen &&
1511+
!memcmp(ce->name, name, namelen))
1512+
return 0; /* Yup, this one exists unmerged */
1513+
}
1514+
return 1;
1515+
}

t/t7502-status.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ test_expect_success 'status submodule summary is disabled by default' '
285285
test_cmp expect output
286286
'
287287

288+
# we expect the same as the previous test
289+
test_expect_success 'status --untracked-files=all does not show submodule' '
290+
git status --untracked-files=all >output &&
291+
test_cmp expect output
292+
'
293+
288294
head=$(cd sm && git rev-parse --short=7 --verify HEAD)
289295

290296
cat >expect <<EOF

wt-status.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,9 @@ static void wt_status_print_untracked(struct wt_status *s)
275275

276276
read_directory(&dir, ".", "", 0, NULL);
277277
for(i = 0; i < dir.nr; i++) {
278-
/* check for matching entry, which is unmerged; lifted from
279-
* builtin-ls-files:show_other_files */
280278
struct dir_entry *ent = dir.entries[i];
281-
int pos = cache_name_pos(ent->name, ent->len);
282-
struct cache_entry *ce;
283-
if (0 <= pos)
284-
die("bug in wt_status_print_untracked");
285-
pos = -pos - 1;
286-
if (pos < active_nr) {
287-
ce = active_cache[pos];
288-
if (ce_namelen(ce) == ent->len &&
289-
!memcmp(ce->name, ent->name, ent->len))
290-
continue;
291-
}
279+
if (!cache_name_is_other(ent->name, ent->len))
280+
continue;
292281
if (!shown_header) {
293282
s->workdir_untracked = 1;
294283
wt_status_print_header(s, "Untracked files",

0 commit comments

Comments
 (0)