* Handle a tree object and determine if we need to recurse into the * tree (READ_TREE_RECURSIVE) or skip it (0). */
| 147 | * tree (READ_TREE_RECURSIVE) or skip it (0). |
| 148 | */ |
| 149 | static int try_update_sparse_directory(const struct object_id *oid, |
| 150 | struct strbuf *base, |
| 151 | const char *pathname, |
| 152 | int overlay_mode) |
| 153 | { |
| 154 | struct strbuf dirpath = STRBUF_INIT; |
| 155 | struct cache_entry *old; |
| 156 | int pos, result = READ_TREE_RECURSIVE; |
| 157 | |
| 158 | if (!the_repository->index->sparse_index) |
| 159 | return result; |
| 160 | |
| 161 | strbuf_addbuf(&dirpath, base); |
| 162 | strbuf_addstr(&dirpath, pathname); |
| 163 | strbuf_addch(&dirpath, '/'); |
| 164 | |
| 165 | pos = index_name_pos_sparse(the_repository->index, |
| 166 | dirpath.buf, dirpath.len); |
| 167 | if (pos < 0) |
| 168 | goto cleanup; |
| 169 | |
| 170 | old = the_repository->index->cache[pos]; |
| 171 | if (!S_ISSPARSEDIR(old->ce_mode)) |
| 172 | goto cleanup; |
| 173 | |
| 174 | if (oideq(oid, &old->oid)) { |
| 175 | /* Tree content already matches; no need to descend. */ |
| 176 | result = 0; |
| 177 | } else if (!overlay_mode) { |
| 178 | /* |
| 179 | * In non-overlay mode (e.g., restore --staged), replace the |
| 180 | * sparse directory OID directly since files not present in |
| 181 | * the source tree should be removed anyway. |
| 182 | */ |
| 183 | oidcpy(&old->oid, oid); |
| 184 | old->ce_flags |= CE_UPDATE; |
| 185 | result = 0; |
| 186 | } |
| 187 | |
| 188 | cleanup: |
| 189 | strbuf_release(&dirpath); |
| 190 | return result; |
| 191 | } |
| 192 | |
| 193 | static int update_some(const struct object_id *oid, struct strbuf *base, |
| 194 | const char *pathname, unsigned mode, void *context) |
no test coverage detected