-
Notifications
You must be signed in to change notification settings - Fork 123
Significant refactoring across Git operations, UI responsiveness, and error handling #441
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
Conversation
The core Git operations for generating diffs (unstaged, staged) and showing commit/stash details have been refactored to use the `git2` Rust library instead of shelling out to external `git` commands. This change offers several benefits: * **Improved Reliability:** Direct API calls are generally more robust than parsing command-line output. * **Error Handling:** Specific `git2::Error` types can be captured, replacing generic `io::Error` for Git-related failures. * **Performance:** Eliminates the overhead of spawning external processes for each operation. Affected areas include: * `diff_unstaged` and `diff_staged` * `show` (for commit details) * `stash_show` Error types `GitDiff` and `GitShow` in `src/error.rs` have been updated to `git2::Error` to reflect the new error sources. Consequently, many snapshot tests were updated to match the slightly altered output format produced by the `git2` diff generation.
The `git status` operation has been refactored to use the `git2` Rust library instead of shelling out to `git status --porcelain`. This change offers several benefits: * **Improved Reliability:** Direct API calls are generally more robust than parsing command-line output. * **Error Handling:** Specific `git2::Error` types can be captured, replacing generic `io::Error` for Git-related failures. * **Performance:** Eliminates the overhead of spawning external processes for each operation. The previous parsing logic, including the `pest` and `pest_derive` dependencies and the `src/git/parse/status` module, has been removed. Consequently, many snapshot tests were updated to match the slightly altered output format produced by `git2`'s status generation.
Updated string formatting throughout the codebase to adhere to clippy's recommendations. Specifically, this commit addresses instances of redundant or less idiomatic string formatting in macros like `format_args!`, `eprintln!`, `log::trace!`, and `log::error!`. These changes improve code readability and consistency, making the codebase happier according to `cargo clippy`.
The Git operations for detecting rebase, merge, and revert statuses have been refactored to use the `git2` Rust library. This change offers several benefits: * **Improved Reliability:** Direct API calls to `git2` for `RepositoryState` and OID parsing are more robust than manually reading and parsing `.git` status files. * **Enhanced Error Handling:** Replaces generic `io::Error` with more specific `git2::Error` types for Git-related failures and adds `GitRebaseStatus` to `src/error.rs`. * **Consistency:** Further aligns Git status detection with the `git2`-based implementation for `diff`, `show`, and general `status` operations. Specifically, the `rebase_status`, `merge_status`, and `revert_status` functions now leverage `repo.state()`, `git2::Oid`, and `repo.open_rebase()` for more accurate and robust status detection. Unnecessary `log::warn!` calls for file read errors have been replaced with proper error propagation. Minor formatting adjustments were also included.
This change introduces a non-blocking user interface for long-running Git
operations such as `fetch` and `pull`. Previously, the UI would freeze
while these commands executed, providing no visual feedback until
completion.
Now, when a long-running operation is initiated, a spinner appears in the
command log, indicating that the operation is in progress. Upon
completion, the spinner is replaced with a "completed" message, and the
full output of the command is displayed.
This refactor offers several benefits:
* **Improved User Experience:** The application remains responsive
during potentially time-consuming Git operations, enhancing perceived
performance.
* **Clearer Feedback:** Users now have immediate visual confirmation that
a command is being executed, reducing uncertainty about application
status.
* **Enhanced Information:** The complete output of fetch and pull
operations is now captured and displayed in the UI, providing more
context than before.
Key changes include:
* Introduction of `OperationStatus` enum and `ongoing_operations`
HashMap in `src/app.rs` to manage and track asynchronous command states.
* New `run_cmd_with_spinner` function in `src/app.rs` to initiate
commands with visual feedback.
* `fetch` and `pull` operations in `src/ops/fetch.rs` and
`src/ops/pull.rs` are updated to use the new non-blocking mechanism.
* The UI rendering logic in `src/ui.rs` is adapted to display animated
spinners for ongoing operations and their results upon completion.
* Numerous snapshot tests were updated to reflect the new output format
of completed operations.
This change introduces optimizations that provide better responsiveness
for syntax highlighting, especially for large repositories, while maintaining
full backward compatibility. Users can now disable syntax highlighting
entirely if performance is a concern.
Previously, syntax highlighting could lead to noticeable slowdowns and
unresponsiveness when dealing with extensive file contents.
Specific changes include:
* Increased the cache size for `HunkHighlights` from 200 to 500 entries.
* Introduced a new cached function, `cached_syntax_parse`, which leverages
`DefaultHasher` to store and reuse parsed syntax trees, significantly
reducing redundant computation.
* Implemented a performance safeguard in `iter_syntax_highlights` that
automatically disables highlighting for files exceeding 100,000 characters
in length, or if the feature is explicitly disabled in the configuration.
* Added `highlight` benchmarks in `benches/highlight.rs` to measure and
track the performance of syntax parsing and diff computation.
* Adjusted module visibility in `src/lib.rs` and `src/syntax_parser.rs`
to support the new benchmarking infrastructure.
This change refactors the application's error handling to provide more structured, contextual, and user-friendly messages. Previously, errors often lacked specific details about the failing operation or provided less actionable feedback, making debugging and user comprehension more difficult. This refactor offers several benefits: * **Enhanced Clarity:** New error variants (`GitOperationFailed`, `IoOperationFailed`, `ParsingFailed`) capture the specific operation that failed, along with the underlying error, providing richer context. * **Improved User Guidance:** Error display messages for critical operations (e.g., Git status, command failures) are now more descriptive and suggest potential remedies or checks. * **Consistency:** Helper functions (`Error::git_operation`, `Error::io_operation`, `Error::parsing`) ensure a standardized approach to error construction and propagation.
|
This has a lot of changes, so I suggest splitting it up into smaller PRs, so I can review one thing at a time.
Looks like a hallucination..
It is actually already non-blocking for those ops. I guess a spinner is nice.
Isn't it already cached?
This feels like a good thing to do. |
|
@altsem, thanks for your time, i will try |
Summary
This PR introduces significant refactoring across Git operations, UI responsiveness, and error handling. It abstracts Git operations using a
GitBackendtrait, enables non-blocking UI for long operations with spinners, optimizes syntax highlighting, and refines error reporting for better context and user feedback. The core Git operations are now handled by thegit2library for improved reliability and consistency.Description
Core Capabilities
GitBackendtrait to abstract Git operations, allowing for interchangeable backends (currentlyGit2Backendforgit2library integration).fetchandpull. A spinner is displayed in the command log during execution, and upon completion, a "completed" message along with the full command output is shown.Notes
The removal of the
pestdependency for parsing Git status output simplifies the codebase. The newGitBackendtrait provides a clean abstraction for Git interactions, paving the way for future backend implementations.