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

Use git for backup #12252

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

Use git for backup #12252

wants to merge 102 commits into from

Conversation

khola22
Copy link

@khola22 khola22 commented Dec 2, 2024

Fiixes #2961

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.
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.

Comment on lines 49 to 50
entries1.add(new BibEntry("this"));
entries1.add(new BibEntry("is"));
Copy link
Member

@subhramit subhramit Dec 15, 2024

Choose a reason for hiding this comment

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

Use different entry types (e.g. Article). Also add fields to the entries using .withField(...)
Example -

void ooHTMLTransformFromCitationWithMultipleEntries(String expected, CitationStyle style) throws IOException {
BibEntry entry1 = new BibEntry(StandardEntryType.Article)
.withField(StandardField.AUTHOR, "Garcia, Maria and Lee, David")
.withField(StandardField.JOURNAL, "International Review of Physics")
.withField(StandardField.NUMBER, "6")
.withField(StandardField.PAGES, "789--810")
.withField(StandardField.TITLE, "Quantum Entanglement in Superconductors")
.withField(StandardField.VOLUME, "28")
.withField(StandardField.ISSUE, "3")
.withField(StandardField.YEAR, "2021")
.withCitationKey("Garcia_2021");

Copy link
Author

Choose a reason for hiding this comment

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

It is modified accordingly !

.gitmodules Outdated
@@ -13,3 +13,6 @@
url = https://github.com/citation-style-language/locales.git
ignore = all
shallow = true
[submodule "jabref"]
Copy link
Member

Choose a reason for hiding this comment

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

Revert this change

Copy link
Member

Choose a reason for hiding this comment

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

and also fix the other submodule issues.
You probably have to first sync your main branch with the latest changes from upstream and then your branch

Copy link
Author

Choose a reason for hiding this comment

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

Hello ! I am sorry for the late reply. I applied what is written here https://devdocs.jabref.org/code-howtos/faq.html#submodules to fix the submodules, it worked correctly because I no more have local changes when I execute : git checkout main -- src/main/resources/csl-styles, still, the problem with the submodule csl-styles doesn't seem to be resolved. And can you tell me what changes am I supposed to adress in the CHANGELOG (we already added the suggested edits from the last month, but there is still some changes required by the PR).

@subhramit
Copy link
Member

subhramit commented Jan 13, 2025

@khola22 we will be making sure your feature is a part of the 6.0-beta release. Thanks for so much patience, it's just that the maintainers are a bit busy with a couple of things (and other urgent issues) at the moment. We'll provide more feedback as soon as we can.

# Conflicts:
#	src/main/resources/csl-locales
#	src/main/resources/csl-styles
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

In case of issues with the import order, double check that you activated Auto Import.
You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

@koppor
Copy link
Member

koppor commented Jan 27, 2025

To ease organizational workflows I have linked the pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message. The pull request must be on the default branch.

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

If you use a keyword to reference a pull request comment in another pull request, the pull requests will be linked. Merging the referencing pull request also closes the referenced pull request.

The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.

Example:

  • Fixes #xyz links pull-request to issue. Merging the PR will close the Issue.
  • Fixes https://github.com/JabRef/jabref/issues/xyz links pull-request to issue. Merging the PR will close the Issue.
  • Fixes https://github.com/Koppor/jabref/issues/xyz links pull-request to issue. Merging the PR will close the Issue.
  • Fixes [#xyz](https://github.com/JabRef/jabref/issues/xyz) links pull-request to issue. Merging the PR will NOT close the Issue.

@koppor
Copy link
Member

koppor commented Jan 27, 2025

Submodule config got messed up:

   Submodule 'abbrv.jabref.org' (https://github.com/JabRef/abbrv.jabref.org.git) registered for path 'buildres/abbrv.jabref.org'
  Error: fatal: No url found for submodule path 'jabref' in .gitmodules

I try to find out how to fix - will be difficult.

@koppor
Copy link
Member

koppor commented Jan 27, 2025

Submodule config got messed up:

   Submodule 'abbrv.jabref.org' (https://github.com/JabRef/abbrv.jabref.org.git) registered for path 'buildres/abbrv.jabref.org'
  Error: fatal: No url found for submodule path 'jabref' in .gitmodules

I try to find out how to fix - will be difficult.

 git rm --cached jabref

Hint https://www.deployhq.com/support/common-repository-errors/no-url-found-for-submodule (found via Google)

Copy link
Member

@koppor koppor left a comment

Choose a reason for hiding this comment

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

I started to dive into the code, but some basic non-code conventions distracted me. Please try to fix them. They might seem to be trivial for you, but I would need several minutes for it, but I currently don't have time to do these kind of tasks. I need time for feedback on a higher level.

LOGGER.info("Database file uniquely copied to backup directory: {}", backupFilePath);
}

// A method
Copy link
Member

Choose a reason for hiding this comment

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

This comment can be removed.

LOGGER.info("Successfully rewrote the file at path: {}", dbFile);
}

// Helper method to normalize BibTeX content
Copy link
Member

Choose a reason for hiding this comment

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

Convert to JAvaDoc - ALL comments to Methods have to be JavaDoc

The WHY is missing the comment -why is this needed?

* @param backupDir the backup directory
* @param objectId the commit ID to restore from
*/

Copy link
Member

Choose a reason for hiding this comment

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

JavaDoc and method begin should be kept together - please remove all empty lines between JavaDoc and method.

if (needsBackup) {
LOGGER.info("Backup needed, because needsBackup is :{}", needsBackup);
} else {
LOGGER.info("Backup needed, because needsCommit is :{}", needsCommit);
Copy link
Member

Choose a reason for hiding this comment

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

indent is wrong. I wonder why our checkstyle did not comlain here.

}

if (needsBackup) {
LOGGER.info("Backup needed, because needsBackup is :{}", needsBackup);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LOGGER.info("Backup needed, because needsBackup is :{}", needsBackup);
LOGGER.info("Backup needed, because needsBackup is: {}", needsBackup);

Please use Amercian positioning of spaces and colon: First comes the colon, then the space.

Comment on lines +39 to +40
String content = Localization.lang("It looks like JabRef did not shut down cleanly last time the file was used.") + "\n\n" +
Localization.lang("Do you want to recover the library from a backup file?");
Copy link
Member

Choose a reason for hiding this comment

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

Merge this into one string!

(Even though in the original, newlines were also split like this, but this is wrong)

@koppor
Copy link
Member

koppor commented Jan 27, 2025

Note that I renamed "BackupManagerGit" to "BackupManager" as the "old" BackupManager is gone. No need to create a new class. Keeping the base class name also simplifies reviewing.

@koppor koppor changed the title Git Integration and UI Improvements Use git for backup Feb 5, 2025
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.

8 participants