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

Issue #77: git: add line changes detection #82

Merged
merged 1 commit into from
Aug 17, 2017

Conversation

Luolc
Copy link
Contributor

@Luolc Luolc commented Aug 16, 2017

#77

In method parse, we have to use for-loop instead of map, for convertDiffEntryToGitChange now throws IOException.

Since IntStream.range is banned for the cobertura bug, I use apache.common's IntRange instead.

I add a comment to ignore ClassDataAbstractionCoupling.

.setOldTree(pair.commonAncestorTreeParser)
.setNewTree(pair.prTreeParser)
.call()
.stream()
.filter(entry -> entry.getChangeType() != DiffEntry.ChangeType.DELETE)
.map(DiffParser::convertDiffEntryToGitChange)
Copy link
Member

Choose a reason for hiding this comment

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

this can't be made into a lambda?

diff -> convertDiffEntryToGitChange(diff, formatter)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I mentioned this at the post:

we have to use for-loop instead of map, for convertDiffEntryToGitChange now throws IOException

There can't be checked exception in lambda

Copy link
Member

Choose a reason for hiding this comment

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

I didn't know this. We can ignore this for now.

DiffEntry diffEntry, DiffFormatter formatter) throws IOException {
final List<Integer> lines = formatter.toFileHeader(diffEntry).toEditList().stream()
.flatMapToInt(edit -> Arrays.stream(
new IntRange(edit.getBeginB(), edit.getEndB() - 1).toArray()))
Copy link
Member

Choose a reason for hiding this comment

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

So this will convert 1,4 to 1,2,3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

assertEquals("There should be 1 change detected", 1, changes.size());
final GitChange expected = ImmutableGitChange.builder()
.path("HelloWorld")
.addLines(1, 2)
Copy link
Member

@rnveach rnveach Aug 16, 2017

Choose a reason for hiding this comment

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

So these are the new/changed lines in the new file?
So we lost out on information like what lines were removed from old file? So complete removal of a line shows no line changes?
Won't we need to know lines being completely removed?

Please make 3 new tests to confirm this behavior: adding new line, and removing line, changing existing line.

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 split this UT to three, including adding line, removing line and changing line.

@rnveach
Copy link
Member

rnveach commented Aug 16, 2017

Since IntStream.range is banned for the cobertura bug, I use apache.common's IntRange instead.

I added banned classes to import control. Please rebase.

@Luolc
Copy link
Contributor Author

Luolc commented Aug 16, 2017

I added banned classes to import control. Please rebase.

Rebased.

final List<GitChange> changes = DiffParser.parse(
repository.getDirectory().getParent(), "foo");
assertEquals("There should be 1 change detected", 1, changes.size());
final GitChange expected = ImmutableGitChange.builder()
Copy link
Member

@rnveach rnveach Aug 16, 2017

Choose a reason for hiding this comment

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

As new test shows, removed lines are completely invisible from view.
This can stay for now, but I think it has to change as it will cause issues for some types of regression.

How will we know what method/code/comment was changed if no lines are displayed?
Issues that will be affected:
#6 - need to know which method
#49 - need to know if has change besides chmod
#69 - need to know if was comment or code

I think we have to work with both sides of the file and not just the latest file.
@Luolc Do you agree? If so, let's create a new issue, unless you want to try and fix it now.

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 split lines to addedLines and deletedLines now. Is that OK?

Copy link
Member

Choose a reason for hiding this comment

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

I assume this should be ok.
Eventually we will probably need some way to examine the before and after file for it's contents and surrounding context.

@@ -32,4 +34,18 @@
* @return the path of the changed file
*/
String path();

/**
* The line numbers of the added codes.
Copy link
Member

@rnveach rnveach Aug 16, 2017

Choose a reason for hiding this comment

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

What is code here? We can't be sure new lines are code, comments, etc...
Should this just be changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

List<Integer> addedLines();

/**
* The line numbers of the deleted codes.
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/**
* The line numbers of the added changes.
* The first line of a file is marked as line zero.
* @return the line numbers of the added codes
Copy link
Member

Choose a reason for hiding this comment

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

You missed other codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

/**
* The line numbers of the deleted changes.
* The first line of a file is marked as line zero.
* @return the line numbers of the deleted codes
Copy link
Member

Choose a reason for hiding this comment

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

same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rnveach rnveach merged commit f92362c into checkstyle:master Aug 17, 2017
@Luolc Luolc deleted the issue77 branch August 18, 2017 04:09
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