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

Fixes all deprecated API usage in libs.jgit and update gitignore IO code #7093

Merged
merged 2 commits into from
Feb 28, 2024

Conversation

mbien
Copy link
Member

@mbien mbien commented Feb 21, 2024

first commit:

  • remove deprecated jgit api usage
  • fixed all other compiler warnings too (edit: only in libs.jgit :))

second commit:

  • renovate the git ignore/unignore IO code
  • make sure the file specific line separators are retained during file updates

I tested (stepped through it) some of it manually: list/switch branches, list/add/remove tags

lets see what tests say

@mbien mbien added Code cleanup git [ci] enable versioning job ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Feb 21, 2024
@mbien mbien added this to the NB22 milestone Feb 21, 2024
@mbien
Copy link
Member Author

mbien commented Feb 21, 2024

testLogWithBranchInfoMoreBranches: org.netbeans.libs.git.jgit.commands.LogTest

junit.framework.AssertionFailedError
	at org.netbeans.libs.git.jgit.commands.LogTest.testLogWithBranchInfoMoreBranches(LogTest.java:775)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:79)
	at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:484)
	at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:405)
	at java.base/java.lang.Thread.run(Thread.java:840)

one test fails, the bug is in ListBranchCommand, since it works when i revert the changes. Going to take a look tomorrow.

@mbien mbien marked this pull request as draft February 21, 2024 20:32
@mbien mbien force-pushed the fix-jgit-deprecations branch from 1cf5b77 to 124c4db Compare February 26, 2024 15:52
@mbien mbien marked this pull request as ready for review February 26, 2024 15:52
Comment on lines +766 to +770
// git commit timestamp resolution is one second.
// commits with the same time stamp don't seem to influence log order unless branches
// change between commits. In that case the branch name is also affecting the order.
// (renaming "newbranch" to "aaa" would fix this too but obfuscate the problem)
Thread.sleep(1100);
Copy link
Member Author

@mbien mbien Feb 26, 2024

Choose a reason for hiding this comment

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

this resolves the encountered test failure. (#7093 (comment))

Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

Looks sane to me. I only found a single location where I think the behavior changed.

@mbien mbien force-pushed the fix-jgit-deprecations branch from 124c4db to e02c519 Compare February 26, 2024 20:16
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

Thank you.

@mbien mbien force-pushed the fix-jgit-deprecations branch from e02c519 to 74791e4 Compare February 27, 2024 14:52
@mbien
Copy link
Member Author

mbien commented Feb 27, 2024

refreshed PR, testing this a bit manually and if I don't find anything I will merge once green again

@mbien
Copy link
Member Author

mbien commented Feb 27, 2024

added an extra commit which renovates git ignore/unignore IO code

Comment on lines -108 to +106
StringBuilder sb = new StringBuilder('/');
StringBuilder sb = new StringBuilder();
Copy link
Member Author

Choose a reason for hiding this comment

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

this did set the capacity of the SB. The char was cast to int. The code did still work though since it didn't need that slash.

@matthiasblaesing
Copy link
Contributor

added an extra commit which renovates git ignore/unignore IO code

Would it be possible to detect the line end character of the file and use that on save? I observe, that using the Ignore/Unignore action in NetBeans currently leads to many of my .gitignore files to be completely changed.

@mbien
Copy link
Member Author

mbien commented Feb 27, 2024

@matthiasblaesing I take a look

Comment on lines +162 to +176
@SuppressWarnings("NestedAssignment")
private static String probeLineSeparator(Path file) throws IOException {
if (Files.exists(file)) {
try (BufferedReader br = Files.newBufferedReader(file)) {
int current;
int last = -1;
while ((current = br.read()) != -1) {
if (current == '\n') {
return last == '\r' ? "\r\n" : "\n";
}
last = current;
}
}
}
return rules;
return System.lineSeparator();
Copy link
Member Author

Choose a reason for hiding this comment

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

@matthiasblaesing could you check if this works for you?
It probes before save and uses the probed result for write. System default as fallback.

 - code renovation
 - file specific line separators are now retained between updates
 - added tests
@mbien mbien force-pushed the fix-jgit-deprecations branch from da74685 to 2983c0f Compare February 28, 2024 16:32
@mbien
Copy link
Member Author

mbien commented Feb 28, 2024

added tests + refreshed PR

Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

I was not able to test this at work on Windows, but I tested locally the opposite situation: A .gitignore file with windows line endings on linux. The implementation also looks sane to me.

Thank you!

@mbien mbien changed the title Fixes all deprecated API usage in libs.jgit Fixes all deprecated API usage in libs.jgit and update gitignore IO code Feb 28, 2024
@mbien mbien merged commit bcaa1ab into apache:master Feb 28, 2024
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) Code cleanup git [ci] enable versioning job
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants