* Follow the chain of deltas from this entry onward, throwing away any links * that cause us to hit a cycle (as determined by the DFS state flags in * the entries). * * We also detect too-long reused chains that would violate our --depth * limit. */
| 2487 | * limit. |
| 2488 | */ |
| 2489 | static void break_delta_chains(struct object_entry *entry) |
| 2490 | { |
| 2491 | /* |
| 2492 | * The actual depth of each object we will write is stored as an int, |
| 2493 | * as it cannot exceed our int "depth" limit. But before we break |
| 2494 | * changes based no that limit, we may potentially go as deep as the |
| 2495 | * number of objects, which is elsewhere bounded to a uint32_t. |
| 2496 | */ |
| 2497 | uint32_t total_depth; |
| 2498 | struct object_entry *cur, *next; |
| 2499 | |
| 2500 | for (cur = entry, total_depth = 0; |
| 2501 | cur; |
| 2502 | cur = DELTA(cur), total_depth++) { |
| 2503 | if (cur->dfs_state == DFS_DONE) { |
| 2504 | /* |
| 2505 | * We've already seen this object and know it isn't |
| 2506 | * part of a cycle. We do need to append its depth |
| 2507 | * to our count. |
| 2508 | */ |
| 2509 | total_depth += cur->depth; |
| 2510 | break; |
| 2511 | } |
| 2512 | |
| 2513 | /* |
| 2514 | * We break cycles before looping, so an ACTIVE state (or any |
| 2515 | * other cruft which made its way into the state variable) |
| 2516 | * is a bug. |
| 2517 | */ |
| 2518 | if (cur->dfs_state != DFS_NONE) |
| 2519 | BUG("confusing delta dfs state in first pass: %d", |
| 2520 | cur->dfs_state); |
| 2521 | |
| 2522 | /* |
| 2523 | * Now we know this is the first time we've seen the object. If |
| 2524 | * it's not a delta, we're done traversing, but we'll mark it |
| 2525 | * done to save time on future traversals. |
| 2526 | */ |
| 2527 | if (!DELTA(cur)) { |
| 2528 | cur->dfs_state = DFS_DONE; |
| 2529 | break; |
| 2530 | } |
| 2531 | |
| 2532 | /* |
| 2533 | * Mark ourselves as active and see if the next step causes |
| 2534 | * us to cycle to another active object. It's important to do |
| 2535 | * this _before_ we loop, because it impacts where we make the |
| 2536 | * cut, and thus how our total_depth counter works. |
| 2537 | * E.g., We may see a partial loop like: |
| 2538 | * |
| 2539 | * A -> B -> C -> D -> B |
| 2540 | * |
| 2541 | * Cutting B->C breaks the cycle. But now the depth of A is |
| 2542 | * only 1, and our total_depth counter is at 3. The size of the |
| 2543 | * error is always one less than the size of the cycle we |
| 2544 | * broke. Commits C and D were "lost" from A's chain. |
| 2545 | * |
| 2546 | * If we instead cut D->B, then the depth of A is correct at 3. |
no test coverage detected