* Determine whether the path specified by 'p' should be unpacked as a new * sparse directory in a sparse index. A new sparse directory 'A/': * - must be outside the sparse cone. * - must not already be in the index (i.e., no index entry with name 'A/' * exists). * - must not have any child entries in the index (i.e., no index entry * 'A/ ' exists). * If 'p' meets the above req
| 1105 | * If 'p' meets the above requirements, return 1; otherwise, return 0. |
| 1106 | */ |
| 1107 | static int entry_is_new_sparse_dir(const struct traverse_info *info, |
| 1108 | const struct name_entry *p) |
| 1109 | { |
| 1110 | int res, pos; |
| 1111 | struct strbuf dirpath = STRBUF_INIT; |
| 1112 | struct unpack_trees_options *o = info->data; |
| 1113 | |
| 1114 | if (!S_ISDIR(p->mode)) |
| 1115 | return 0; |
| 1116 | |
| 1117 | /* |
| 1118 | * If the path is inside the sparse cone, it can't be a sparse directory. |
| 1119 | */ |
| 1120 | strbuf_add(&dirpath, info->traverse_path, info->pathlen); |
| 1121 | strbuf_add(&dirpath, p->path, p->pathlen); |
| 1122 | strbuf_addch(&dirpath, '/'); |
| 1123 | if (path_in_cone_mode_sparse_checkout(dirpath.buf, o->src_index)) { |
| 1124 | res = 0; |
| 1125 | goto cleanup; |
| 1126 | } |
| 1127 | |
| 1128 | pos = index_name_pos_sparse(o->src_index, dirpath.buf, dirpath.len); |
| 1129 | if (pos >= 0) { |
| 1130 | /* Path is already in the index, not a new sparse dir */ |
| 1131 | res = 0; |
| 1132 | goto cleanup; |
| 1133 | } |
| 1134 | |
| 1135 | /* Where would this sparse dir be inserted into the index? */ |
| 1136 | pos = -pos - 1; |
| 1137 | if (pos >= o->src_index->cache_nr) { |
| 1138 | /* |
| 1139 | * Sparse dir would be inserted at the end of the index, so we |
| 1140 | * know it has no child entries. |
| 1141 | */ |
| 1142 | res = 1; |
| 1143 | goto cleanup; |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * If the dir has child entries in the index, the first would be at the |
| 1148 | * position the sparse directory would be inserted. If the entry at this |
| 1149 | * position is inside the dir, not a new sparse dir. |
| 1150 | */ |
| 1151 | res = strncmp(o->src_index->cache[pos]->name, dirpath.buf, dirpath.len); |
| 1152 | |
| 1153 | cleanup: |
| 1154 | strbuf_release(&dirpath); |
| 1155 | return res; |
| 1156 | } |
| 1157 | |
| 1158 | /* |
| 1159 | * Note that traverse_by_cache_tree() duplicates some logic in this function |
no test coverage detected