From 9c2c5b2391496592ea296a149c15de47c4620012 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 11 Mar 2024 18:05:35 -0500 Subject: [PATCH] Prevented writing useless null tags for unstitched diverged trunks This can happen if we end up pruning all alts in a diverged trunk. Note this is subtly different than finding no diverged trunk, as we still need to switch to the LFSR_D_DIVERGED* state in order to prune alts on the non-empty diverged trunk. We need a special case here, because there's no way to represent an empty trunk without a reachable null tag. But a reachable null tag would violate our rbyd's right-leaning property and break lookupnext. We already had a special case for this situation, which would skip the alt that would stitch the trunks together, but we were still writing out a null tag for the diverged trunk even if it was empty. We don't need this null tag and it turns out not writing the null tag saves a null tag. --- lfs.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lfs.c b/lfs.c index fdfdd6f5..f8422679 100644 --- a/lfs.c +++ b/lfs.c @@ -3277,7 +3277,7 @@ again:; } // TODO is this not a_lower_tag? - d_tag = lfsr_tag_key(p_alts[0]); + d_tag = p_alts[0]; // flush any pending alts err = lfsr_rbyd_p_flush(lfs, rbyd, @@ -3290,13 +3290,15 @@ again:; // why does hiding this behind if d_tag=0 not work? // // terminate diverged branch with an unreachable tag - err = lfsr_rbyd_appendattr_(lfs, rbyd, - (lfsr_rbyd_isshrub(rbyd) ? LFSR_TAG_SHRUB : 0) - | LFSR_TAG_NULL, - 0, - LFSR_DATA_NULL()); - if (err) { - return err; + if (d_tag) { + err = lfsr_rbyd_appendattr_(lfs, rbyd, + (lfsr_rbyd_isshrub(rbyd) ? LFSR_TAG_SHRUB : 0) + | LFSR_TAG_NULL, + 0, + LFSR_DATA_NULL()); + if (err) { + return err; + } } // save the found lower rid/tag