| 691 | static int in_expand_to_path = 0; |
| 692 | |
| 693 | void expand_to_path(struct index_state *istate, |
| 694 | const char *path, size_t pathlen, int icase) |
| 695 | { |
| 696 | struct strbuf path_mutable = STRBUF_INIT; |
| 697 | size_t substr_len; |
| 698 | |
| 699 | /* prevent extra recursion */ |
| 700 | if (in_expand_to_path) |
| 701 | return; |
| 702 | |
| 703 | if (!istate->sparse_index) |
| 704 | return; |
| 705 | |
| 706 | in_expand_to_path = 1; |
| 707 | |
| 708 | /* |
| 709 | * We only need to actually expand a region if the |
| 710 | * following are both true: |
| 711 | * |
| 712 | * 1. 'path' is not already in the index. |
| 713 | * 2. Some parent directory of 'path' is a sparse directory. |
| 714 | */ |
| 715 | |
| 716 | if (index_file_exists(istate, path, pathlen, icase)) |
| 717 | goto cleanup; |
| 718 | |
| 719 | strbuf_add(&path_mutable, path, pathlen); |
| 720 | strbuf_addch(&path_mutable, '/'); |
| 721 | |
| 722 | /* Check the name hash for all parent directories */ |
| 723 | substr_len = 0; |
| 724 | while (substr_len < pathlen) { |
| 725 | char temp; |
| 726 | char *replace = strchr(path_mutable.buf + substr_len, '/'); |
| 727 | |
| 728 | if (!replace) |
| 729 | break; |
| 730 | |
| 731 | /* replace the character _after_ the slash */ |
| 732 | replace++; |
| 733 | temp = *replace; |
| 734 | *replace = '\0'; |
| 735 | substr_len = replace - path_mutable.buf; |
| 736 | if (index_file_exists(istate, path_mutable.buf, |
| 737 | substr_len, icase)) { |
| 738 | /* |
| 739 | * We found a parent directory in the name-hash |
| 740 | * hashtable, because only sparse directory entries |
| 741 | * have a trailing '/' character. Since "path" wasn't |
| 742 | * in the index, perhaps it exists within this |
| 743 | * sparse-directory. Expand accordingly. |
| 744 | */ |
| 745 | ensure_full_index(istate); |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | *replace = temp; |
| 750 | } |
no test coverage detected