Skip to content

diff_generate: fix unsetting diff flags#4426

Merged
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/diff-flag-set-fix
Nov 30, 2017
Merged

diff_generate: fix unsetting diff flags#4426
ethomson merged 2 commits into
libgit2:masterfrom
pks-t:pks/diff-flag-set-fix

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Nov 30, 2017

The macro DIFF_FLAG_SET can be used to set or unset a flag by
modifying the diff's bitmask. While the case of setting the flag is
handled correctly, the case of unsetting the flag was not. Instead of
inverting the flags, we are inverting the value which is used to decide
whether we want to set or unset the bits.

The value being used here is a simple bool which is false. As that
is being uplifted to int when getting the bitwise-complement, we will
end up retaining all bits inside of the bitmask. As that's only ever
used to set GIT_DIFF_IGNORE_CASE, we were actually always ignoring
case for generated diffs.

Fix that by instead getting the bitwise-complement of FLAG, not VAL.

In commit 9be638e (git_diff_generated: abstract generated diffs,
2016-04-19), the code for generated diffs was moved out of the generic
"diff.c" and instead into its own module. During that conversion, it was
forgotten to remove the macros `DIFF_FLAG_IS_SET`, `DIFF_FLAG_ISNT_SET`
and `DIFF_FLAG_SET`, which are now only used in "diff_generated.c".

Remove those macros now.
The macro `DIFF_FLAG_SET` can be used to set or unset a flag by
modifying the diff's bitmask. While the case of setting the flag is
handled correctly, the case of unsetting the flag was not. Instead of
inverting the flags, we are inverting the value which is used to decide
whether we want to set or unset the bits.

The value being used here is a simple `bool` which is `false`. As that
is being uplifted to `int` when getting the bitwise-complement, we will
end up retaining all bits inside of the bitmask. As that's only ever
used to set `GIT_DIFF_IGNORE_CASE`, we were actually always ignoring
case for generated diffs.

Fix that by instead getting the bitwise-complement of `FLAG`, not `VAL`.
@ethomson
Copy link
Copy Markdown
Member

lol. macros, always helpful.

@ethomson ethomson merged commit 494a2f2 into libgit2:master Nov 30, 2017
@pks-t pks-t added the backport label Jan 11, 2018
@pks-t pks-t mentioned this pull request Jan 12, 2018
@pks-t pks-t deleted the pks/diff-flag-set-fix branch July 11, 2019 19:05
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.

2 participants