refactor(build): reformat code and add tonic health dependency

- Reformatted build script with proper indentation and line breaks
- Added tonic-health dependency to Cargo.toml and updated lock file
- Improved error handling in disk cache with concurrent deletion checks
- Refactored conditional chains using && and let expressions
- Reformatted struct initialization and function parameter lists
- Added proper spacing and alignment in language stats processing
- Improved assertion formatting in test cases
- Reorganized import statements and code layout in multiple files
- Updated metrics functions with better parameter handling and formatting
This commit is contained in:
zhenyi
2026-06-11 13:56:15 +08:00
parent c32a7cad2f
commit a40da90ef9
31 changed files with 696 additions and 417 deletions
+19 -12
View File
@@ -5,9 +5,7 @@ use gix::object::tree::EntryKind;
use crate::bare::GitBare;
use crate::error::{GitError, GitResult};
use crate::pb::{
GetLanguageStatsRequest, GetLanguageStatsResponse, LanguageStat, object_selector,
};
use crate::pb::{GetLanguageStatsRequest, GetLanguageStatsResponse, LanguageStat, object_selector};
// Include the generated linguist rules
include!(concat!(env!("OUT_DIR"), "/linguist_generated.rs"));
@@ -181,10 +179,12 @@ impl GitBare {
let mut resolved: HashMap<String, LangStats> = HashMap::new();
for (lang, s) in stats {
let target = resolve_group(&lang).unwrap_or(&lang);
let entry = resolved.entry(target.to_string()).or_insert_with(|| LangStats {
lang_type: s.lang_type.clone(),
..Default::default()
});
let entry = resolved
.entry(target.to_string())
.or_insert_with(|| LangStats {
lang_type: s.lang_type.clone(),
..Default::default()
});
entry.file_count += s.file_count;
entry.bytes += s.bytes;
entry.lines += s.lines;
@@ -214,7 +214,11 @@ impl GitBare {
})
.collect();
languages.sort_by(|a, b| b.bytes.cmp(&a.bytes).then_with(|| a.language.cmp(&b.language)));
languages.sort_by(|a, b| {
b.bytes
.cmp(&a.bytes)
.then_with(|| a.language.cmp(&b.language))
});
Ok(GetLanguageStatsResponse {
languages,
@@ -283,10 +287,13 @@ impl GitBare {
*ctx.total_bytes += size;
*ctx.total_lines += lines;
let s = ctx.stats.entry(lang_key.clone()).or_insert_with(|| LangStats {
lang_type: lang_type.to_string(),
..Default::default()
});
let s = ctx
.stats
.entry(lang_key.clone())
.or_insert_with(|| LangStats {
lang_type: lang_type.to_string(),
..Default::default()
});
s.file_count += 1;
s.bytes += size;
s.lines += lines;
+1 -1
View File
@@ -57,7 +57,7 @@ impl GitBare {
let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 2 {
let oid = parts[0];
let found = parts.get(1).map_or(true, |&s| s != "missing");
let found = parts.get(1).is_none_or(|&s| s != "missing");
let size = parts.get(1).and_then(|s| s.parse().ok()).unwrap_or(0);
sizes.push(ObjectSize {
oid: oid.to_string(),
+12 -12
View File
@@ -19,13 +19,13 @@ impl GitBare {
let stats = self.get_repository_statistics()?;
// Run commit-graph write if needed
if stats.commit_graph_size_bytes == 0 || strategy == OptimizeStrategy::Aggressive {
if let Ok(resp) = write_commit_graph(self, false, false) {
if !resp.ok {
stderr_all.push_str(&resp.stderr);
}
stdout_all.push_str(&resp.stdout);
if (stats.commit_graph_size_bytes == 0 || strategy == OptimizeStrategy::Aggressive)
&& let Ok(resp) = write_commit_graph(self, false, false)
{
if !resp.ok {
stderr_all.push_str(&resp.stderr);
}
stdout_all.push_str(&resp.stdout);
}
// Repack if many loose objects or packfiles
@@ -42,13 +42,13 @@ impl GitBare {
}
// Prune if aggressive
if strategy == OptimizeStrategy::Aggressive {
if let Ok(resp) = run_gc(self, true, true) {
if !resp.ok {
stderr_all.push_str(&resp.stderr);
}
stdout_all.push_str(&resp.stdout);
if strategy == OptimizeStrategy::Aggressive
&& let Ok(resp) = run_gc(self, true, true)
{
if !resp.ok {
stderr_all.push_str(&resp.stderr);
}
stdout_all.push_str(&resp.stdout);
}
}
OptimizeStrategy::Incremental => {
+8 -8
View File
@@ -58,14 +58,14 @@ impl GitBare {
// Format: path:line:col:matched_text
if let Some((path_and_rest, matched)) = line.rsplit_once(':') {
let prefix_parts: Vec<&str> = path_and_rest.rsplitn(3, ':').collect();
if prefix_parts.len() >= 3 {
if let Ok(line_num) = prefix_parts[0].parse::<u32>() {
results.push(SearchResult {
path: prefix_parts[2].to_string(),
line: line_num,
matched_text: matched.to_string(),
});
}
if prefix_parts.len() >= 3
&& let Ok(line_num) = prefix_parts[0].parse::<u32>()
{
results.push(SearchResult {
path: prefix_parts[2].to_string(),
line: line_num,
matched_text: matched.to_string(),
});
}
}
}