-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix: Decouple GitHandler creation via registry and extend semantic conflict detection #13666
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
Fix: Decouple GitHandler creation via registry and extend semantic conflict detection #13666
Conversation
Decouple GitHandler creation via GitHandlerRegistry
da6b7c8 to
267a42f
Compare
Update SemanticConflictDetector
Apply OpenRewrite auto-fixes for code style compliance
267a42f to
687698c
Compare
Case comments are consistent with actual logic.
| boolean localDeleted = local == null; | ||
| boolean remoteDeleted = remote == null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| boolean localDeleted = local == null; | |
| boolean remoteDeleted = remote == null; | |
| boolean localDeleted = (local == null); | |
| boolean remoteDeleted = (remote == null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like each time it is changed by OpenRewrite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can skip then
| boolean localChanged = !localDeleted && !Objects.equals(base.getFieldMap(), local.getFieldMap()); | ||
| boolean remoteChanged = !remoteDeleted && !Objects.equals(base.getFieldMap(), remote.getFieldMap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since we have already checked for base != null and also since short circuiting guarantees that the respective second conditions are evaluated only if the first is not true (i.e, not null), we can use the plain equals method in these cases instead of Objects.equals?
| boolean localChanged = !localDeleted && !Objects.equals(base.getFieldMap(), local.getFieldMap()); | |
| boolean remoteChanged = !remoteDeleted && !Objects.equals(base.getFieldMap(), remote.getFieldMap()); | |
| boolean localChanged = !localDeleted && !base.getFieldMap().equals(local.getFieldMap()); | |
| boolean remoteChanged = !remoteDeleted && !base.getFieldMap().equals(remote.getFieldMap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, no risk of NPE here. Changed to use equals() as suggested
| boolean localChanged = !Objects.equals(base.getFieldMap(), local.getFieldMap()); | ||
| boolean remoteChanged = !Objects.equals(base.getFieldMap(), remote.getFieldMap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as https://github.com/JabRef/jabref/pull/13666/files#r2257660938 here
| boolean localChanged = !Objects.equals(base.getType(), local.getType()); | ||
| boolean remoteChanged = !Objects.equals(base.getType(), remote.getType()); | ||
|
|
||
| return localChanged && remoteChanged && !Objects.equals(local.getType(), remote.getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
| public GitHandler get(Path repoPath) { | ||
| if (repoPath == null) { | ||
| throw new IllegalArgumentException("Path must not be null"); | ||
| } | ||
|
|
||
| Path normalized = repoPath.toAbsolutePath().normalize(); | ||
| return handlerCache.computeIfAbsent(normalized, GitHandler::new); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is debatable, but I am not a huge fan of using logical branching to throw exceptions. If there is a logical branch, it should not deal with an exceptional/unexpected case. Catch blocks are there for that.
How about
| public GitHandler get(Path repoPath) { | |
| if (repoPath == null) { | |
| throw new IllegalArgumentException("Path must not be null"); | |
| } | |
| Path normalized = repoPath.toAbsolutePath().normalize(); | |
| return handlerCache.computeIfAbsent(normalized, GitHandler::new); | |
| } | |
| public GitHandler get(Path repoPath) { | |
| Path normalized = Objects.requireNonNull(repoPath, "Path must not be null") | |
| .toAbsolutePath().normalize(); | |
| return handlerCache.computeIfAbsent(normalized, GitHandler::new); | |
| } |
Note that if you take this suggestion, you'll need the Objects import here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, the path is already checked before calling this method, so this is really just a defensive guard (and to keep trag-bot happy). Switched to Objects.requireNonNull(...). Thanks!
| public Optional<GitHandler> fromAnyPath(Path anyPathInsideRepo) { | ||
| if (anyPathInsideRepo == null) { | ||
| throw new IllegalArgumentException("Path must not be null"); | ||
| } | ||
|
|
||
| return GitHandler.findRepositoryRoot(anyPathInsideRepo) | ||
| .map(this::get); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment as https://github.com/JabRef/jabref/pull/13666/files#r2257720507 here
public Optional<GitHandler> fromAnyPath(Path anyPathInsideRepo) {
return GitHandler.findRepositoryRoot(Objects.requireNonNull(anyPathInsideRepo, "Path must not be null"))
.map(this::get);
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
|
@trag-bot didn't find any issues in the code! ✅✨ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Closes #12350
This PR includes two major improvements:
Decoupled
GitHandlercreation using a newGitHandlerRegistryGitHandlerinstance per Git repository root.Improved semantic conflict detection logic
SemanticConflictDetectorto better handle edge cases in entry-level conflictsSteps to test
All changes are covered by new or updated unit tests:
Mandatory checks
CHANGELOG.mddescribed in a way that is understandable for the average user (if change is visible to the user)