Skip to content

Commit 9287e63

Browse files
authored
complete MR layer creation (#1233)
1 parent f9e7b12 commit 9287e63

12 files changed

Lines changed: 128 additions & 60 deletions

File tree

jupiter/src/service/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
pub mod issue_service;
44
pub mod mr_service;
5-

libra/src/command/commit.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ pub async fn execute(args: CommitArgs) {
5858
let user_email = UserConfig::get("user", None, "email")
5959
.await
6060
.unwrap_or_else(|| "unknown".to_string());
61-
61+
6262
// get sign line
6363
let signoff_line = format!("Signed-off-by: {user_name} <{user_email}>");
6464
format!("{}\n\n{signoff_line}", args.message)
6565
} else {
6666
args.message.clone()
6767
};
68-
68+
6969
// check format(if needed)
7070
if args.conventional && !check_conventional_commits_message(&commit_message) {
7171
panic!("fatal: commit message does not follow conventional commits");
@@ -270,11 +270,10 @@ mod test {
270270
let args = args.unwrap();
271271
assert!(args.amend);
272272
assert!(args.signoff);
273-
274273
}
275274

276275
#[tokio::test]
277-
#[serial]
276+
#[serial]
278277
/// Tests the recursive tree creation from index entries.
279278
/// Verifies that tree objects are correctly created, saved to storage, and properly organized in a hierarchical structure.
280279
async fn test_create_tree() {

libra/tests/command/log_test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,32 +132,32 @@ async fn test_log_oneline() {
132132
let temp_path = tempdir().unwrap();
133133
test::setup_with_new_libra_in(temp_path.path()).await;
134134
let _guard = ChangeDirGuard::new(temp_path.path());
135-
135+
136136
// Create test commits
137137
let commit_id = create_test_commit_tree().await;
138138
let reachable_commits = get_reachable_commits(commit_id).await;
139-
139+
140140
// Test oneline format
141-
let args = LogArgs {
142-
number: Some(3),
143-
oneline: true
141+
let args = LogArgs {
142+
number: Some(3),
143+
oneline: true,
144144
};
145-
145+
146146
// Since execute function writes to stdout, we'll test the logic directly
147147
let mut sorted_commits = reachable_commits.clone();
148148
sorted_commits.sort_by(|a, b| b.committer.timestamp.cmp(&a.committer.timestamp));
149-
149+
150150
let max_commits = std::cmp::min(args.number.unwrap_or(usize::MAX), sorted_commits.len());
151-
151+
152152
for (i, commit) in sorted_commits.iter().take(max_commits).enumerate() {
153153
// Test short hash format (should be 7 characters)
154154
let short_hash = &commit.id.to_string()[..7];
155155
assert_eq!(short_hash.len(), 7);
156-
156+
157157
// Test that commit message parsing works
158158
let (msg, _) = common::utils::parse_commit_msg(&commit.message);
159159
assert!(!msg.is_empty());
160-
160+
161161
// For our test commits, verify the expected format
162162
let expected_number = 6 - i; // commits are numbered 6, 5, 4, 3, 2, 1
163163
assert_eq!(msg.trim(), format!("Commit_{expected_number}"));

mercury/src/internal/model/commit.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
2-
31
use callisto::{git_commit, mega_commit};
42
use common::utils::generate_id;
53

6-
use crate::{
7-
internal::{
8-
object::{commit::Commit, ObjectTrait},
9-
pack::entry::Entry,
10-
},
4+
use crate::internal::{
5+
object::{commit::Commit, ObjectTrait},
6+
pack::entry::Entry,
117
};
128

13-
149
impl From<Commit> for mega_commit::Model {
1510
fn from(value: Commit) -> Self {
1611
mega_commit::Model {

mercury/src/internal/object/blob.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl ObjectTrait for Blob {
8282
}
8383

8484
impl Blob {
85-
8685
/// Create a new Blob object from the given content string.
8786
/// - This is a convenience method for creating a Blob from a string.
8887
/// - It converts the string to bytes and then calls `from_content_bytes`.

mercury/src/internal/object/commit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ impl PartialEq for Commit {
5151
}
5252
}
5353

54-
55-
5654
impl Display for Commit {
5755
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5856
writeln!(f, "tree: {}", self.tree_id)?;
@@ -279,4 +277,4 @@ impl From<git_commit::Model> for Commit {
279277
value.content,
280278
)
281279
}
282-
}
280+
}

mercury/src/internal/pack/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ mod tests {
573573
println!("{data:?}");
574574
let mut reader = Cursor::new(data);
575575
let (result, _) = read_offset_encoding(&mut reader).unwrap();
576-
println!("result: {result}" );
576+
println!("result: {result}");
577577
assert_eq!(result, value as u64);
578578
}
579579
}

scorpio/src/daemon/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async fn mount_handler(
154154
};
155155

156156
let store_path = PathBuf::from(store_path).join(&temp_hash);
157-
let _ = state.fuse.overlay_mount(inode, store_path,false).await;
157+
let _ = state.fuse.overlay_mount(inode, store_path, false).await;
158158
let mount_info = MountInfo {
159159
hash: temp_hash.clone(),
160160
path: mono_path.clone(),
@@ -174,10 +174,15 @@ async fn mount_handler(
174174
}
175175

176176
if let Some(m) = &req.mr {
177-
177+
let mr_store_path = PathBuf::from(store_path).join("mr");
178178
// if mr is provided, we need to fetch the mr info from mono.
179-
mr::build_mr_layer(m, store_path.into()).await.unwrap();
180-
179+
if let Err(e) = mr::build_mr_layer(m, mr_store_path).await {
180+
return axum::Json(MountResponse {
181+
status: FAIL.into(),
182+
mount: MountInfo::default(),
183+
message: format!("Failed to build mr layer: {e}"),
184+
});
185+
}
181186
}
182187

183188
// fetch the dionary node info from mono.
@@ -186,7 +191,10 @@ async fn mount_handler(
186191
let store_path = PathBuf::from(store_path).join(&work_dir.hash);
187192
// checkout / mount this dictionary.
188193

189-
let _ = state.fuse.overlay_mount(inode, store_path,false).await;
194+
let _ = state
195+
.fuse
196+
.overlay_mount(inode, store_path, req.mr.is_some())
197+
.await;
190198

191199
let mount_info = MountInfo {
192200
hash: work_dir.hash,

scorpio/src/fuse/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ impl MegaFuse {
7070
// mount user works.
7171
for dir in &manager.works {
7272
let _lower = PathBuf::from(store_path).join(&dir.hash);
73-
megafuse.overlay_mount(dir.node, &_lower,false).await.unwrap();
73+
megafuse
74+
.overlay_mount(dir.node, &_lower, false)
75+
.await
76+
.unwrap();
7477
}
7578

7679
megafuse
@@ -92,7 +95,7 @@ impl MegaFuse {
9295
&self,
9396
inode: u64,
9497
store_path: P,
95-
need_mr:bool, // if need mr, then create mr layer.
98+
need_mr: bool, // if need mr, then create mr layer.
9699
) -> std::io::Result<()> {
97100
let lower = store_path.as_ref().join("lower");
98101
let upper = store_path.as_ref().join("upper");
@@ -151,8 +154,6 @@ impl MegaFuse {
151154
Ok(())
152155
}
153156

154-
155-
156157
/// Unmounts the overlay filesystem associated with a given inode asynchronously.
157158
///
158159
/// This function removes the overlay filesystem mapped to the specified inode from

scorpio/src/manager/fetch.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,29 @@ pub fn enqueue_file_download(file_id: SHA1, save_path: PathBuf) {
328328
}
329329
}
330330

331+
/// Download multiple files for MR scenarios.
332+
pub async fn download_mr_files(
333+
files: Vec<(SHA1, PathBuf)>,
334+
) -> Result<(), Box<dyn std::error::Error>> {
335+
let download_manager = DownloadManager::get_global();
336+
337+
// Since this is for MR files only (no directory traversal),
338+
// we mark directory processing as complete immediately
339+
download_manager.notify_directory_processing_complete();
340+
341+
// Enqueue all file download tasks
342+
for (file_id, save_path) in files {
343+
let task = DownloadTask::new(file_id, save_path);
344+
if let Err(e) = download_manager.enqueue_download(task) {
345+
return Err(format!("Failed to enqueue download task for file {file_id}: {e}").into());
346+
}
347+
}
348+
349+
// Wait for all downloads to complete
350+
download_manager.wait_for_completion().await;
351+
352+
Ok(())
353+
}
331354
#[allow(unused)]
332355
#[async_trait]
333356
pub trait CheckHash {

0 commit comments

Comments
 (0)