Skip to content

portbump: improve checksum matching and handling#378

Merged
herbygillot merged 1 commit intomacports:masterfrom
herbygillot:trac-73593-2
Mar 21, 2026
Merged

portbump: improve checksum matching and handling#378
herbygillot merged 1 commit intomacports:masterfrom
herbygillot:trac-73593-2

Conversation

@herbygillot
Copy link
Member

@herbygillot herbygillot commented Mar 12, 2026

Drop sed(1) entirely from portbump. Instead, read the Portfile into a
line list and use three new procs for targeted modifications:

  • replace_checksums: match on unique hash values rather than regex
    patterns, so only the correct lines are modified even with multiple
    subports, conditional branches, or variant-scoped checksums.

  • find_revision_line: two-phase strategy — first check for an inline
    revision on the subport declaration line (e.g. llvm pattern), then
    fall back to the nearest standalone revision line, excluding lines
    inside subport { } blocks when bumping the parent port.

  • reset_revision: simple regsub to set revision to 0, preserving
    indentation and surrounding text.

Fixes a bug where both_checksums was reset on each distfile iteration,
causing only the last distfile's checksums to be updated in Portfiles
with multiple distfiles (e.g. git with git-manpages and git-htmldocs).

Also fixes a bug where patch mode applied file attributes to the
Portfile instead of the patch file.

Removes dead code left over from the sed-based implementation.

Adds comprehensive test suite covering real-world Portfile patterns
(git, go, llvm-16, gradle), including tests for size field replacement,
subport blocks with nested braces, multiple distfiles, and the
no-revision-line code path.

Closes: https://trac.macports.org/ticket/65601
Closes: https://trac.macports.org/ticket/73593

@herbygillot herbygillot requested a review from jmroot March 12, 2026 08:02
@herbygillot herbygillot force-pushed the trac-73593-2 branch 2 times, most recently from b4f56e3 to b582f70 Compare March 12, 2026 08:21
@herbygillot herbygillot requested a review from ryandesign March 13, 2026 03:05
@fhgwright
Copy link

On a somewhat related note, the traditional approach (pasting some output from port -v checksum into the Portfile) would be more convenient if the suggested checksum lines duplicated the indentations of the existing lines. That's probably less important as port bump improves, but it's also probably fairly easy given what you've already done for port bump.

@herbygillot
Copy link
Member Author

On a somewhat related note, the traditional approach (pasting some output from port -v checksum into the Portfile) would be more convenient if the suggested checksum lines duplicated the indentations of the existing lines. That's probably less important as port bump improves, but it's also probably fairly easy given what you've already done for port bump.

Here's a PR that will do the right thing in regards to formatting for port checksum: #398

…andling

Drop sed(1) entirely from portbump. Instead, read the Portfile into a
line list and use three new procs for targeted modifications:

- replace_checksums: match hash values as whole words using \y
  word-boundary anchors, so a size value like 123 cannot accidentally
  clobber a larger value such as 12345; targets only the correct lines
  even with multiple subports, conditional branches, or variant-scoped
  checksums.

- find_revision_line: two-phase strategy — first check for an inline
  revision on the subport declaration line (e.g. llvm pattern), then
  fall back to the nearest standalone revision line, excluding lines
  inside subport { } blocks when bumping the parent port.

- reset_revision: simple regsub to set revision to 0, preserving
  indentation and surrounding text.

Fixes a bug where both_checksums was reset on each distfile iteration,
causing only the last distfile's checksums to be updated in Portfiles
with multiple distfiles (e.g. git with git-manpages and git-htmldocs).

Fixes a bug where already-correct checksums were shown in the
"We will bump these:" output.

Also fixes a bug where patch mode applied file attributes to the
Portfile instead of the patch file.

Removes dead code left over from the sed-based implementation.

Adds comprehensive test suite covering real-world Portfile patterns
(git, go, llvm-16, gradle), including tests for whole-word size
matching, subport blocks with nested braces, multiple distfiles,
partial mismatch, and the no-revision-line code path.

Closes: https://trac.macports.org/ticket/65601
Closes: https://trac.macports.org/ticket/73593

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@herbygillot herbygillot merged commit 0cd72bf into macports:master Mar 21, 2026
5 checks passed
@jmroot
Copy link
Member

jmroot commented Mar 21, 2026

You're not always going to get a review as quickly as you would like. MacPorts is not anybody's day job and there has been a lot going on recently. I'm not going to do a major release without going through the pending PRs.

@herbygillot
Copy link
Member Author

You're not always going to get a review as quickly as you would like. MacPorts is not anybody's day job and there has been a lot going on recently. I'm not going to do a major release without going through the pending PRs.

Yes, I certainly understand that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants