Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Comments

feat: add ApplyResult with change statistics#5

Merged
remimimimimi merged 11 commits intoprefix-dev:masterfrom
baszalmstra:claude/patch-apply-return-info-011CUtHAfZk1n8X2w4djgy6q
Nov 7, 2025
Merged

feat: add ApplyResult with change statistics#5
remimimimimi merged 11 commits intoprefix-dev:masterfrom
baszalmstra:claude/patch-apply-return-info-011CUtHAfZk1n8X2w4djgy6q

Conversation

@baszalmstra
Copy link

Implements a feature to return detailed statistics about patch application, including:

  • Number of lines added, deleted, and context lines
  • Number of hunks applied
  • Whether any changes were made (detect already-applied patches)

The apply functions now return ApplyResult<T> containing both the patched content and ApplyStats with the change information. This allows users to determine if a patch actually changed anything or was already applied.

Added comprehensive tests for the new functionality.

AI Disclosure

Written by cloud code web.

Implements a feature to return detailed statistics about patch application,
including:
- Number of lines added, deleted, and context lines
- Number of hunks applied
- Whether any changes were made (detect already-applied patches)

The apply functions now return ApplyResult<T> containing both the patched
content and ApplyStats with the change information. This allows users to
determine if a patch actually changed anything or was already applied.

Added comprehensive tests for the new functionality.
Copy link

@remimimimimi remimimimimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful!

- Convert has_changes from stored field to computed method
- Restructure ApplyResult to be Result-like (ApplyResult<T, E> instead of Result<ApplyResult<T>, E>)
- Replace tuple return with named HunkStats struct for better clarity

These changes improve the API design based on reviewer feedback:
1. has_changes() is now computed on-demand rather than stored
2. ApplyResult now follows Result-like conventions with ApplyResult::Ok and ApplyResult::Err
3. Internal hunk statistics use a named struct instead of a tuple for better readability
Copy link

@remimimimimi remimimimimi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We almost good to go!

@wolfv
Copy link
Member

wolfv commented Nov 7, 2025

Can we actually detect that a patch had already been applied? Should be easy to double apply a patch to test?

@baszalmstra
Copy link
Author

Can we actually detect that a patch had already been applied? Should be easy to double apply a patch to test?

WDYM? My assumption was that if a patch didnt actually apply any changes, then it is superflous.

…on test

- Refactor ApplyResult from custom enum to type alias following nom's IResult pattern
  - Changed from ApplyResult<T, E> enum to type alias: Result<(T, ApplyStats), E>
  - Added default error type parameter: ApplyResult<T, E = ApplyError>
  - Simplified API: users now use standard Result methods (?, unwrap, etc.)
- Add test for detecting already-applied patches
  - Demonstrates that applying a patch twice fails on the second attempt
  - First application succeeds with changes, second fails as expected

This addresses reviewer feedback to use a simpler, more idiomatic approach
similar to nom's IResult, and validates that the library can detect when
patches have already been applied.
@remimimimimi remimimimimi merged commit 63377fa into prefix-dev:master Nov 7, 2025
3 checks passed
@wolfv
Copy link
Member

wolfv commented Nov 7, 2025

I think patch will say something like "patch already applied". I was wondering if this allows us to recreate that. I believe we are currently erroring on that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants