portsnap: Shorten 'Skipping' output lines

Portsnap uses patches opportunistically to reduce download bandwidth: It
attempts to fetch patches which could be useful, and then makes use of
whichever patches it actually gets.  (This solves the otherwise O(n^2)
issue for the server to build patches between every pair of versions.)

During the process of applying patches, portsnap prints lines of the
form "Skipping XXX-YYY (123 of 4567).\r", where the \r serves to allow
each of these (potentially many) lines to overwrite the previous one
on the console.  Unfortunately, XXX and YYY here are SHA256 hashes,
resulting in these lines wrapping on reasonable-width consoles.

Replace the hashes with abbreviations of the form "0123...cdef"
(cutting 64 characters down to 11) in order to keep lines to a
reasonable length.

The rather ugly shell code here is used to avoid forking additional
processes; it would be much cleaner using sed(1), but in my testing
the sed-based alternative increases CPU time consumption by 50%.

Requested by:	des
This commit is contained in:
Colin Percival 2021-06-29 10:45:46 -07:00
parent 5ca9d41700
commit a9f5512f07

View File

@ -838,6 +838,11 @@ fetch_update() {
I=$(($I + 1))
F="${X}-${Y}"
if [ ! -f "${F}" ]; then
XS=${X%[0-9a-f][0-9a-f][0-9a-f][0-9a-f]}
XE=${X#[0-9a-f][0-9a-f][0-9a-f][0-9a-f]}
YS=${Y%[0-9a-f][0-9a-f][0-9a-f][0-9a-f]}
YE=${Y#[0-9a-f][0-9a-f][0-9a-f][0-9a-f]}
F="${X%${XE}}...${X#${XS}}-${Y%${YE}}...${Y#${YS}}"
printf " Skipping ${F} (${I} of ${PATCHCNT}).\r"
continue;
fi