Changeset 782 for git/branches/dmik/builtin/ls-files.c
- Timestamp:
- Jun 23, 2014, 9:45:51 PM (11 years ago)
- Location:
- git/branches/dmik
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
git/branches/dmik ¶
- Property svn:mergeinfo changed
/git/vendor/2.0.0 (added) merged: 777 /git/vendor/current merged: 772,774,776
- Property svn:mergeinfo changed
-
TabularUnified git/branches/dmik/builtin/ls-files.c ¶
r626 r782 14 14 #include "resolve-undo.h" 15 15 #include "string-list.h" 16 #include "pathspec.h" 16 17 17 18 static int abbrev; … … 31 32 static int max_prefix_len; 32 33 static int prefix_len; 33 static const char **pathspec;34 static struct pathspec pathspec; 34 35 static int error_unmatch; 35 36 static char *ps_matched; 36 37 static const char *with_tree; 37 38 static int exc_given; 39 static int exclude_args; 38 40 39 41 static const char *tag_cached = ""; … … 46 48 static const char *tag_resolve_undo = ""; 47 49 48 static void write_name(const char* name, size_t len) 49 { 50 write_name_quoted_relative(name, len, prefix, prefix_len, stdout, 51 line_terminator); 50 static void write_name(const char *name) 51 { 52 /* 53 * With "--full-name", prefix_len=0; this caller needs to pass 54 * an empty string in that case (a NULL is good for ""). 55 */ 56 write_name_quoted_relative(name, prefix_len ? prefix : NULL, 57 stdout, line_terminator); 52 58 } 53 59 … … 59 65 die("git ls-files: internal error - directory entry not superset of prefix"); 60 66 61 if (! match_pathspec(pathspec, ent->name, ent->len, len, ps_matched))67 if (!dir_path_match(ent, &pathspec, len, ps_matched)) 62 68 return; 63 69 64 70 fputs(tag, stdout); 65 write_name(ent->name , ent->len);71 write_name(ent->name); 66 72 } 67 73 … … 127 133 } 128 134 129 static void show_ce_entry(const char *tag, struct cache_entry *ce)135 static void show_ce_entry(const char *tag, const struct cache_entry *ce) 130 136 { 131 137 int len = max_prefix_len; … … 134 140 die("git ls-files: internal error - cache entry not superset of prefix"); 135 141 136 if (!match_pathspec(pathspec, ce->name, ce_namelen(ce), len, ps_matched)) 142 if (!match_pathspec(&pathspec, ce->name, ce_namelen(ce), 143 len, ps_matched, 144 S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode))) 137 145 return; 138 146 … … 163 171 ce_stage(ce)); 164 172 } 165 write_name(ce->name , ce_namelen(ce));173 write_name(ce->name); 166 174 if (debug_mode) { 167 printf(" ctime: %d:%d\n", ce->ce_ctime.sec, ce->ce_ctime.nsec); 168 printf(" mtime: %d:%d\n", ce->ce_mtime.sec, ce->ce_mtime.nsec); 169 printf(" dev: %d\tino: %d\n", ce->ce_dev, ce->ce_ino); 170 printf(" uid: %d\tgid: %d\n", ce->ce_uid, ce->ce_gid); 171 printf(" size: %d\tflags: %x\n", ce->ce_size, ce->ce_flags); 175 const struct stat_data *sd = &ce->ce_stat_data; 176 177 printf(" ctime: %d:%d\n", sd->sd_ctime.sec, sd->sd_ctime.nsec); 178 printf(" mtime: %d:%d\n", sd->sd_mtime.sec, sd->sd_mtime.nsec); 179 printf(" dev: %d\tino: %d\n", sd->sd_dev, sd->sd_ino); 180 printf(" uid: %d\tgid: %d\n", sd->sd_uid, sd->sd_gid); 181 printf(" size: %d\tflags: %x\n", sd->sd_size, ce->ce_flags); 172 182 } 173 183 } … … 188 198 if (len < max_prefix_len) 189 199 continue; /* outside of the prefix */ 190 if (!match_pathspec(pathspec, path, len, max_prefix_len, ps_matched)) 200 if (!match_pathspec(&pathspec, path, len, 201 max_prefix_len, ps_matched, 0)) 191 202 continue; /* uninterested */ 192 203 for (i = 0; i < 3; i++) { … … 196 207 find_unique_abbrev(ui->sha1[i], abbrev), 197 208 i + 1); 198 write_name(path, len); 199 } 200 } 209 write_name(path); 210 } 211 } 212 } 213 214 static int ce_excluded(struct dir_struct *dir, const struct cache_entry *ce) 215 { 216 int dtype = ce_to_dtype(ce); 217 return is_excluded(dir, ce->name, &dtype); 201 218 } 202 219 … … 207 224 /* For cached/deleted files we don't need to even do the readdir */ 208 225 if (show_others || show_killed) { 209 fill_directory(dir, pathspec); 226 if (!show_others) 227 dir->flags |= DIR_COLLECT_KILLED_ONLY; 228 fill_directory(dir, &pathspec); 210 229 if (show_others) 211 230 show_other_files(dir); … … 213 232 show_killed_files(dir); 214 233 } 215 if (show_cached | show_stage) {234 if (show_cached || show_stage) { 216 235 for (i = 0; i < active_nr; i++) { 217 struct cache_entry *ce = active_cache[i]; 218 int dtype = ce_to_dtype(ce); 219 if (dir->flags & DIR_SHOW_IGNORED && 220 !excluded(dir, ce->name, &dtype)) 236 const struct cache_entry *ce = active_cache[i]; 237 if ((dir->flags & DIR_SHOW_IGNORED) && 238 !ce_excluded(dir, ce)) 221 239 continue; 222 240 if (show_unmerged && !ce_stage(ce)) … … 228 246 } 229 247 } 230 if (show_deleted | show_modified) {248 if (show_deleted || show_modified) { 231 249 for (i = 0; i < active_nr; i++) { 232 struct cache_entry *ce = active_cache[i];250 const struct cache_entry *ce = active_cache[i]; 233 251 struct stat st; 234 252 int err; 235 int dtype = ce_to_dtype(ce); 236 if (dir->flags & DIR_SHOW_IGNORED && 237 !excluded(dir, ce->name, &dtype)) 253 if ((dir->flags & DIR_SHOW_IGNORED) && 254 !ce_excluded(dir, ce)) 238 255 continue; 239 256 if (ce->ce_flags & CE_UPDATE) … … 267 284 while (last > first) { 268 285 int next = (last + first) >> 1; 269 struct cache_entry *ce = active_cache[next];286 const struct cache_entry *ce = active_cache[next]; 270 287 if (!strncmp(ce->name, prefix, max_prefix_len)) { 271 288 first = next+1; … … 275 292 } 276 293 active_nr = last; 277 }278 279 static void strip_trailing_slash_from_submodules(void)280 {281 const char **p;282 283 for (p = pathspec; *p != NULL; p++) {284 int len = strlen(*p), pos;285 286 if (len < 1 || (*p)[len - 1] != '/')287 continue;288 pos = cache_name_pos(*p, len - 1);289 if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))290 *p = xstrndup(*p, len - 1);291 }292 294 } 293 295 … … 323 325 324 326 if (prefix) { 325 static const char *(matchbuf[2]); 326 matchbuf[0] = prefix; 327 matchbuf[1] = NULL; 328 init_pathspec(&pathspec, matchbuf); 329 pathspec.items[0].use_wildcard = 0; 327 static const char *(matchbuf[1]); 328 matchbuf[0] = NULL; 329 parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC, 330 PATHSPEC_PREFER_CWD, prefix, matchbuf); 330 331 } else 331 init_pathspec(&pathspec, NULL);332 memset(&pathspec, 0, sizeof(pathspec)); 332 333 if (read_tree(tree, 1, &pathspec)) 333 334 die("unable to read tree entries %s", tree_name); … … 354 355 } 355 356 356 int report_path_error(const char *ps_matched, const char **pathspec, const char *prefix) 357 int report_path_error(const char *ps_matched, 358 const struct pathspec *pathspec, 359 const char *prefix) 357 360 { 358 361 /* … … 360 363 */ 361 364 struct strbuf sb = STRBUF_INIT; 362 const char *name;363 365 int num, errors = 0; 364 for (num = 0; pathspec[num]; num++) {366 for (num = 0; num < pathspec->nr; num++) { 365 367 int other, found_dup; 366 368 … … 370 372 * The caller might have fed identical pathspec 371 373 * twice. Do not barf on such a mistake. 374 * FIXME: parse_pathspec should have eliminated 375 * duplicate pathspec. 372 376 */ 373 377 for (found_dup = other = 0; 374 !found_dup && pathspec[other];378 !found_dup && other < pathspec->nr; 375 379 other++) { 376 380 if (other == num || !ps_matched[other]) 377 381 continue; 378 if (!strcmp(pathspec[other], pathspec[num])) 382 if (!strcmp(pathspec->items[other].original, 383 pathspec->items[num].original)) 379 384 /* 380 385 * Ok, we have a match already. … … 385 390 continue; 386 391 387 name = quote_path_relative(pathspec[num], -1, &sb, prefix);388 392 error("pathspec '%s' did not match any file(s) known to git.", 389 name);393 pathspec->items[num].original); 390 394 errors++; 391 395 } … … 395 399 396 400 static const char * const ls_files_usage[] = { 397 "git ls-files [options] [<file>...]",401 N_("git ls-files [options] [<file>...]"), 398 402 NULL 399 403 }; … … 410 414 const char *arg, int unset) 411 415 { 412 struct exclude_list *list = opt->value;416 struct string_list *exclude_list = opt->value; 413 417 414 418 exc_given = 1; 415 add_exclude(arg, "", 0, list);419 string_list_append(exclude_list, arg); 416 420 417 421 return 0; … … 442 446 int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) 443 447 { 444 int require_work_tree = 0, show_tag = 0 ;448 int require_work_tree = 0, show_tag = 0, i; 445 449 const char *max_prefix; 446 450 struct dir_struct dir; 451 struct exclude_list *el; 452 struct string_list exclude_list = STRING_LIST_INIT_NODUP; 447 453 struct option builtin_ls_files_options[] = { 448 454 { OPTION_CALLBACK, 'z', NULL, NULL, NULL, 449 "paths are separated with NUL character",455 N_("paths are separated with NUL character"), 450 456 PARSE_OPT_NOARG, option_parse_z }, 451 OPT_BOOL EAN('t', NULL, &show_tag,452 "identify the file status with tags"),453 OPT_BOOL EAN('v', NULL, &show_valid_bit,454 "use lowercase letters for 'assume unchanged' files"),455 OPT_BOOL EAN('c', "cached", &show_cached,456 "show cached files in the output (default)"),457 OPT_BOOL EAN('d', "deleted", &show_deleted,458 "show deleted files in the output"),459 OPT_BOOL EAN('m', "modified", &show_modified,460 "show modified files in the output"),461 OPT_BOOL EAN('o', "others", &show_others,462 "show other files in the output"),457 OPT_BOOL('t', NULL, &show_tag, 458 N_("identify the file status with tags")), 459 OPT_BOOL('v', NULL, &show_valid_bit, 460 N_("use lowercase letters for 'assume unchanged' files")), 461 OPT_BOOL('c', "cached", &show_cached, 462 N_("show cached files in the output (default)")), 463 OPT_BOOL('d', "deleted", &show_deleted, 464 N_("show deleted files in the output")), 465 OPT_BOOL('m', "modified", &show_modified, 466 N_("show modified files in the output")), 467 OPT_BOOL('o', "others", &show_others, 468 N_("show other files in the output")), 463 469 OPT_BIT('i', "ignored", &dir.flags, 464 "show ignored files in the output",470 N_("show ignored files in the output"), 465 471 DIR_SHOW_IGNORED), 466 OPT_BOOL EAN('s', "stage", &show_stage,467 "show staged contents' object name in the output"),468 OPT_BOOL EAN('k', "killed", &show_killed,469 "show files on the filesystem that need to be removed"),472 OPT_BOOL('s', "stage", &show_stage, 473 N_("show staged contents' object name in the output")), 474 OPT_BOOL('k', "killed", &show_killed, 475 N_("show files on the filesystem that need to be removed")), 470 476 OPT_BIT(0, "directory", &dir.flags, 471 "show 'other' directories' name only",477 N_("show 'other' directories' name only"), 472 478 DIR_SHOW_OTHER_DIRECTORIES), 473 479 OPT_NEGBIT(0, "empty-directory", &dir.flags, 474 "don't show empty directories",480 N_("don't show empty directories"), 475 481 DIR_HIDE_EMPTY_DIRECTORIES), 476 OPT_BOOL EAN('u', "unmerged", &show_unmerged,477 "show unmerged files in the output"),478 OPT_BOOL EAN(0, "resolve-undo", &show_resolve_undo,479 "show resolve-undo information"),480 { OPTION_CALLBACK, 'x', "exclude", & dir.exclude_list[EXC_CMDL], "pattern",481 "skip files matching pattern",482 OPT_BOOL('u', "unmerged", &show_unmerged, 483 N_("show unmerged files in the output")), 484 OPT_BOOL(0, "resolve-undo", &show_resolve_undo, 485 N_("show resolve-undo information")), 486 { OPTION_CALLBACK, 'x', "exclude", &exclude_list, N_("pattern"), 487 N_("skip files matching pattern"), 482 488 0, option_parse_exclude }, 483 { OPTION_CALLBACK, 'X', "exclude-from", &dir, "file",484 "exclude patterns are read from <file>",489 { OPTION_CALLBACK, 'X', "exclude-from", &dir, N_("file"), 490 N_("exclude patterns are read from <file>"), 485 491 0, option_parse_exclude_from }, 486 OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, "file",487 "read additional per-directory exclude patterns in <file>"),492 OPT_STRING(0, "exclude-per-directory", &dir.exclude_per_dir, N_("file"), 493 N_("read additional per-directory exclude patterns in <file>")), 488 494 { OPTION_CALLBACK, 0, "exclude-standard", &dir, NULL, 489 "add the standard git exclusions",495 N_("add the standard git exclusions"), 490 496 PARSE_OPT_NOARG, option_parse_exclude_standard }, 491 497 { OPTION_SET_INT, 0, "full-name", &prefix_len, NULL, 492 "make the output relative to the project top directory",498 N_("make the output relative to the project top directory"), 493 499 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL }, 494 OPT_BOOL EAN(0, "error-unmatch", &error_unmatch,495 "if any <file> is not in the index, treat this as an error"),496 OPT_STRING(0, "with-tree", &with_tree, "tree-ish",497 "pretend that paths removed since <tree-ish> are still present"),500 OPT_BOOL(0, "error-unmatch", &error_unmatch, 501 N_("if any <file> is not in the index, treat this as an error")), 502 OPT_STRING(0, "with-tree", &with_tree, N_("tree-ish"), 503 N_("pretend that paths removed since <tree-ish> are still present")), 498 504 OPT__ABBREV(&abbrev), 499 OPT_BOOL EAN(0, "debug", &debug_mode, "show debugging data"),505 OPT_BOOL(0, "debug", &debug_mode, N_("show debugging data")), 500 506 OPT_END() 501 507 }; … … 515 521 argc = parse_options(argc, argv, prefix, builtin_ls_files_options, 516 522 ls_files_usage, 0); 523 el = add_exclude_list(&dir, EXC_CMDL, "--exclude option"); 524 for (i = 0; i < exclude_list.nr; i++) { 525 add_exclude(exclude_list.items[i].string, "", 0, el, --exclude_args); 526 } 517 527 if (show_tag || show_valid_bit) { 518 528 tag_cached = "H "; … … 539 549 setup_work_tree(); 540 550 541 pathspec = get_pathspec(prefix, argv); 542 543 /* be nice with submodule paths ending in a slash */ 544 if (pathspec) 545 strip_trailing_slash_from_submodules(); 551 parse_pathspec(&pathspec, 0, 552 PATHSPEC_PREFER_CWD | 553 PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP, 554 prefix, argv); 546 555 547 556 /* Find common prefix for all pathspec's */ 548 max_prefix = common_prefix( pathspec);557 max_prefix = common_prefix(&pathspec); 549 558 max_prefix_len = max_prefix ? strlen(max_prefix) : 0; 550 559 551 560 /* Treat unmatching pathspec elements as errors */ 552 if (pathspec && error_unmatch) { 553 int num; 554 for (num = 0; pathspec[num]; num++) 555 ; 556 ps_matched = xcalloc(1, num); 557 } 561 if (pathspec.nr && error_unmatch) 562 ps_matched = xcalloc(1, pathspec.nr); 558 563 559 564 if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) … … 561 566 562 567 /* With no flags, we default to showing the cached files */ 563 if (!(show_stage | show_deleted | show_others | show_unmerged|564 show_killed | show_modified| show_resolve_undo))568 if (!(show_stage || show_deleted || show_others || show_unmerged || 569 show_killed || show_modified || show_resolve_undo)) 565 570 show_cached = 1; 566 571 … … 582 587 if (ps_matched) { 583 588 int bad; 584 bad = report_path_error(ps_matched, pathspec, prefix);589 bad = report_path_error(ps_matched, &pathspec, prefix); 585 590 if (bad) 586 591 fprintf(stderr, "Did you forget to 'git add'?\n");
Note:
See TracChangeset
for help on using the changeset viewer.