chore: Normalize short_git_version strip optional 'g' and take first 7 chars#1734
chore: Normalize short_git_version strip optional 'g' and take first 7 chars#1734VolodymyrBg wants to merge 1 commit intoscroll-tech:developfrom
Conversation
WalkthroughRefactors short_git_version in crates/libzkp/src/utils.rs to consistently derive a 7-character commit abbreviation by splitting GIT_VERSION on hyphens, removing a leading 'g' if present, and truncating to seven characters. No public API signatures were changed. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/libzkp/src/utils.rs (1)
18-20: Edge case: exact tag builds can return the tag name, not a hashAt an exact tag,
git describe --alwaysreturns the tag itself (e.g.,v1.2.3), sosplit('-').next_back()yields the tag; the function would emit"v1.2.3"(truncated) instead of a 7-char hex. If callers expect a hex abbrev, release builds at tags will be inconsistent.Two low-friction fixes (either is fine):
- Make
git describealways include the-g<hash>suffix by adding--long.- Or scan from the end for the first segment that looks like
g[0-9a-f]+or[0-9a-f]+before truncating.Apply this minimal change if you prefer the
--longapproach:@@ -const GIT_VERSION: &str = git_version!(args = ["--abbrev=7", "--always"]); +const GIT_VERSION: &str = git_version!(args = ["--abbrev=7", "--always", "--long"]);Or, keep current args and harden the parsing:
@@ pub(crate) fn short_git_version() -> String { - let last = GIT_VERSION.split('-').next_back().unwrap(); - let hash = last.strip_prefix('g').unwrap_or(last); - hash.chars().take(7).collect() + let cand = GIT_VERSION + .rsplit('-') + .find(|s| s.starts_with('g') || s.chars().all(|c| c.is_ascii_hexdigit())) + .unwrap_or(GIT_VERSION); + let hash = cand.strip_prefix('g').unwrap_or(cand); + hash.chars().take(7).collect()Optional test suggestion (to guard both forms and exact-tag): extract the parsing into a small helper
fn short_from(s: &str) -> Stringand unit-test inputs likev1.2.3-45-gabcdef1,abcdef1, andv1.2.3.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/libzkp/src/utils.rs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crates/libzkp/src/utils.rs (1)
crates/libzkp/src/tasks/chunk.rs (1)
hash(190-190)
🔇 Additional comments (1)
crates/libzkp/src/utils.rs (1)
18-20: LGTM: simpler and correct normalization of g-prefixed vs bare hashesThe new logic robustly strips an optional leading 'g' and safely truncates to 7 chars without indexing panics. Matches the PR goal.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor