| 336 | struct lazy_entry *lazy_entries); |
| 337 | |
| 338 | static int handle_range_dir( |
| 339 | struct index_state *istate, |
| 340 | int k_start, |
| 341 | int k_end, |
| 342 | struct dir_entry *parent, |
| 343 | struct strbuf *prefix, |
| 344 | struct lazy_entry *lazy_entries, |
| 345 | struct dir_entry **dir_new_out) |
| 346 | { |
| 347 | int rc, k; |
| 348 | int input_prefix_len = prefix->len; |
| 349 | struct dir_entry *dir_new; |
| 350 | |
| 351 | dir_new = hash_dir_entry_with_parent_and_prefix(istate, parent, prefix); |
| 352 | |
| 353 | strbuf_addch(prefix, '/'); |
| 354 | |
| 355 | /* |
| 356 | * Scan forward in the index array for index entries having the same |
| 357 | * path prefix (that are also in this directory). |
| 358 | */ |
| 359 | if (k_start + 1 >= k_end) |
| 360 | k = k_end; |
| 361 | else if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0) |
| 362 | k = k_start + 1; |
| 363 | else if (strncmp(istate->cache[k_end - 1]->name, prefix->buf, prefix->len) == 0) |
| 364 | k = k_end; |
| 365 | else { |
| 366 | int begin = k_start; |
| 367 | int end = k_end; |
| 368 | assert(begin >= 0); |
| 369 | while (begin < end) { |
| 370 | int mid = begin + ((end - begin) >> 1); |
| 371 | int cmp = strncmp(istate->cache[mid]->name, prefix->buf, prefix->len); |
| 372 | if (cmp == 0) /* mid has same prefix; look in second part */ |
| 373 | begin = mid + 1; |
| 374 | else if (cmp > 0) /* mid is past group; look in first part */ |
| 375 | end = mid; |
| 376 | else |
| 377 | die("cache entry out of order"); |
| 378 | } |
| 379 | k = begin; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Recurse and process what we can of this subset [k_start, k). |
| 384 | */ |
| 385 | rc = handle_range_1(istate, k_start, k, dir_new, prefix, lazy_entries); |
| 386 | |
| 387 | strbuf_setlen(prefix, input_prefix_len); |
| 388 | |
| 389 | *dir_new_out = dir_new; |
| 390 | return rc; |
| 391 | } |
| 392 | |
| 393 | static int handle_range_1( |
| 394 | struct index_state *istate, |
no test coverage detected