-
Notifications
You must be signed in to change notification settings - Fork 0
Unify Author type, optimize performance and fix parsing accuracy #11
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
Remove duplicate Author struct from tag module and use the existing Author type from log module to avoid API ambiguity and maintain consistency across the codebase.
- Replace O(n) git show calls with single git for-each-ref in tag listing - Fix stash branch name parsing by correcting splitn logic - Add proper Unix timestamp parsing for tags and stashes - Update CLAUDE.md to reflect timestamp behavior documentation
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.
Pull Request Overview
This PR unifies the Author type across modules, optimizes tag parsing performance, and improves timestamp accuracy. The changes eliminate code duplication by using a shared Author type and switch to more efficient Git commands for better performance.
- Unified Author type by removing duplicate struct and importing from log module
- Optimized tag listing performance by replacing multiple git show calls with single git for-each-ref command
- Enhanced timestamp parsing accuracy by implementing proper Unix timestamp parsing for stashes
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/commands/tag.rs | Removes duplicate Author struct, implements efficient git for-each-ref parsing, adds Unix timestamp parsing |
| src/commands/stash.rs | Adds Unix timestamp parsing and updates stash list format to include actual timestamps |
| CLAUDE.md | Updates documentation to reflect unified Author type and clarifies default behavior |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/commands/tag.rs
Outdated
| /// Parse Unix timestamp to DateTime<Utc> | ||
| fn parse_unix_timestamp(timestamp_str: &str) -> Result<DateTime<Utc>> { |
Copilot
AI
Sep 21, 2025
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.
The parse_unix_timestamp function is duplicated between tag.rs and stash.rs. Consider moving this utility function to a shared module to avoid code duplication.
src/commands/tag.rs
Outdated
|
|
||
| if parts.len() < 9 { | ||
| return Err(GitError::CommandFailed( | ||
| "Invalid for-each-ref format".to_string(), |
Copilot
AI
Sep 21, 2025
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.
The error message 'Invalid for-each-ref format' is not specific enough. Consider including the expected number of parts (9) and actual number received to help with debugging.
| "Invalid for-each-ref format".to_string(), | |
| format!( | |
| "Invalid for-each-ref format: expected 9 parts, got {}. Line: '{}'", | |
| parts.len(), | |
| line | |
| ), |
src/commands/tag.rs
Outdated
| // Build tagger information for annotated tags | ||
| let tagger = | ||
| if tag_type == TagType::Annotated && !tagger_name.is_empty() && !tagger_email.is_empty() { | ||
| let timestamp = parse_unix_timestamp(tagger_date).unwrap_or_else(|_| Utc::now()); |
Copilot
AI
Sep 21, 2025
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.
Using unwrap_or_else(|_| Utc::now()) silently ignores parsing errors. Consider logging the error or using a more explicit fallback strategy for better debugging.
| let timestamp = parse_unix_timestamp(tagger_date).unwrap_or_else(|_| Utc::now()); | |
| let timestamp = parse_unix_timestamp(tagger_date).unwrap_or_else(|err| { | |
| eprintln!("Failed to parse tagger date '{}': {}. Falling back to Utc::now()", tagger_date, err); | |
| Utc::now() | |
| }); |
| // Format: "stash@{0} hash timestamp On branch: message" | ||
| let parts: Vec<&str> = line.splitn(4, ' ').collect(); | ||
|
|
||
| if parts.len() < 4 { |
Copilot
AI
Sep 21, 2025
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.
The parsing logic expects 4 parts but the format comment indicates 'stash@{0} hash timestamp On branch: message' which would be 5+ parts. The splitn(4, ' ') will merge everything after the 4th space into the last element, but the validation should check for at least 4 parts after adding timestamp.
| if parts.len() < 4 { | |
| if parts.len() < 4 || !parts[3].contains(':') { |
src/commands/stash.rs
Outdated
| let hash = Hash::from(parts[1]); | ||
|
|
||
| // Parse timestamp | ||
| let timestamp = parse_unix_timestamp(parts[2]).unwrap_or_else(|_| Utc::now()); |
Copilot
AI
Sep 21, 2025
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.
Using unwrap_or_else(|_| Utc::now()) silently ignores parsing errors. Consider logging the error or using a more explicit fallback strategy for better debugging.
| let timestamp = parse_unix_timestamp(parts[2]).unwrap_or_else(|_| Utc::now()); | |
| let timestamp = parse_unix_timestamp(parts[2])?; |
- Extract duplicate parse_unix_timestamp function from tag and stash modules - Add shared implementation to utils module with comprehensive documentation - Update imports in tag.rs and stash.rs to use shared function - Add test coverage for the shared utility function
- Include expected and actual parts count in error message for better debugging - Add test coverage for invalid format error handling - Change from generic "Invalid format" to specific "expected 9 parts, got X"
- Add explicit comments explaining timestamp parsing error handling - Document when and why fallback to current time occurs - Add test for invalid timestamp parsing with fallback verification - Clarify that fallback indicates corrupted git metadata edge case
- Include expected and actual parts count in validation error message - Add validation for empty remainder part containing branch and message - Add comprehensive test coverage for parsing edge cases - Change from generic "Invalid format" to specific "expected 4 parts, got X"
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.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let timestamp = parse_unix_timestamp(tagger_date).unwrap_or_else(|_| { | ||
| // Timestamp parsing failed - this indicates malformed git metadata | ||
| // Fall back to current time to avoid breaking the API, but this should be rare | ||
| Utc::now() | ||
| }); |
Copilot
AI
Sep 21, 2025
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.
The fallback to current time when timestamp parsing fails may mask data corruption issues. Consider logging the error or using a more appropriate fallback like epoch time to indicate invalid data."
src/commands/stash.rs
Outdated
| let hash = Hash::from(parts[1]); | ||
|
|
||
| // Parse timestamp | ||
| let timestamp = parse_unix_timestamp(parts[2]).unwrap_or_else(|_| Utc::now()); |
Copilot
AI
Sep 21, 2025
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.
Using current time as fallback for invalid timestamps is inconsistent with the error handling pattern. This silent fallback may hide data corruption issues and make debugging difficult."
| let timestamp = parse_unix_timestamp(parts[2]).unwrap_or_else(|_| Utc::now()); | |
| let timestamp = match parse_unix_timestamp(parts[2]) { | |
| Ok(ts) => ts, | |
| Err(e) => { | |
| return Err(GitError::CommandFailed(format!( | |
| "Failed to parse stash timestamp '{}': {}", | |
| parts[2], e | |
| ))); | |
| } | |
| }; |
- Add explicit comments explaining timestamp parsing error handling - Document when and why fallback to current time occurs - Add test for invalid timestamp parsing with fallback verification - Clarify that fallback indicates corrupted git stash metadata edge case
…tion - Replace Utc::now() fallback with Unix epoch (1970-01-01) for invalid timestamps - Make data corruption obvious instead of silently masking with current time - Add test verification for epoch fallback behavior - Ensure consistent error handling pattern across both modules
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.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
The DateTime::from_timestamp(0, 0).unwrap_or_else(Utc::now) chain is problematic. If DateTime::from_timestamp(0, 0) fails (which is extremely unlikely), it falls back to the current time, making it inconsistent with the documented behavior of using Unix epoch as a fallback for data corruption. Consider using DateTime::from_timestamp(0, 0).unwrap() or a more explicit error handling approach. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.