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

Git Integration and UI Improvements #12252

Open
wants to merge 93 commits into
base: main
Choose a base branch
from
Open

Conversation

khola22
Copy link

@khola22 khola22 commented Dec 2, 2024

This PR introduces several key updates and improvements aimed at enhancing the backup management, change detection, and UI functionalities.

Backup Management with Git Integration:
A new BackupManagerGit class has been implemented to handle backups using Git. This allows .bib files to be automatically copied to a dedicated jabref/backups directory every 19 seconds, ensuring that a comprehensive commit history is maintained via Git. This approach provides a centralized and version-controlled backup mechanism, independent of the file location.

Change Detection Logic:
Change detection is now triggered when .bib files are overwritten during explicit user actions such as Save, Save All, or the save prompts when exiting the application. While listeners continue to track edits, their strict conditions occasionally limit their ability to dynamically detect changes. As a result, we face two challenges:
Lack of autosave functionality without user interaction.
Potential failure to record unsaved changes if the application closes unexpectedly.

UI Enhancements:
The UI has been updated to provide functionality for saving, committing, and discarding changes, along with accurate commit details retrieval. While most features are working as expected, challenges remain with the checkout functionality, especially when reverting commits using JGit. We welcome feedback on this part of the implementation.
Date of backup refers to the date of the commit.

Screenshot 2024-12-05 at 23 04 21

WhatsApp Image 2024-12-01 at 13 37 08

Screenshot 2024-12-05 at 23 04 39

Code Refactoring and Adaptation:
We’ve refactored various components to integrate with BackupManagerGit, replacing the older BackupManager logic. Existing classes like CoarseChangeFilter have been retained without modification, as our focus was on implementing the new Git-based backup mechanism.

PS 1: We have retained the BackupManager class for reference, allowing us to review its contents should further clarification of the backup logic be necessary. However, we have ensured that this class is no longer used outside of the specific tests previously dedicated to it, and we have confirmed that BackupManagerGit is the primary class in operation. Despite these precautions, we have encountered an issue with the legacy backup tracking method. Specifically, we have observed occasional, unexpected creation of .bak files within the backup directory. This anomaly has occurred only once during testing. While we suspect the issue may be linked to the UI components of the code, we have yet to pinpoint the precise cause.

PS 2: A potential issue arose concerning the handling of two .bib files with identical names. Copying such files into the repository would result in one file overwriting the other, which is problematic. We are currently investigating a solution to this before finalizing the PR for review.

PS 3 : We didn't implement squashing older backup commits.

Update 1: The issue identified in PS 2 has been addressed by implementing UUID-generated unique file names. However, when a .bib file is relocated, a new UUID is generated, which results in a new file being recorded in the Git repository. To resolve this, we propose the following solutions: 1/ Move the .uuid file along with the .bib file when the move is performed through JabRef. 2/ Utilize a file system watcher to track and handle file movements performed outside of JabRef.

Updates 2 : Restore button works.

We have not yet pursued further investigation into these solutions.

The title of the isuue : Enhanced backup restore dialog #2961
The link of the issue : #2961 (comment)

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

nawalchahboune and others added 30 commits October 23, 2024 20:18
Removed BackupManagerJGit to do UI changes
…into branch-1"

This reverts commit df21a4d, reversing
changes made to 62a8beb.
@khola22
Copy link
Author

khola22 commented Dec 5, 2024

hello @subhramit , we were trying to resolve the conflicts with submodules as said in the link, the first approache didn't work, but for the second one, we have an issue :

  • (base) khaoula@Khaoulas-MacBook-Air JabRef % cd src/main/resources/csl-locales
  • (base) khaoula@Khaoulas-MacBook-Air csl-locales % git checkout 96d704d
    error: pathspec '96d704d' did not match any file(s) known to git
  • (base) khaoula@Khaoulas-MacBook-Air csl-locales % git checkout 96d704d
    error: pathspec '96d704d' did not match any file(s) known to git
  • (base) khaoula@Khaoulas-MacBook-Air csl-locales % git status
    HEAD detached at 8bc2af1
    nothing to commit, working tree clean

