Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly detect combined diffs #942

Merged
merged 1 commit into from
Jul 26, 2019
Merged

Properly detect combined diffs #942

merged 1 commit into from
Jul 26, 2019

Conversation

moben
Copy link
Contributor

@moben moben commented Jul 4, 2019

Combined diff chunks start with '@@@', use that to detect them instead of
the "Merge:" field that is present for all merges, regardless of diff type.

Technically, this still doesn't handle merges with more than 2 parents
but that's not a regression

From git-log(1):

 4. Chunk header format is modified to prevent people from
    accidentally feeding it to patch -p1. Combined diff format was
    created for review of merge commit changes, and was not meant
    for apply. The change is similar to the change in the extended
    index header:

        @@@ <from-file-range> <from-file-range> <to-file-range> @@@

    There are (number of parents + 1) @ characters in the chunk
    header for combined diff format.

Closes #941

@moben moben force-pushed the master branch 2 times, most recently from 8af16d6 to 6fd6191 Compare July 16, 2019 15:02
src/diff.c Outdated
@@ -296,6 +292,8 @@ diff_common_read(struct view *view, const char *data, struct diff_state *state)
return true;

} else if (type == LINE_PP_MERGE) {
/* we will check again when highlighting diff chunks but we
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for spotting and fixing this issue. What about removing this part as you initially proposed and changing the test if (state->combined_diff && !state->after_diff && data[0] == ' ' && data[1] != ' ') to if (!state->after_diff && data[0] == ' ' && data[1] != ' ') as the check on after_diff should be sufficient here ? Maybe it would be wise to add a comment stating that this test is necessary because merge commits lack the LINE_DIFF_START.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, that's better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review!

Combined diff chunks start with '@@@', use that to detect them instead of
the "Merge:" field that is present for all merges, regardless of diff type.

Technically, this still doesn't handle merges with more than 2 parents
but that's not a regression

From git-log(1):

     4. Chunk header format is modified to prevent people from
        accidentally feeding it to patch -p1. Combined diff format was
        created for review of merge commit changes, and was not meant
        for apply. The change is similar to the change in the extended
        index header:

            @@@ <from-file-range> <from-file-range> <to-file-range> @@@

        There are (number of parents + 1) @ characters in the chunk
        header for combined diff format.

Closes jonas#941
@koutcher koutcher merged commit e5a9b5e into jonas:master Jul 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Viewing merges with --first-parent gives "Allocation Failure"
2 participants