Check if a regular file should be skipped (filters + gitignore + size). */ Classify why a file is skipped. Returns a static reason string (the #963 * "purposely not indexed" class) or NULL to keep the file. Check order and * semantics — including the .cbmignore negation un-ignoring a global-gitignore * match — are IDENTICAL to the original boolean predicate. */
| 644 | * semantics — including the .cbmignore negation un-ignoring a global-gitignore |
| 645 | * match — are IDENTICAL to the original boolean predicate. */ |
| 646 | static const char *file_skip_reason(const char *entry_name, const char *rel_path, |
| 647 | const cbm_discover_opts_t *opts, |
| 648 | const cbm_gitignore_t *gitignore, |
| 649 | const cbm_gitignore_t *global_gi, |
| 650 | const cbm_gitignore_t *cbmignore, |
| 651 | const cbm_gitignore_t *local_gi, const char *local_gi_prefix, |
| 652 | off_t file_size) { |
| 653 | cbm_index_mode_t mode = opts ? opts->mode : CBM_MODE_FULL; |
| 654 | if (cbm_has_ignored_suffix(entry_name, mode)) { |
| 655 | return "ignored-suffix"; |
| 656 | } |
| 657 | if (cbm_should_skip_filename(entry_name, mode)) { |
| 658 | return "skip-list"; |
| 659 | } |
| 660 | if (cbm_matches_fast_pattern(entry_name, mode)) { |
| 661 | return "fast-pattern"; |
| 662 | } |
| 663 | if (gitignore && cbm_gitignore_matches(gitignore, rel_path, false)) { |
| 664 | return "gitignore"; |
| 665 | } |
| 666 | bool global_ignored = global_gi && cbm_gitignore_matches(global_gi, rel_path, false); |
| 667 | if (local_gi) { |
| 668 | const char *lrel = local_rel_path(rel_path, local_gi_prefix); |
| 669 | if (cbm_gitignore_matches(local_gi, lrel, false)) { |
| 670 | return "gitignore"; |
| 671 | } |
| 672 | } |
| 673 | if (cbmignore) { |
| 674 | int cbm_result = cbm_gitignore_match_result(cbmignore, rel_path, false); |
| 675 | if (cbm_result > 0) { |
| 676 | return "cbmignore"; |
| 677 | } |
| 678 | if (cbm_result < 0 && global_ignored) { |
| 679 | global_ignored = false; |
| 680 | } |
| 681 | } |
| 682 | if (opts && opts->max_file_size > 0 && file_size > opts->max_file_size) { |
| 683 | return "size-cap"; |
| 684 | } |
| 685 | return global_ignored ? "gitignore" : NULL; |
| 686 | } |
| 687 | |
| 688 | /* Detect language for a file, handling .m disambiguation and JSON filtering. */ |
| 689 | static CBMLanguage detect_file_language(const char *entry_name, const char *abs_path) { |
no test coverage detected