Back when we switched pack-objects to visiting packs in most-recently-used order last August, we realized that this could reuse cross-pack deltas, and that the result could have longer delta chains than any single pack contains. I produced a patch back then[1], but we decided not to follow through with it. Two things happened to make me revive that patch: 1. I hit a case in the wild with a really long delta chain that caused pack-objects' write_one() to run out of stack space. 2. We dropped the --aggressive depth to match the normal one. So there's less concern about mismatches throwing out on-disk deltas from a previous aggressive repack (but see the caveats in the first patch's commit message). So here it is, plus another patch that converts the recursion to iteration (the stack space needed by the function is small enough that just the first patch was enough to fix my problem case, but it seemed like tempting fate to leave it recursive). [1/2]: pack-objects: enforce --depth limit in reused deltas [2/2]: pack-objects: convert recursion to iteration in break_delta_chain() builtin/pack-objects.c | 133 ++++++++++++++++++++++++++++++++++++-------- pack-objects.h | 4 ++ t/t5316-pack-delta-depth.sh | 93 +++++++++++++++++++++++++++++++ 3 files changed, 207 insertions(+), 23 deletions(-) create mode 100755 t/t5316-pack-delta-depth.sh -Peff [1] http://public-inbox.org/git/20160811095710.p2bffympjlwmv3gc@xxxxxxxxxxxxxxxxxxxxx/