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;