@khola22 khola22 marked this pull request as ready for review December 5, 2024 00:44
@khola22
Copy link
Author

khola22 commented Dec 5, 2024

Update : we fixed the conflicts relative to submodules.

github-actions[bot]

This comment was marked as outdated.

Copy link
Member

@subhramit subhramit left a comment

Choose a reason for hiding this comment

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

Initial suggestions.

@calixtus I'd want you to take a look at the usage of 1. preferences 2. mockito in this PR once. I remember using RETURN_DEEP_STUBS for some preference in the past, the use case seems similar here. However, I think we can reduce the usage of mockito for other cases by using concrete instantiations (entries, database context, database, entrytypesmanager in particular).

CHANGELOG.md Outdated
@@ -11,6 +11,11 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- Implemented BackupManagerGit to handle automatic backups of .bib files using Git, ensuring centralized, version-controlled backup management. [#2961](https://github.com/JabRef/jabref/issues/2961)
Copy link
Member

@subhramit subhramit Dec 5, 2024

Choose a reason for hiding this comment

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

Changelog entries are primarily for users, so they are not supposed to be aware of internal implementations or class names ("BackupManagerGit"). Just mention git-based version control. Ideally make entries short and crisp as well. For example:

Suggested change
- Implemented BackupManagerGit to handle automatic backups of .bib files using Git, ensuring centralized, version-controlled backup management. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Implemented version-control based backup management of .bib files using Git. [#2961](https://github.com/JabRef/jabref/issues/2961)

CHANGELOG.md Outdated
@@ -11,6 +11,11 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Added

- Implemented BackupManagerGit to handle automatic backups of .bib files using Git, ensuring centralized, version-controlled backup management. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Added automatic copying of .bib files to a jabref/backups directory every 19 seconds with comprehensive commit history. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Added support for unique file naming using UUIDs to prevent overwriting files with identical names in the backup directory. [#2961](https://github.com/JabRef/jabref/issues/2961)
Copy link
Member

@subhramit subhramit Dec 5, 2024

Choose a reason for hiding this comment

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

Part of internal implementation of the introduced feature and not a "change" from existing release. Remove this.

Copy link
Member

@subhramit subhramit Dec 5, 2024

Choose a reason for hiding this comment

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

@khola22 Please do not mark review comments as resolved (except if it is trivially visible that it has been resolved). In this case, this was asked to be removed, and it is not (yet).
Once you push fresh commits on the code window, this will automatically be marked "Outdated". Then, one of the maintainers can take a look and mark them resolved.
This also allows for conversations in case you get stuck in a particular comment's context or amongst maintainers if there's any change of plans or someone suggests a better idea.

Copy link
Author

Choose a reason for hiding this comment

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

@subhramit okay ! sorry about that .

Copy link
Member

Choose a reason for hiding this comment

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

@subhramit okay ! sorry about that .

No issues, and no need to be sorry. It's on us to guide new contributors!

CHANGELOG.md Outdated
- Implemented BackupManagerGit to handle automatic backups of .bib files using Git, ensuring centralized, version-controlled backup management. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Added automatic copying of .bib files to a jabref/backups directory every 19 seconds with comprehensive commit history. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Added support for unique file naming using UUIDs to prevent overwriting files with identical names in the backup directory. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Introduced UI functionality (only during opening) for saving, restoring, reviewing and discarding changes with accurate commit details retrieval. [#2961](https://github.com/JabRef/jabref/issues/2961)
Copy link
Member

Choose a reason for hiding this comment

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

Part of the introduced feature (also pertains to the same issue). Remove this as well.

CHANGELOG.md Outdated
- Added automatic copying of .bib files to a jabref/backups directory every 19 seconds with comprehensive commit history. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Added support for unique file naming using UUIDs to prevent overwriting files with identical names in the backup directory. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Introduced UI functionality (only during opening) for saving, restoring, reviewing and discarding changes with accurate commit details retrieval. [#2961](https://github.com/JabRef/jabref/issues/2961)
- Enabled a "Restore" button to recover specific backup versions. [#2961](https://github.com/JabRef/jabref/issues/2961)
Copy link
Member

Choose a reason for hiding this comment

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

Remove.

Copy link
Member

Choose a reason for hiding this comment

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

Some user facing information should be kept, e.g. "enhanced backup and restore functionality".

CHANGELOG.md Outdated
@@ -52,6 +57,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Changed

- Refactored backup-related components to integrate with the new BackupManagerGit, replacing the older BackupManager logic. [#2961](https://github.com/JabRef/jabref/issues/2961)
Copy link
Member

Choose a reason for hiding this comment

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

Internal implementation, not relevant to user-side. Remove.

String normalized = lines
.map(String::trim) // Supprimer les espaces en début et fin de ligne
.filter(line -> !line.isBlank()) // Supprimer les lignes vides
.collect(Collectors.joining("\n")); // Réassembler avec des sauts de ligne
Copy link
Member

Choose a reason for hiding this comment

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

Avoid magic strings. Put \n into a constant named LINE_BREAK.

Copy link
Member

Choose a reason for hiding this comment

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

OS.NEWLINE

Comment on lines 44 to 45
mockDatabaseContext1 = mock(BibDatabaseContext.class);
mockDatabaseContext2 = mock(BibDatabaseContext.class);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to mock multiple instances of the same class.
If you actually want variation, make different entries/set of entries and generate a database context from them.

mockLibraryTab = mock(LibraryTab.class);
mockDatabaseContext1 = mock(BibDatabaseContext.class);
mockDatabaseContext2 = mock(BibDatabaseContext.class);
mockEntryTypesManager = mock(BibEntryTypesManager.class);
Copy link
Member

@subhramit subhramit Dec 5, 2024

Choose a reason for hiding this comment

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

You can make an actual instance instead of mocking this.

.map(Path::toFile)
.forEach(file -> {
if (!file.delete()) {
file.deleteOnExit();
Copy link
Member

Choose a reason for hiding this comment

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

@koppor Not sure about this one, I think using @TempDir would take care of the deletion?

GuiPreferences preferences,
List<BackupEntry> backups) {
return UiTaskExecutor.runInJavaFXThread(
() -> dialogService.showCustomDialogAndWait(new BackupChoiceDialog(preferences.getFilePreferences().getBackupDirectory(), backups)));
Copy link
Member

@subhramit subhramit Dec 5, 2024

Choose a reason for hiding this comment

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

Pass preferences.getFilePreferences().getBackupDirectory() via constructor and use it here for better abstraction (detailed reason in similar review comment above).

Also, is this supposed to be GuiPreferences or CliPreferences?

Copy link
Member

Choose a reason for hiding this comment

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

Its fine in the FilePreferences/GuiPreferences. You only need the backup in the ui mode.

Copy link
Member

Choose a reason for hiding this comment

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

Its fine in the FilePreferences/GuiPreferences. You only need the backup in the ui mode.

The rest of their changes involve clipreferences

Copy link
Member

Choose a reason for hiding this comment

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

guipreferences is a superset of clipreferences.

@subhramit
Copy link
Member

subhramit commented Dec 5, 2024

By the way, really good work guys.

Please also take a look at the failing tests and try to fix them.
https://devdocs.jabref.org/code-howtos/faq.html will help you.

Co-authored-by: Subhramit Basu Bhowmick <[email protected]>
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@subhramit
Copy link
Member

Hey team, good job fixing the tests.
The maintainers are currently a bit busy, and will get to your PR as soon as they find time.

@khola22
Copy link
Author

khola22 commented Dec 13, 2024

Hello @subhramit ,
We wanted to let you know that we have carefully reviewed all your comments and made the necessary adjustments. Thank you for taking the time to provide your feedback—it is greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants