Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bluekeyes/go-gitdiff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.1
Choose a base ref
...
head repository: bluekeyes/go-gitdiff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 19 commits
  • 43 files changed
  • 2 contributors

Commits on Mar 18, 2022

  1. Configuration menu
    Copy the full SHA
    8764d81 View commit details
    Browse the repository at this point in the history

Commits on Mar 20, 2022

  1. Split apply logic by fragment type (#32)

    Remove the Applier type and replace it with TextApplier and
    BinaryApplier, both of which operate on fragments instead of on full
    files. Move the logic that previously existed in Applier.ApplyFile to
    the top-level Apply function.
    
    Also restructure arguments and methods to make it clear that appliers
    are one-time-use objects. The destination is now set when creating an
    applier and the Reset() method was replaced by Close().
    bluekeyes authored Mar 20, 2022
    Configuration menu
    Copy the full SHA
    7593039 View commit details
    Browse the repository at this point in the history

Commits on Oct 1, 2022

  1. Test with Go 1.19, upgrade golangci-lint (#35)

    The previous version of the golangci-lint action would install its own
    version of Go, which eventually conflicted with the old pinned version
    of the linter I was using. Upgrade the action to avoid this, but also
    update Go and the linter while I'm here.
    bluekeyes authored Oct 1, 2022
    Configuration menu
    Copy the full SHA
    071689e View commit details
    Browse the repository at this point in the history
  2. Slightly simplify patch header parsing (#34)

    Use standard string functions instead of removing leading whitespace in
    a custom loop. This also makes the distinction between the two types of
    mail header parsing a bit clearer.
    bluekeyes authored Oct 1, 2022
    Configuration menu
    Copy the full SHA
    dc43dbf View commit details
    Browse the repository at this point in the history
  3. Add option to control patch subject cleaning (#36)

    When processing mail-formatted patches, the default cleanup removed all
    leading content in square brackets, but this pattern is often used to
    identify tickets or other information that should remain in the commit
    title. Git supports disabling this the the `-k` and `-b` flags, which we
    simulate with the new SubjectCleanMode options.
    
    Use WithSubjectCleanMode(SubjectCleanPatchOnly) to only remove bracketed
    strings that contain "PATCH", keeping others that are (probably) part of
    the actual commit message.
    
    Note that because of the mail parsing library, we cannot replicate the
    `-k` flag exactly and always clean leading and trailing whitespace.
    bluekeyes authored Oct 1, 2022
    Configuration menu
    Copy the full SHA
    03daf96 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1575e0c View commit details
    Browse the repository at this point in the history

Commits on Dec 26, 2022

  1. Fix parsing of mode lines with trailing space (#38)

    If a patch is passed through a system that converts line endings to
    '\r\n', mode lines end up with trailing whitespace that confuses
    strconv.ParseInt. In Git, this is avoided by using strtoul() for parsing,
    which stops at the first non-digit character.
    
    Changing line endings in patch content itself will cause other problems
    so it is best to avoid this transform, but if it does happen, it
    shouldn't cause a parse error.
    bluekeyes authored Dec 26, 2022
    Configuration menu
    Copy the full SHA
    981bc4b View commit details
    Browse the repository at this point in the history

Commits on Feb 25, 2024

  1. Configuration menu
    Copy the full SHA
    13e8639 View commit details
    Browse the repository at this point in the history

Commits on Mar 7, 2024

  1. Accept empty emails in ParsePatchIdentity (#42)

    Git is actually more lenient here than I thought. As long as the
    identity contains the "<>" delimiters, Git will allow an empty email, so
    we should accept the same thing. I also discovered that an identity with
    only an email set will use the email as the name, so I've implemented
    that behavior as well.
    bluekeyes authored Mar 7, 2024
    Configuration menu
    Copy the full SHA
    3f2ea5c View commit details
    Browse the repository at this point in the history

Commits on May 6, 2024

  1. Follow git logic when parsing patch identities (#44)

    When GitHub creates patches for Dependabot PRs, it generates a "From:"
    line that is not valid according to RFC 5322: the address spec contains
    unquoted special characters (the "[bot]" in "dependabot[bot]"). While
    the 'net/mail' parser makes some exceptions to the spec, this is not one
    of them, so parsing these patch headers fails.
    
    Git's 'mailinfo' command avoids this by only implementing the unquoting
    part of RFC 5322 and then applying a heuristic to separate the string in
    to name and email values that seem reasonable.
    
    This commit does two things:
    
    1. Reimplements ParsePatchIdentity to follow Git's logic, so that it can
       accept a wider range of inputs, including quoted strings.  Strings
       accepted by the previous implementation parse in the same way with
       one exception: inputs that contain whitespace inside the angle
       brackets for an email address now use the email address as the name
       and drop any separate name component.
    
    2. When parsing mail-formatted patches, use ParsePatchIdentity to parse
       the "From:" line instead of the 'net/mail' function.
    bluekeyes authored May 6, 2024
    Configuration menu
    Copy the full SHA
    a00d2cc View commit details
    Browse the repository at this point in the history

Commits on Jul 15, 2024

  1. Return preamble when a patch has no files (#46)

    While empty patches with only a header were parsable, the parser
    discarded the preamble content. This meant callers had to handle this
    case specially. Now, if we reach the end of the input without finding a
    file, Parse() returns the full content of the patch as the preamble.
    bluekeyes authored Jul 15, 2024
    Configuration menu
    Copy the full SHA
    0a4e55f View commit details
    Browse the repository at this point in the history

Commits on Aug 11, 2024

  1. Update Go and golangci-lint versions (#49)

    The minimum Go version for the package is now Go 1.21. This is because a
    future change will use the 'slices' package in test code. Note that non-test
    code in the package should still be compatible with older versions of Go.
    
    As part of this, also update the golangci-lint version to one that works
    with Go 1.21, which required replacing some deprecated linters.
    bluekeyes authored Aug 11, 2024
    Configuration menu
    Copy the full SHA
    9e0997e View commit details
    Browse the repository at this point in the history
  2. Add String() methods to parsed types (#48)

    This enables clients to move back and forth between parsed objects and
    text patches. The generated patches are semantically equal to the parsed
    object and should re-parse to the same object, but may not be
    byte-for-byte identical to the original input.
    
    In my testing, formatted text patches are usually identical to the
    input, but there may be cases where this is not true. Binary patches
    always differ. This is because Go's 'compress/flate' package ends
    streams with an empty block instead of adding the end-of-stream flag to
    the last non-empty block, like Git's C implementation. Since the streams
    will always be different for this reason, I chose to also enable default
    compression (the test patches I generated with Git used no compression.)
    
    The main tests for this feature involve parsing, formatting, and then
    re-parsing a patch to make sure we get equal objects.
    
    Formatting is handled by a new internal formatter type, which allows
    writing all data to the same stream. This isn't exposed publicly right
    now, but will be useful if there's a need for more flexible formatting
    functions in the future, like formatting to a user-provided io.Writer.
    bluekeyes authored Aug 11, 2024
    Configuration menu
    Copy the full SHA
    8584cd5 View commit details
    Browse the repository at this point in the history

Commits on Jan 8, 2025

  1. Parse binary headers with file paths (#55)

    Some patches may include one or more file paths as part of the binary
    header when there is no binary data. Git accounts for this by only
    checking the prefix and suffix of the line, but I missed that logic when
    implementing this originally.
    bluekeyes authored Jan 8, 2025
    Configuration menu
    Copy the full SHA
    14da3d3 View commit details
    Browse the repository at this point in the history
  2. Fix binary headers in formatted patches (#56)

    Include file names in the header (now that we can actually parse them)
    and fix a bad find-and-replace that changed "differ" to "fmer". Add a
    new test to verify that binary files without data format correctly.
    bluekeyes authored Jan 8, 2025
    Configuration menu
    Copy the full SHA
    fffa3cc View commit details
    Browse the repository at this point in the history

Commits on Mar 5, 2025

  1. Add a test for removing the last newline in a file (#59)

    This worked, but completes the test coverage in combination with the
    test that adds a final newline and one that leaves the missing newline
    in place.
    bluekeyes authored Mar 5, 2025
    Configuration menu
    Copy the full SHA
    823d31d View commit details
    Browse the repository at this point in the history

Commits on Mar 29, 2025

  1. Clarify that we only support GNU diff

    In issue #57, it was reported that the library could not apply some
    patches generated by BSD `diff` because of the way that variant reports
    changes in files without trailing newlines. Since the library behavior
    matches Git, I don't consider this a bug, but update the README to
    mention that the support for standard unified diffs is only for the GNU
    variant of the `diff` tool.
    bluekeyes committed Mar 29, 2025
    Configuration menu
    Copy the full SHA
    0896f01 View commit details
    Browse the repository at this point in the history

Commits on Apr 1, 2025

  1. Configuration menu
    Copy the full SHA
    7413262 View commit details
    Browse the repository at this point in the history

Commits on Sep 4, 2025

  1. Report short sources as conflicts during apply (#63)

    Previously, this returned an io.ErrUnexpectedEOF. This is not wrong, in
    that we did unexpectedly hit the end of the input file, but it is vague
    and implies a possible library bug rather than a problem with the patch
    or the input. This condition is really a conflict, as the changes
    described by the patch are not compatible with the state of the input.
    bluekeyes authored Sep 4, 2025
    Configuration menu
    Copy the full SHA
    17bd72f View commit details
    Browse the repository at this point in the history
Loading