* feat: add flush_vbranches method to Controller struct
The `flush_vbranches` method has been added to the `Controller` struct. This method allows flushing virtual branches as a tree for a specific project. It iterates over the virtual branches of the project and calls the `flush_vbranch_as_tree` function to flush each virtual branch. This method is used in the `Handler` struct to flush virtual branches for a project before flushing the session.
* cleanup error handling
* make controller async for consistency and block on the caller site
- Previously, the functions `init_device_oauth` and `check_auth_status` did not properly handle errors when sending requests and parsing response bodies.
- This commit updates the error handling in both functions to provide more informative error messages and properly propagate errors.
- Now, if there is an error sending the request or parsing the response body, the functions will return an `Error::Unknown` error with the appropriate context.
- This improves the reliability and error reporting of the login functionality in the client application.
The changes in this commit add support for tracking the upstream head commit in virtual branches. This is done by introducing a new field `upstream_head` in the `Branch` struct. The `upstream_head` field represents the last commit that has been pushed to the upstream branch.
The following changes were made:
- Added `upstream_head` field to the `Branch` struct
- Updated the `create_virtual_branch` function to initialize the `upstream_head` field as `None`
- Updated the `push` function to set the `upstream_head` field to the current head commit of the virtual branch
- Updated the `create_virtual_branch_from_branch` function to initialize the `upstream_head` field as `None`
- Updated the `BranchWriter` struct to write the `upstream_head` field to the branch metadata
- Updated the `TryFrom<&dyn crate::reader::Reader>` implementation
* remove GB_FLUSH after processing it
* add test for flushing and deleting flush file
* add more unittests for cases:
* no session, file -> no flush, file deleted
* session, file -> flush, file deleted
* session, no file -> no flush
The `set_user` function in the client code has been updated to return the updated user object after setting it in the app. This change allows for better handling of the user object and enables further operations on it if needed. The updated function now returns a `Result<User, Error>` instead of `Result<(), Error>`.
The zip controller has been refactored to use the new zip module. This change includes updating the import statements and modifying the main function to generate the tauri context with the new zip module.
Additionally, the zip controller now has a new struct called Controller, which contains the necessary fields for handling zip operations. The TryFrom trait has been implemented for the Controller struct to allow for easy creation from the AppHandle.
The main changes include:
- Importing the zip module and updating import statements
- Refactoring the main function to generate the tauri context with the new zip module
- Creating a new Controller struct for handling zip operations
- Implementing the TryFrom trait for the Controller struct to allow for easy creation from the AppHandle
The changes in this commit refactor the error handling in the controller module. Instead of using a specific error type for storage errors, the code now uses the `anyhow` crate to handle errors more generically. This simplifies the code and allows for better error handling and reporting.
The users controller has been added to handle user-related operations such as getting, setting, and deleting user information. This controller is responsible for interacting with the storage module to perform these operations.
The mark_active_session function has been added to the Repository struct. This function updates the last_timestamp_ms field of the current session's metadata to the current system time. This is done to keep track of the last time the session was active.
This function is called in several places where the current session is required to be updated, such as when writing to targets, branches, deltas, bookmarks, and handling git file changes. By updating the session metadata, we ensure that the session remains active and up-to-date.
This change improves the accuracy of session tracking and helps in managing active sessions effectively.
The changes in this commit refactor the methods in the `projects_storage` module to use consistent naming and simplify the code. The following changes were made:
- Renamed the `update_project` method to `update` in the `projects_storage` module.
- Renamed the `add_project` method to `add` in the `projects_storage` module.
- Renamed the `get_project` method to `get` in the `projects_storage` module.
- Renamed the `list_projects` method to `list` in the `projects_storage` module.
These changes improve code readability and maintainability by using consistent naming conventions and simplifying the method signatures.
- The `upsert_bookmark` method was not properly handling the async code. It now properly awaits the necessary async operations.
- The `init_project` method now properly handles async code and awaits the necessary async operations.
- The `init` method now properly handles async code and awaits the necessary async operations.
- The `add_project` method now properly handles async code and awaits the necessary async operations.
This ensures that the async operations are properly executed and awaited, preventing potential race conditions or incorrect behavior.
The previous implementation used a string to represent the project path, which led to potential issues when manipulating paths. The update changes the project path to use the path::PathBuf type, which provides better path manipulation and error handling capabilities. This change improves the overall reliability and maintainability of the code.
The code previously included unnecessary steps to make the symlink target path relative and convert it to a byte array. These steps have been removed as they are not needed for creating the symlink content.
The changes in this commit update the dependencies in the Cargo.toml file and remove the sentry-anyhow package. The sentry-anyhow package is no longer needed as it has been replaced by the sentry package. This change simplifies the dependencies and ensures that the project is using the latest versions of the required packages.
The changes in this commit add support for unapplying ownership for a hunk in the client. This allows users to discard changes made to a specific hunk and revert it back to its original state. The unapplyHunk method is added to the BranchController class, which sends a request to the server to unapply the ownership of the hunk. Upon successful unapplying, the virtual branch store is reloaded to reflect the changes.
The parsing logic for ownership ranges in the `FileOwnership` struct has been improved. Previously, it split the input string by ':' and then by ',' to extract the file path and ranges. However, this approach had issues with file paths containing ':' characters.
The updated logic now iterates over the parts of the input string in reverse order. If a part can be parsed as a `Hunk` (range), it is added to the `ranges` vector. Otherwise, it is considered as part of the file path and added to the `file_path_parts` vector. Finally, the `file_path_parts` vector is joined with ':' to form the file path.
This change ensures that file paths containing ':' characters are correctly parsed, allowing for more flexible and accurate parsing of ownership ranges.
The merge_virtual_branch_upstream, apply_branch, and update_base_branch functions had repetitive code for checking out conflicts. This commit refactors the code to use a new CheckoutIndexBuilder struct, which simplifies the checkout options and makes the code more readable.
The code for checking out a tree has been simplified by removing unnecessary code and using the builder pattern for checkout options. This makes the code more readable and maintainable.
The merge_virtual_branch_upstream function is added to merge the changes from the upstream branch into the current branch. This function checks if the project is in a conflicted state and if not, it proceeds with the merge. It finds the merge base between the upstream commit and the current branch's head commit, and then tries to merge the working directory tree with the remote tree. If the merge is successful, it commits the merge tree and updates the branch data.
The virtual branch module structure has been refactored to improve code organization and readability. The module now consists of separate files for virtual branch, remote, and files related functionality.
Additionally, materialized view structs have been added for presentation purposes. These structs include `VirtualBranch`, `VirtualBranchCommit`, `VirtualBranchFile`, and `VirtualBranchHunk`. These structs provide a materialized view of the virtual branch data and are used for presentation purposes through the IPC.
This refactoring improves code maintainability and provides a clearer separation of concerns between the virtual branch module and the presentation layer.