File: | builtin/ls-files.c |
Location: | line 576, column 2 |
Description: | Value stored to 'argc' is never read |
1 | /* |
2 | * This merges the file listing in the directory cache index |
3 | * with the actual working directory list, and shows different |
4 | * combinations of the two. |
5 | * |
6 | * Copyright (C) Linus Torvalds, 2005 |
7 | */ |
8 | #include "cache.h" |
9 | #include "quote.h" |
10 | #include "dir.h" |
11 | #include "builtin.h" |
12 | #include "tree.h" |
13 | #include "parse-options.h" |
14 | #include "resolve-undo.h" |
15 | #include "string-list.h" |
16 | #include "pathspec.h" |
17 | #include "run-command.h" |
18 | |
19 | static int abbrev; |
20 | static int show_deleted; |
21 | static int show_cached; |
22 | static int show_others; |
23 | static int show_stage; |
24 | static int show_unmerged; |
25 | static int show_resolve_undo; |
26 | static int show_modified; |
27 | static int show_killed; |
28 | static int show_valid_bit; |
29 | static int line_terminator = '\n'; |
30 | static int debug_mode; |
31 | static int show_eol; |
32 | static int recurse_submodules; |
33 | static struct argv_array submodules_options = ARGV_ARRAY_INIT{ empty_argv, 0, 0 }; |
34 | |
35 | static const char *prefix; |
36 | static const char *super_prefix; |
37 | static int max_prefix_len; |
38 | static int prefix_len; |
39 | static struct pathspec pathspec; |
40 | static int error_unmatch; |
41 | static char *ps_matched; |
42 | static const char *with_tree; |
43 | static int exc_given; |
44 | static int exclude_args; |
45 | |
46 | static const char *tag_cached = ""; |
47 | static const char *tag_unmerged = ""; |
48 | static const char *tag_removed = ""; |
49 | static const char *tag_other = ""; |
50 | static const char *tag_killed = ""; |
51 | static const char *tag_modified = ""; |
52 | static const char *tag_skip_worktree = ""; |
53 | static const char *tag_resolve_undo = ""; |
54 | |
55 | static void write_eolinfo(const struct cache_entry *ce, const char *path) |
56 | { |
57 | if (!show_eol) |
58 | return; |
59 | else { |
60 | struct stat st; |
61 | const char *i_txt = ""; |
62 | const char *w_txt = ""; |
63 | const char *a_txt = get_convert_attr_ascii(path); |
64 | if (ce && S_ISREG(ce->ce_mode)(((ce->ce_mode) & 0170000) == 0100000)) |
65 | i_txt = get_cached_convert_stats_ascii(ce->name); |
66 | if (!lstat(path, &st) && S_ISREG(st.st_mode)(((st.st_mode) & 0170000) == 0100000)) |
67 | w_txt = get_wt_convert_stats_ascii(path); |
68 | printf("i/%-5s w/%-5s attr/%-17s\t", i_txt, w_txt, a_txt); |
69 | } |
70 | } |
71 | |
72 | static void write_name(const char *name) |
73 | { |
74 | /* |
75 | * Prepend the super_prefix to name to construct the full_name to be |
76 | * written. |
77 | */ |
78 | struct strbuf full_name = STRBUF_INIT{ 0, 0, strbuf_slopbuf }; |
79 | if (super_prefix) { |
80 | strbuf_addstr(&full_name, super_prefix); |
81 | strbuf_addstr(&full_name, name); |
82 | name = full_name.buf; |
83 | } |
84 | |
85 | /* |
86 | * With "--full-name", prefix_len=0; this caller needs to pass |
87 | * an empty string in that case (a NULL is good for ""). |
88 | */ |
89 | write_name_quoted_relative(name, prefix_len ? prefix : NULL((void*)0), |
90 | stdout__stdoutp, line_terminator); |
91 | |
92 | strbuf_release(&full_name); |
93 | } |
94 | |
95 | static void show_dir_entry(const char *tag, struct dir_entry *ent) |
96 | { |
97 | int len = max_prefix_len; |
98 | |
99 | if (len >= ent->len) |
100 | die("git ls-files: internal error - directory entry not superset of prefix"); |
101 | |
102 | if (!dir_path_match(ent, &pathspec, len, ps_matched)) |
103 | return; |
104 | |
105 | fputs(tag, stdout__stdoutp); |
106 | write_eolinfo(NULL((void*)0), ent->name); |
107 | write_name(ent->name); |
108 | } |
109 | |
110 | static void show_other_files(struct dir_struct *dir) |
111 | { |
112 | int i; |
113 | |
114 | for (i = 0; i < dir->nr; i++) { |
115 | struct dir_entry *ent = dir->entries[i]; |
116 | if (!cache_name_is_other(ent->name, ent->len)index_name_is_other(&the_index, (ent->name), (ent-> len))) |
117 | continue; |
118 | show_dir_entry(tag_other, ent); |
119 | } |
120 | } |
121 | |
122 | static void show_killed_files(struct dir_struct *dir) |
123 | { |
124 | int i; |
125 | for (i = 0; i < dir->nr; i++) { |
126 | struct dir_entry *ent = dir->entries[i]; |
127 | char *cp, *sp; |
128 | int pos, len, killed = 0; |
129 | |
130 | for (cp = ent->name; cp - ent->name < ent->len; cp = sp + 1) { |
131 | sp = strchr(cp, '/'); |
132 | if (!sp) { |
133 | /* If ent->name is prefix of an entry in the |
134 | * cache, it will be killed. |
135 | */ |
136 | pos = cache_name_pos(ent->name, ent->len)index_name_pos(&the_index,(ent->name),(ent->len)); |
137 | if (0 <= pos) |
138 | die("BUG: killed-file %.*s not found", |
139 | ent->len, ent->name); |
140 | pos = -pos - 1; |
141 | while (pos < active_nr(the_index.cache_nr) && |
142 | ce_stage(active_cache[pos])(((0x3000) & ((the_index.cache)[pos])->ce_flags) >> 12)) |
143 | pos++; /* skip unmerged */ |
144 | if (active_nr(the_index.cache_nr) <= pos) |
145 | break; |
146 | /* pos points at a name immediately after |
147 | * ent->name in the cache. Does it expect |
148 | * ent->name to be a directory? |
149 | */ |
150 | len = ce_namelen(active_cache[pos])(((the_index.cache)[pos])->ce_namelen); |
151 | if ((ent->len < len) && |
152 | !strncmp(active_cache(the_index.cache)[pos]->name, |
153 | ent->name, ent->len) && |
154 | active_cache(the_index.cache)[pos]->name[ent->len] == '/') |
155 | killed = 1; |
156 | break; |
157 | } |
158 | if (0 <= cache_name_pos(ent->name, sp - ent->name)index_name_pos(&the_index,(ent->name),(sp - ent->name ))) { |
159 | /* If any of the leading directories in |
160 | * ent->name is registered in the cache, |
161 | * ent->name will be killed. |
162 | */ |
163 | killed = 1; |
164 | break; |
165 | } |
166 | } |
167 | if (killed) |
168 | show_dir_entry(tag_killed, dir->entries[i]); |
169 | } |
170 | } |
171 | |
172 | /* |
173 | * Compile an argv_array with all of the options supported by --recurse_submodules |
174 | */ |
175 | static void compile_submodule_options(const struct dir_struct *dir, int show_tag) |
176 | { |
177 | if (line_terminator == '\0') |
178 | argv_array_push(&submodules_options, "-z"); |
179 | if (show_tag) |
180 | argv_array_push(&submodules_options, "-t"); |
181 | if (show_valid_bit) |
182 | argv_array_push(&submodules_options, "-v"); |
183 | if (show_cached) |
184 | argv_array_push(&submodules_options, "--cached"); |
185 | if (show_eol) |
186 | argv_array_push(&submodules_options, "--eol"); |
187 | if (debug_mode) |
188 | argv_array_push(&submodules_options, "--debug"); |
189 | } |
190 | |
191 | /** |
192 | * Recursively call ls-files on a submodule |
193 | */ |
194 | static void show_gitlink(const struct cache_entry *ce) |
195 | { |
196 | struct child_process cp = CHILD_PROCESS_INIT{ ((void*)0), { empty_argv, 0, 0 }, { empty_argv, 0, 0 } }; |
197 | int status; |
198 | int i; |
199 | |
200 | argv_array_pushf(&cp.args, "--super-prefix=%s%s/", |
201 | super_prefix ? super_prefix : "", |
202 | ce->name); |
203 | argv_array_push(&cp.args, "ls-files"); |
204 | argv_array_push(&cp.args, "--recurse-submodules"); |
205 | |
206 | /* add supported options */ |
207 | argv_array_pushv(&cp.args, submodules_options.argv); |
208 | |
209 | /* |
210 | * Pass in the original pathspec args. The submodule will be |
211 | * responsible for prepending the 'submodule_prefix' prior to comparing |
212 | * against the pathspec for matches. |
213 | */ |
214 | argv_array_push(&cp.args, "--"); |
215 | for (i = 0; i < pathspec.nr; i++) |
216 | argv_array_push(&cp.args, pathspec.items[i].original); |
217 | |
218 | cp.git_cmd = 1; |
219 | cp.dir = ce->name; |
220 | status = run_command(&cp); |
221 | if (status) |
222 | exit(status); |
223 | } |
224 | |
225 | static void show_ce_entry(const char *tag, const struct cache_entry *ce) |
226 | { |
227 | struct strbuf name = STRBUF_INIT{ 0, 0, strbuf_slopbuf }; |
228 | int len = max_prefix_len; |
229 | if (super_prefix) |
230 | strbuf_addstr(&name, super_prefix); |
231 | strbuf_addstr(&name, ce->name); |
232 | |
233 | if (len >= ce_namelen(ce)((ce)->ce_namelen)) |
234 | die("git ls-files: internal error - cache entry not superset of prefix"); |
235 | |
236 | if (recurse_submodules && S_ISGITLINK(ce->ce_mode)(((ce->ce_mode) & 0170000) == 0160000) && |
237 | submodule_path_match(&pathspec, name.buf, ps_matched)) { |
238 | show_gitlink(ce); |
239 | } else if (match_pathspec(&pathspec, name.buf, name.len, |
240 | len, ps_matched, |
241 | S_ISDIR(ce->ce_mode)(((ce->ce_mode) & 0170000) == 0040000) || |
242 | S_ISGITLINK(ce->ce_mode)(((ce->ce_mode) & 0170000) == 0160000))) { |
243 | if (tag && *tag && show_valid_bit && |
244 | (ce->ce_flags & CE_VALID(0x8000))) { |
245 | static char alttag[4]; |
246 | memcpy(alttag, tag, 3)__builtin___memcpy_chk (alttag, tag, 3, __builtin_object_size (alttag, 0)); |
247 | if (isalpha(tag[0])((sane_ctype[(unsigned char)(tag[0])] & (0x04)) != 0)) |
248 | alttag[0] = tolower(tag[0])sane_case((unsigned char)(tag[0]), 0x20); |
249 | else if (tag[0] == '?') |
250 | alttag[0] = '!'; |
251 | else { |
252 | alttag[0] = 'v'; |
253 | alttag[1] = tag[0]; |
254 | alttag[2] = ' '; |
255 | alttag[3] = 0; |
256 | } |
257 | tag = alttag; |
258 | } |
259 | |
260 | if (!show_stage) { |
261 | fputs(tag, stdout__stdoutp); |
262 | } else { |
263 | printf("%s%06o %s %d\t", |
264 | tag, |
265 | ce->ce_mode, |
266 | find_unique_abbrev(ce->oid.hash, abbrev), |
267 | ce_stage(ce)(((0x3000) & (ce)->ce_flags) >> 12)); |
268 | } |
269 | write_eolinfo(ce, ce->name); |
270 | write_name(ce->name); |
271 | if (debug_mode) { |
272 | const struct stat_data *sd = &ce->ce_stat_data; |
273 | |
274 | printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec); |
275 | printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec); |
276 | printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino); |
277 | printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid); |
278 | printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags); |
279 | } |
280 | } |
281 | |
282 | strbuf_release(&name); |
283 | } |
284 | |
285 | static void show_ru_info(void) |
286 | { |
287 | struct string_list_item *item; |
288 | |
289 | if (!the_index.resolve_undo) |
290 | return; |
291 | |
292 | for_each_string_list_item(item, the_index.resolve_undo)for (item = (the_index.resolve_undo)->items; item < (the_index .resolve_undo)->items + (the_index.resolve_undo)->nr; ++ item) { |
293 | const char *path = item->string; |
294 | struct resolve_undo_info *ui = item->util; |
295 | int i, len; |
296 | |
297 | len = strlen(path); |
298 | if (len < max_prefix_len) |
299 | continue; /* outside of the prefix */ |
300 | if (!match_pathspec(&pathspec, path, len, |
301 | max_prefix_len, ps_matched, 0)) |
302 | continue; /* uninterested */ |
303 | for (i = 0; i < 3; i++) { |
304 | if (!ui->mode[i]) |
305 | continue; |
306 | printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], |
307 | find_unique_abbrev(ui->sha1[i], abbrev), |
308 | i + 1); |
309 | write_name(path); |
310 | } |
311 | } |
312 | } |
313 | |
314 | static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce) |
315 | { |
316 | int dtype = ce_to_dtype(ce); |
317 | return is_excluded(dir, ce->name, &dtype); |
318 | } |
319 | |
320 | static void show_files(struct dir_struct *dir) |
321 | { |
322 | int i; |
323 | |
324 | /* For cached/deleted files we don't need to even do the readdir */ |
325 | if (show_others || show_killed) { |
326 | if (!show_others) |
327 | dir->flags |= DIR_COLLECT_KILLED_ONLY; |
328 | fill_directory(dir, &pathspec); |
329 | if (show_others) |
330 | show_other_files(dir); |
331 | if (show_killed) |
332 | show_killed_files(dir); |
333 | } |
334 | if (show_cached || show_stage) { |
335 | for (i = 0; i < active_nr(the_index.cache_nr); i++) { |
336 | const struct cache_entry *ce = active_cache(the_index.cache)[i]; |
337 | if ((dir->flags & DIR_SHOW_IGNORED) && |
338 | !ce_excluded(dir, ce)) |
339 | continue; |
340 | if (show_unmerged && !ce_stage(ce)(((0x3000) & (ce)->ce_flags) >> 12)) |
341 | continue; |
342 | if (ce->ce_flags & CE_UPDATE(1 << 16)) |
343 | continue; |
344 | show_ce_entry(ce_stage(ce)(((0x3000) & (ce)->ce_flags) >> 12) ? tag_unmerged : |
345 | (ce_skip_worktree(ce)((ce)->ce_flags & (1 << 30)) ? tag_skip_worktree : tag_cached), ce); |
346 | } |
347 | } |
348 | if (show_deleted || show_modified) { |
349 | for (i = 0; i < active_nr(the_index.cache_nr); i++) { |
350 | const struct cache_entry *ce = active_cache(the_index.cache)[i]; |
351 | struct stat st; |
352 | int err; |
353 | if ((dir->flags & DIR_SHOW_IGNORED) && |
354 | !ce_excluded(dir, ce)) |
355 | continue; |
356 | if (ce->ce_flags & CE_UPDATE(1 << 16)) |
357 | continue; |
358 | if (ce_skip_worktree(ce)((ce)->ce_flags & (1 << 30))) |
359 | continue; |
360 | err = lstat(ce->name, &st); |
361 | if (show_deleted && err) |
362 | show_ce_entry(tag_removed, ce); |
363 | if (show_modified && ce_modified(ce, &st, 0)ie_modified(&the_index, (ce), (&st), (0))) |
364 | show_ce_entry(tag_modified, ce); |
365 | } |
366 | } |
367 | } |
368 | |
369 | /* |
370 | * Prune the index to only contain stuff starting with "prefix" |
371 | */ |
372 | static void prune_cache(const char *prefix, size_t prefixlen) |
373 | { |
374 | int pos; |
375 | unsigned int first, last; |
376 | |
377 | if (!prefix) |
378 | return; |
379 | pos = cache_name_pos(prefix, prefixlen)index_name_pos(&the_index,(prefix),(prefixlen)); |
380 | if (pos < 0) |
381 | pos = -pos-1; |
382 | first = pos; |
383 | last = active_nr(the_index.cache_nr); |
384 | while (last > first) { |
385 | int next = (last + first) >> 1; |
386 | const struct cache_entry *ce = active_cache(the_index.cache)[next]; |
387 | if (!strncmp(ce->name, prefix, prefixlen)) { |
388 | first = next+1; |
389 | continue; |
390 | } |
391 | last = next; |
392 | } |
393 | memmove(active_cache, active_cache + pos,__builtin___memmove_chk ((the_index.cache), (the_index.cache) + pos, (last - pos) * sizeof(struct cache_entry *), __builtin_object_size ((the_index.cache), 0)) |
394 | (last - pos) * sizeof(struct cache_entry *))__builtin___memmove_chk ((the_index.cache), (the_index.cache) + pos, (last - pos) * sizeof(struct cache_entry *), __builtin_object_size ((the_index.cache), 0)); |
395 | active_nr(the_index.cache_nr) = last - pos; |
396 | } |
397 | |
398 | /* |
399 | * Read the tree specified with --with-tree option |
400 | * (typically, HEAD) into stage #1 and then |
401 | * squash them down to stage #0. This is used for |
402 | * --error-unmatch to list and check the path patterns |
403 | * that were given from the command line. We are not |
404 | * going to write this index out. |
405 | */ |
406 | void overlay_tree_on_cache(const char *tree_name, const char *prefix) |
407 | { |
408 | struct tree *tree; |
409 | unsigned char sha1[20]; |
410 | struct pathspec pathspec; |
411 | struct cache_entry *last_stage0 = NULL((void*)0); |
412 | int i; |
413 | |
414 | if (get_sha1(tree_name, sha1)) |
415 | die("tree-ish %s not found.", tree_name); |
416 | tree = parse_tree_indirect(sha1); |
417 | if (!tree) |
418 | die("bad tree-ish %s", tree_name); |
419 | |
420 | /* Hoist the unmerged entries up to stage #3 to make room */ |
421 | for (i = 0; i < active_nr(the_index.cache_nr); i++) { |
422 | struct cache_entry *ce = active_cache(the_index.cache)[i]; |
423 | if (!ce_stage(ce)(((0x3000) & (ce)->ce_flags) >> 12)) |
424 | continue; |
425 | ce->ce_flags |= CE_STAGEMASK(0x3000); |
426 | } |
427 | |
428 | if (prefix) { |
429 | static const char *(matchbuf[1]); |
430 | matchbuf[0] = NULL((void*)0); |
431 | parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC((1<<0) | (1<<1) | (1<<2) | (1<<3) | ( 1<<4) | (1<<5)), |
432 | PATHSPEC_PREFER_CWD(1<<0), prefix, matchbuf); |
433 | } else |
434 | memset(&pathspec, 0, sizeof(pathspec))__builtin___memset_chk (&pathspec, 0, sizeof(pathspec), __builtin_object_size (&pathspec, 0)); |
435 | if (read_tree(tree, 1, &pathspec)) |
436 | die("unable to read tree entries %s", tree_name); |
437 | |
438 | for (i = 0; i < active_nr(the_index.cache_nr); i++) { |
439 | struct cache_entry *ce = active_cache(the_index.cache)[i]; |
440 | switch (ce_stage(ce)(((0x3000) & (ce)->ce_flags) >> 12)) { |
441 | case 0: |
442 | last_stage0 = ce; |
443 | /* fallthru */ |
444 | default: |
445 | continue; |
446 | case 1: |
447 | /* |
448 | * If there is stage #0 entry for this, we do not |
449 | * need to show it. We use CE_UPDATE bit to mark |
450 | * such an entry. |
451 | */ |
452 | if (last_stage0 && |
453 | !strcmp(last_stage0->name, ce->name)) |
454 | ce->ce_flags |= CE_UPDATE(1 << 16); |
455 | } |
456 | } |
457 | } |
458 | |
459 | static const char * const ls_files_usage[] = { |
460 | N_("git ls-files [<options>] [<file>...]")("git ls-files [<options>] [<file>...]"), |
461 | NULL((void*)0) |
462 | }; |
463 | |
464 | static int option_parse_exclude(const struct option *opt, |
465 | const char *arg, int unset) |
466 | { |
467 | struct string_list *exclude_list = opt->value; |
468 | |
469 | exc_given = 1; |
470 | string_list_append(exclude_list, arg); |
471 | |
472 | return 0; |
473 | } |
474 | |
475 | static int option_parse_exclude_from(const struct option *opt, |
476 | const char *arg, int unset) |
477 | { |
478 | struct dir_struct *dir = opt->value; |
479 | |
480 | exc_given = 1; |
481 | add_excludes_from_file(dir, arg); |
482 | |
483 | return 0; |
484 | } |
485 | |
486 | static int option_parse_exclude_standard(const struct option *opt, |
487 | const char *arg, int unset) |
488 | { |
489 | struct dir_struct *dir = opt->value; |
490 | |
491 | exc_given = 1; |
492 | setup_standard_excludes(dir); |
493 | |
494 | return 0; |
495 | } |
496 | |
497 | int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) |
498 | { |
499 | int require_work_tree = 0, show_tag = 0, i; |
500 | const char *max_prefix; |
501 | struct dir_struct dir; |
502 | struct exclude_list *el; |
503 | struct string_list exclude_list = STRING_LIST_INIT_NODUP{ ((void*)0), 0, 0, 0, ((void*)0) }; |
504 | struct option builtin_ls_files_options[] = { |
505 | /* Think twice before adding "--nul" synonym to this */ |
506 | OPT_SET_INT('z', NULL, &line_terminator,{ OPTION_SET_INT, ('z'), (((void*)0)), (&line_terminator) , ((void*)0), (("paths are separated with NUL character")), PARSE_OPT_NOARG , ((void*)0), ('\0') } |
507 | N_("paths are separated with NUL character"), '\0'){ OPTION_SET_INT, ('z'), (((void*)0)), (&line_terminator) , ((void*)0), (("paths are separated with NUL character")), PARSE_OPT_NOARG , ((void*)0), ('\0') }, |
508 | OPT_BOOL('t', NULL, &show_tag,{ OPTION_SET_INT, ('t'), (((void*)0)), (&show_tag), ((void *)0), (("identify the file status with tags")), PARSE_OPT_NOARG , ((void*)0), (1) } |
509 | N_("identify the file status with tags")){ OPTION_SET_INT, ('t'), (((void*)0)), (&show_tag), ((void *)0), (("identify the file status with tags")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
510 | OPT_BOOL('v', NULL, &show_valid_bit,{ OPTION_SET_INT, ('v'), (((void*)0)), (&show_valid_bit), ((void*)0), (("use lowercase letters for 'assume unchanged' files" )), PARSE_OPT_NOARG, ((void*)0), (1) } |
511 | N_("use lowercase letters for 'assume unchanged' files")){ OPTION_SET_INT, ('v'), (((void*)0)), (&show_valid_bit), ((void*)0), (("use lowercase letters for 'assume unchanged' files" )), PARSE_OPT_NOARG, ((void*)0), (1) }, |
512 | OPT_BOOL('c', "cached", &show_cached,{ OPTION_SET_INT, ('c'), ("cached"), (&show_cached), ((void *)0), (("show cached files in the output (default)")), PARSE_OPT_NOARG , ((void*)0), (1) } |
513 | N_("show cached files in the output (default)")){ OPTION_SET_INT, ('c'), ("cached"), (&show_cached), ((void *)0), (("show cached files in the output (default)")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
514 | OPT_BOOL('d', "deleted", &show_deleted,{ OPTION_SET_INT, ('d'), ("deleted"), (&show_deleted), (( void*)0), (("show deleted files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) } |
515 | N_("show deleted files in the output")){ OPTION_SET_INT, ('d'), ("deleted"), (&show_deleted), (( void*)0), (("show deleted files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
516 | OPT_BOOL('m', "modified", &show_modified,{ OPTION_SET_INT, ('m'), ("modified"), (&show_modified), ( (void*)0), (("show modified files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) } |
517 | N_("show modified files in the output")){ OPTION_SET_INT, ('m'), ("modified"), (&show_modified), ( (void*)0), (("show modified files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
518 | OPT_BOOL('o', "others", &show_others,{ OPTION_SET_INT, ('o'), ("others"), (&show_others), ((void *)0), (("show other files in the output")), PARSE_OPT_NOARG, ( (void*)0), (1) } |
519 | N_("show other files in the output")){ OPTION_SET_INT, ('o'), ("others"), (&show_others), ((void *)0), (("show other files in the output")), PARSE_OPT_NOARG, ( (void*)0), (1) }, |
520 | OPT_BIT('i', "ignored", &dir.flags,{ OPTION_BIT, ('i'), ("ignored"), (&dir.flags), ((void*)0 ), (("show ignored files in the output")), PARSE_OPT_NOARG, ( (void*)0), (DIR_SHOW_IGNORED) } |
521 | N_("show ignored files in the output"),{ OPTION_BIT, ('i'), ("ignored"), (&dir.flags), ((void*)0 ), (("show ignored files in the output")), PARSE_OPT_NOARG, ( (void*)0), (DIR_SHOW_IGNORED) } |
522 | DIR_SHOW_IGNORED){ OPTION_BIT, ('i'), ("ignored"), (&dir.flags), ((void*)0 ), (("show ignored files in the output")), PARSE_OPT_NOARG, ( (void*)0), (DIR_SHOW_IGNORED) }, |
523 | OPT_BOOL('s', "stage", &show_stage,{ OPTION_SET_INT, ('s'), ("stage"), (&show_stage), ((void *)0), (("show staged contents' object name in the output")), PARSE_OPT_NOARG , ((void*)0), (1) } |
524 | N_("show staged contents' object name in the output")){ OPTION_SET_INT, ('s'), ("stage"), (&show_stage), ((void *)0), (("show staged contents' object name in the output")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
525 | OPT_BOOL('k', "killed", &show_killed,{ OPTION_SET_INT, ('k'), ("killed"), (&show_killed), ((void *)0), (("show files on the filesystem that need to be removed" )), PARSE_OPT_NOARG, ((void*)0), (1) } |
526 | N_("show files on the filesystem that need to be removed")){ OPTION_SET_INT, ('k'), ("killed"), (&show_killed), ((void *)0), (("show files on the filesystem that need to be removed" )), PARSE_OPT_NOARG, ((void*)0), (1) }, |
527 | OPT_BIT(0, "directory", &dir.flags,{ OPTION_BIT, (0), ("directory"), (&dir.flags), ((void*)0 ), (("show 'other' directories' names only")), PARSE_OPT_NOARG , ((void*)0), (DIR_SHOW_OTHER_DIRECTORIES) } |
528 | N_("show 'other' directories' names only"),{ OPTION_BIT, (0), ("directory"), (&dir.flags), ((void*)0 ), (("show 'other' directories' names only")), PARSE_OPT_NOARG , ((void*)0), (DIR_SHOW_OTHER_DIRECTORIES) } |
529 | DIR_SHOW_OTHER_DIRECTORIES){ OPTION_BIT, (0), ("directory"), (&dir.flags), ((void*)0 ), (("show 'other' directories' names only")), PARSE_OPT_NOARG , ((void*)0), (DIR_SHOW_OTHER_DIRECTORIES) }, |
530 | OPT_BOOL(0, "eol", &show_eol, N_("show line endings of files")){ OPTION_SET_INT, (0), ("eol"), (&show_eol), ((void*)0), ( ("show line endings of files")), PARSE_OPT_NOARG, ((void*)0), (1) }, |
531 | OPT_NEGBIT(0, "empty-directory", &dir.flags,{ OPTION_NEGBIT, (0), ("empty-directory"), (&dir.flags), ( (void*)0), (("don't show empty directories")), PARSE_OPT_NOARG , ((void*)0), (DIR_HIDE_EMPTY_DIRECTORIES) } |
532 | N_("don't show empty directories"),{ OPTION_NEGBIT, (0), ("empty-directory"), (&dir.flags), ( (void*)0), (("don't show empty directories")), PARSE_OPT_NOARG , ((void*)0), (DIR_HIDE_EMPTY_DIRECTORIES) } |
533 | DIR_HIDE_EMPTY_DIRECTORIES){ OPTION_NEGBIT, (0), ("empty-directory"), (&dir.flags), ( (void*)0), (("don't show empty directories")), PARSE_OPT_NOARG , ((void*)0), (DIR_HIDE_EMPTY_DIRECTORIES) }, |
534 | OPT_BOOL('u', "unmerged", &show_unmerged,{ OPTION_SET_INT, ('u'), ("unmerged"), (&show_unmerged), ( (void*)0), (("show unmerged files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) } |
535 | N_("show unmerged files in the output")){ OPTION_SET_INT, ('u'), ("unmerged"), (&show_unmerged), ( (void*)0), (("show unmerged files in the output")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
536 | OPT_BOOL(0, "resolve-undo", &show_resolve_undo,{ OPTION_SET_INT, (0), ("resolve-undo"), (&show_resolve_undo ), ((void*)0), (("show resolve-undo information")), PARSE_OPT_NOARG , ((void*)0), (1) } |
537 | N_("show resolve-undo information")){ OPTION_SET_INT, (0), ("resolve-undo"), (&show_resolve_undo ), ((void*)0), (("show resolve-undo information")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
538 | { OPTION_CALLBACK, 'x', "exclude", &exclude_list, N_("pattern")("pattern"), |
539 | N_("skip files matching pattern")("skip files matching pattern"), |
540 | 0, option_parse_exclude }, |
541 | { OPTION_CALLBACK, 'X', "exclude-from", &dir, N_("file")("file"), |
542 | N_("exclude patterns are read from <file>")("exclude patterns are read from <file>"), |
543 | 0, option_parse_exclude_from }, |
544 | OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, N_("file"),{ OPTION_STRING, (0), ("exclude-per-directory"), (&dir.exclude_per_dir ), (("file")), (("read additional per-directory exclude patterns in <file>" )) } |
545 | N_("read additional per-directory exclude patterns in <file>")){ OPTION_STRING, (0), ("exclude-per-directory"), (&dir.exclude_per_dir ), (("file")), (("read additional per-directory exclude patterns in <file>" )) }, |
546 | { OPTION_CALLBACK, 0, "exclude-standard", &dir, NULL((void*)0), |
547 | N_("add the standard git exclusions")("add the standard git exclusions"), |
548 | PARSE_OPT_NOARG, option_parse_exclude_standard }, |
549 | { OPTION_SET_INT, 0, "full-name", &prefix_len, NULL((void*)0), |
550 | N_("make the output relative to the project top directory")("make the output relative to the project top directory"), |
551 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL((void*)0) }, |
552 | OPT_BOOL(0, "recurse-submodules", &recurse_submodules,{ OPTION_SET_INT, (0), ("recurse-submodules"), (&recurse_submodules ), ((void*)0), (("recurse through submodules")), PARSE_OPT_NOARG , ((void*)0), (1) } |
553 | N_("recurse through submodules")){ OPTION_SET_INT, (0), ("recurse-submodules"), (&recurse_submodules ), ((void*)0), (("recurse through submodules")), PARSE_OPT_NOARG , ((void*)0), (1) }, |
554 | OPT_BOOL(0, "error-unmatch", &error_unmatch,{ OPTION_SET_INT, (0), ("error-unmatch"), (&error_unmatch ), ((void*)0), (("if any <file> is not in the index, treat this as an error" )), PARSE_OPT_NOARG, ((void*)0), (1) } |
555 | N_("if any <file> is not in the index, treat this as an error")){ OPTION_SET_INT, (0), ("error-unmatch"), (&error_unmatch ), ((void*)0), (("if any <file> is not in the index, treat this as an error" )), PARSE_OPT_NOARG, ((void*)0), (1) }, |
556 | OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"),{ OPTION_STRING, (0), ("with-tree"), (&with_tree), (("tree-ish" )), (("pretend that paths removed since <tree-ish> are still present" )) } |
557 | N_("pretend that paths removed since <tree-ish> are still present")){ OPTION_STRING, (0), ("with-tree"), (&with_tree), (("tree-ish" )), (("pretend that paths removed since <tree-ish> are still present" )) }, |
558 | OPT__ABBREV(&abbrev){ OPTION_CALLBACK, 0, "abbrev", (&abbrev), ("n"), ("use <n> digits to display SHA-1s" ), PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }, |
559 | OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")){ OPTION_SET_INT, (0), ("debug"), (&debug_mode), ((void*) 0), (("show debugging data")), PARSE_OPT_NOARG, ((void*)0), ( 1) }, |
560 | OPT_END(){ OPTION_END } |
561 | }; |
562 | |
563 | if (argc == 2 && !strcmp(argv[1], "-h")) |
564 | usage_with_options(ls_files_usage, builtin_ls_files_options); |
565 | |
566 | memset(&dir, 0, sizeof(dir))__builtin___memset_chk (&dir, 0, sizeof(dir), __builtin_object_size (&dir, 0)); |
567 | prefix = cmd_prefix; |
568 | if (prefix) |
569 | prefix_len = strlen(prefix); |
570 | super_prefix = get_super_prefix(); |
571 | git_config(git_default_config, NULL((void*)0)); |
572 | |
573 | if (read_cache()read_index(&the_index) < 0) |
574 | die("index file corrupt"); |
575 | |
576 | argc = parse_options(argc, argv, prefix, builtin_ls_files_options, |
Value stored to 'argc' is never read | |
577 | ls_files_usage, 0); |
578 | el = add_exclude_list(&dir, EXC_CMDL0, "--exclude option"); |
579 | for (i = 0; i < exclude_list.nr; i++) { |
580 | add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args); |
581 | } |
582 | if (show_tag || show_valid_bit) { |
583 | tag_cached = "H "; |
584 | tag_unmerged = "M "; |
585 | tag_removed = "R "; |
586 | tag_modified = "C "; |
587 | tag_other = "? "; |
588 | tag_killed = "K "; |
589 | tag_skip_worktree = "S "; |
590 | tag_resolve_undo = "U "; |
591 | } |
592 | if (show_modified || show_others || show_deleted || (dir.flags & DIR_SHOW_IGNORED) || show_killed) |
593 | require_work_tree = 1; |
594 | if (show_unmerged) |
595 | /* |
596 | * There's no point in showing unmerged unless |
597 | * you also show the stage information. |
598 | */ |
599 | show_stage = 1; |
600 | if (dir.exclude_per_dir) |
601 | exc_given = 1; |
602 | |
603 | if (require_work_tree && !is_inside_work_tree()) |
604 | setup_work_tree(); |
605 | |
606 | if (recurse_submodules) |
607 | compile_submodule_options(&dir, show_tag); |
608 | |
609 | if (recurse_submodules && |
610 | (show_stage || show_deleted || show_others || show_unmerged || |
611 | show_killed || show_modified || show_resolve_undo || with_tree)) |
612 | die("ls-files --recurse-submodules unsupported mode"); |
613 | |
614 | if (recurse_submodules && error_unmatch) |
615 | die("ls-files --recurse-submodules does not support " |
616 | "--error-unmatch"); |
617 | |
618 | parse_pathspec(&pathspec, 0, |
619 | PATHSPEC_PREFER_CWD(1<<0) | |
620 | PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP(1<<3), |
621 | prefix, argv); |
622 | |
623 | /* |
624 | * Find common prefix for all pathspec's |
625 | * This is used as a performance optimization which unfortunately cannot |
626 | * be done when recursing into submodules |
627 | */ |
628 | if (recurse_submodules) |
629 | max_prefix = NULL((void*)0); |
630 | else |
631 | max_prefix = common_prefix(&pathspec); |
632 | max_prefix_len = max_prefix ? strlen(max_prefix) : 0; |
633 | |
634 | /* Treat unmatching pathspec elements as errors */ |
635 | if (pathspec.nr && error_unmatch) |
636 | ps_matched = xcalloc(pathspec.nr, 1); |
637 | |
638 | if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) |
639 | die("ls-files --ignored needs some exclude pattern"); |
640 | |
641 | /* With no flags, we default to showing the cached files */ |
642 | if (!(show_stage || show_deleted || show_others || show_unmerged || |
643 | show_killed || show_modified || show_resolve_undo)) |
644 | show_cached = 1; |
645 | |
646 | prune_cache(max_prefix, max_prefix_len); |
647 | if (with_tree) { |
648 | /* |
649 | * Basic sanity check; show-stages and show-unmerged |
650 | * would not make any sense with this option. |
651 | */ |
652 | if (show_stage || show_unmerged) |
653 | die("ls-files --with-tree is incompatible with -s or -u"); |
654 | overlay_tree_on_cache(with_tree, max_prefix); |
655 | } |
656 | show_files(&dir); |
657 | if (show_resolve_undo) |
658 | show_ru_info(); |
659 | |
660 | if (ps_matched) { |
661 | int bad; |
662 | bad = report_path_error(ps_matched, &pathspec, prefix); |
663 | if (bad) |
664 | fprintf(stderr__stderrp, "Did you forget to 'git add'?\n"); |
665 | |
666 | return bad ? 1 : 0; |
667 | } |
668 | |
669 | return 0; |
670 | } |