refactor(bare): enhance security and performance optimizations

- Remove unnecessary sorting in advertise_refs for deterministic output
- Add path traversal detection and validation in bare_dir construction
- Implement symlink resolution checks to prevent security vulnerabilities
- Refactor cache system with CRC validation and improved metrics
- Integrate repo-specific cache invalidation using indexed keys
- Add comprehensive unit tests for commit operations and diff functionality
- Move configuration constants to centralized config module
- Optimize string operations in disk cache random value generation
- Enhance license detection algorithm with cleaner matching logic
- Streamline argument processing in various git operations
- Update dependencies including crc32fast and flate2 for performance
- Add signal handling capability to tokio runtime configuration
This commit is contained in:
zhenyi
2026-06-12 15:04:12 +08:00
parent e386f44ee2
commit 10a4398e81
41 changed files with 1373 additions and 365 deletions
+49
View File
@@ -172,3 +172,52 @@ pub fn setup_bare_repo_with_conflict() -> (tempfile::TempDir, GitBare) {
(dir, GitBare::new(bare_dir))
}
#[allow(dead_code)]
pub fn get_oid(gb: &GitBare, rev: &str) -> String {
let output = std::process::Command::new("git")
.args([
"--git-dir",
gb.bare_dir.to_string_lossy().as_ref(),
"rev-parse",
rev,
])
.output()
.expect("git rev-parse");
assert!(output.status.success(), "git rev-parse {rev} failed");
String::from_utf8_lossy(&output.stdout).trim().to_string()
}
#[allow(dead_code)]
pub fn get_main_oid(gb: &GitBare) -> String {
get_oid(gb, "refs/heads/main")
}
#[allow(dead_code)]
pub fn get_feature_oid(gb: &GitBare) -> String {
get_oid(gb, "refs/heads/feature")
}
#[allow(dead_code)]
pub fn oid_selector(hex: &str) -> Option<gitks::pb::ObjectSelector> {
Some(gitks::pb::ObjectSelector {
selector: Some(gitks::pb::object_selector::Selector::Oid(
gitks::pb::Oid {
hex: hex.to_string(),
value: vec![],
format: 0,
},
)),
})
}
#[allow(dead_code)]
pub fn rev_selector(rev: &str) -> Option<gitks::pb::ObjectSelector> {
Some(gitks::pb::ObjectSelector {
selector: Some(gitks::pb::object_selector::Selector::Revision(
gitks::pb::ObjectName {
revision: rev.to_string(),
},
)),
})
}