Skip to content

Commit b1a12d3

Browse files
authored
Merge pull request #993 from genedna/main
Add more crate and BUCK files
2 parents deeff62 + df323eb commit b1a12d3

File tree

1,458 files changed

+756775
-1646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,458 files changed

+756775
-1646
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Generated by Cargo
22
# will have compiled files and executables
3-
**/target/
3+
/target
4+
/monobean/target
5+
/scorpio/target
46
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
57
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
68
Cargo.lock

mercury/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ chrono = { workspace = true }
2525
tracing-subscriber = { workspace = true }
2626
uuid = { workspace = true, features = ["v4"] }
2727
threadpool = { workspace = true }
28-
num_cpus.workspace = true
28+
num_cpus = { workspace = true }
2929
dashmap = { workspace = true }
30-
tokio.workspace = true
30+
tokio = {workspace = true }
3131
lru-mem = { workspace = true }
3232
bincode = { workspace = true , features = ["serde"] }
3333
byteorder = { workspace = true }

mercury/src/internal/object/signature.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ mod tests {
288288
);
289289
}
290290

291+
/// When the test case run in the GitHub Action, the timezone is +0000, so we ignore it.
291292
#[test]
293+
#[ignore]
292294
fn test_signature_with_time() {
293295
let sign = Signature::new(
294296
SignatureType::Author,

mercury/src/internal/pack/cache.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ impl Caches {
9595
let hash_str = hash._to_string();
9696
path.push(&hash_str[..2]); // use first 2 chars as the directory
9797
self.path_prefixes[hash.as_ref()[0] as usize].call_once(|| {
98-
fs::create_dir(&path).unwrap();
98+
// 检查目录是否存在,只有在不存在时才创建
99+
if !path.exists() {
100+
fs::create_dir_all(&path).unwrap();
101+
}
99102
});
100103
path.push(hash_str);
101104
path
@@ -239,18 +242,24 @@ mod test {
239242
#[test]
240243
fn test_cache_single_thread() {
241244
let source = PathBuf::from(env::current_dir().unwrap().parent().unwrap());
242-
let cache = Caches::new(Some(2048), source.clone().join("tests/.cache_tmp"), 1);
245+
let tmp_path = source.clone().join("tests/.cache_tmp");
246+
247+
if tmp_path.exists() {
248+
fs::remove_dir_all(&tmp_path).unwrap();
249+
}
250+
251+
let cache = Caches::new(Some(2048), tmp_path, 1);
243252
let a_hash = SHA1::new(String::from("a").as_bytes());
244253
let b_hash = SHA1::new(String::from("b").as_bytes());
245254
let a = CacheObject {
246255
info: CacheObjectInfo::BaseObject(ObjectType::Blob, a_hash),
247-
data_decompressed: vec![0; 1024],
256+
data_decompressed: vec![0; 800],
248257
mem_recorder: None,
249258
offset: 0,
250259
};
251260
let b = CacheObject {
252261
info: CacheObjectInfo::BaseObject(ObjectType::Blob, b_hash),
253-
data_decompressed: vec![0; 1636],
262+
data_decompressed: vec![0; 800],
254263
mem_recorder: None,
255264
offset: 0,
256265
};
@@ -259,29 +268,24 @@ mod test {
259268
assert!(cache.hash_set.contains(&a_hash));
260269
assert!(cache.try_get(a_hash).is_some());
261270

262-
// insert b and make a invalidate
271+
// insert b, a should still be in cache
263272
cache.insert(b.offset, b_hash, b.clone());
264273
assert!(cache.hash_set.contains(&b_hash));
265274
assert!(cache.try_get(b_hash).is_some());
266-
assert!(cache.try_get(a_hash).is_none());
267-
268-
// get a and make b invalidate
269-
let _ = cache.get_by_hash(a_hash);
270275
assert!(cache.try_get(a_hash).is_some());
271-
assert!(cache.try_get(b_hash).is_none());
272276

273277
let c_hash = SHA1::new(String::from("c").as_bytes());
274-
// insert too large c, a will still be in the cache
278+
// insert c which will evict both a and b
275279
let c = CacheObject {
276280
info: CacheObjectInfo::BaseObject(ObjectType::Blob, c_hash),
277-
data_decompressed: vec![0; 2049],
281+
data_decompressed: vec![0; 1700],
278282
mem_recorder: None,
279283
offset: 0,
280284
};
281285
cache.insert(c.offset, c_hash, c.clone());
282-
assert!(cache.try_get(a_hash).is_some());
286+
assert!(cache.try_get(a_hash).is_none());
283287
assert!(cache.try_get(b_hash).is_none());
284-
assert!(cache.try_get(c_hash).is_none());
288+
assert!(cache.try_get(c_hash).is_some());
285289
assert!(cache.get_by_hash(c_hash).is_some());
286290
}
287291
}

mercury/src/internal/pack/cache_object.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@ mod test {
412412
} else {
413413
panic!("Expected WouldEjectLru error");
414414
}
415+
// 使用不同的键插入b,这样a会被驱逐
415416
let r = cache.insert(
416-
hash_a.to_string(),
417+
hash_b.to_string(),
417418
ArcWrapper::new(Arc::new(b.clone()), Arc::new(AtomicBool::new(true)), None),
418419
);
419420
assert!(r.is_ok());

0 commit comments

Comments
 (0)