aptly-dev / aptly

aptly - Debian repository management tool
https://www.aptly.info/
MIT License
2.54k stars 369 forks source link

Fix reflist diffs failing to compact when one of the inputs ends #1275

Closed neolynx closed 2 months ago

neolynx commented 2 months ago

Replaces #1233

Requirements

All new code should be covered with tests, documentation should be updated. CI should pass.

Description of the Change

The previous reflist logic would early-exit the loop body if one of the lists was empty, but that skips the compacting logic entirely.

Instead of doing the early-exit, we can leave a list's ref as nil when the list end is reached and then flip the comparison result, which will essentially treat it as being greater than all others. This should preserve the general behavior without omitting the compaction.


I suspect this might fix #282 and/or #287, but I haven't tested that.

An alternate approach in the same vein is to create a "sentinel" slice like:

sentinel := []byte{255}

and then use that when we reach the end of a reflist, which avoids the need to flip the comparison result. However, the code later on that checks if the ref is set would then look like:

if pl == nil && rl[0] != sentinel[0]

which felt worse to me while also being a tad wasteful (extra slice allocation every call!). That being said, omitting the comparison flip could certainly be seen as cleaner.

Checklist

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 83.87097% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 74.81%. Comparing base (27013c0) to head (a599bb1).

Files Patch % Lines
deb/publish.go 70.58% 4 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1275 +/- ## ========================================== + Coverage 74.78% 74.81% +0.02% ========================================== Files 144 144 Lines 16246 16248 +2 ========================================== + Hits 12150 12156 +6 + Misses 3154 3152 -2 + Partials 942 940 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.