Skip to content

Add support for git diff --indent-heuristic option #1652

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

Merged
merged 5 commits into from
Dec 25, 2018

Conversation

jcansdale
Copy link
Contributor

@jcansdale jcansdale commented Dec 19, 2018

What this PR does

  • Add IndentHeuristic option to CompareOptions (it's a bool)
  • Add test to check that --indent-heuristic makes a difference
  • Add test for when --indent-heuristic won't make a difference

When this flag is set, enable the GIT_DIFF_INDENT_HEURISTIC option.
When compared files don't contain spaces, the --indent-heuristic option
won't make a difference.
ContentChanges changes0 = repo.Diff.Compare(oldBlob, newBlob, noIndentHeuristicOption);
ContentChanges changes1 = repo.Diff.Compare(oldBlob, newBlob, indentHeuristicOption);

Assert.NotEqual(changes0.Patch, changes1.Patch);
Copy link
Member

Choose a reason for hiding this comment

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

Can we validate that changes0 is a superset of changes1?

Copy link
Member

Choose a reason for hiding this comment

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

Or validate the results of the patch strings?

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 was wondering about what exactly to validate in this case. The main thing I wanted to validate was that the flag was making its way to indent heuristic code. By checking when we expect the flag to make a difference and when we don't expect it to make a difference, I hope that is pretty much covered.

I've added a sanity check in 2f583cb to make sure that the same lines are being added or removed. I'm trusting the algorithm to add or remove them in the correct order. 🙂

The --indent-heuristic option should create patches that add or remove
the same lines, but potentially in a different order.
@ethomson ethomson merged commit ac599f4 into libgit2:master Dec 25, 2018
@jcansdale jcansdale deleted the fixes/git-diff-indent-heuristic branch January 7, 2019 09:44
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.

3 participants