Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ anyhow = "1.0.93"
serde = "1.0.215"
serde_json = "1.0.132"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-subscriber = "0.3.19"
tracing-appender = "0.2"
thiserror = "2.0.3"
thiserror = "2.0.4"
rand = "0.8.5"
smallvec = "1.13.2"
tokio = "1.41.1"
tokio = "1.42"
tokio-stream = "0.1.16"
tokio-test = "0.4.4"
clap = "4.5.21"
Expand Down
2 changes: 1 addition & 1 deletion ceres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ callisto = { workspace = true }
mercury = { workspace = true }

anyhow = { workspace = true }
tokio = { workspace = true, features = ["net"] }
tokio = { workspace = true, features = ["net", "process"] }
tokio-stream = { workspace = true }
axum = { workspace = true }
tracing = { workspace = true }
Expand Down
76 changes: 76 additions & 0 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::{HashMap, VecDeque};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::{env, fs};

use axum::async_trait;
use tokio::process::Command;

use callisto::db_enums::ConvType;
use callisto::{mega_blob, mega_tree, raw_blob};
Expand Down Expand Up @@ -354,6 +356,80 @@ impl MonoApiService {
.unwrap();
Ok(p_commit_id)
}

pub async fn content_diff(&self, mr_link: &str) -> Result<String, GitError> {
let stg = self.context.mr_stg();
if let Some(mr) = stg.get_mr(mr_link).await.unwrap() {
let base_path = self.context.config.base_dir.clone();
env::set_current_dir(&base_path).unwrap();
let clone_path = base_path.join(mr_link);
if fs::exists(&clone_path).unwrap() {
fs::remove_dir_all(&clone_path).unwrap();
}
Command::new("mkdir")
.arg(mr_link)
.output()
.await
.expect("Failed to mkdir");
// cd QB0X1X1K
env::set_current_dir(&clone_path).unwrap();
// libra init
Command::new("libra")
.arg("init")
.output()
.await
.expect("Failed to execute libra init");
// libra remote add origin http://localhost:8000/project
Command::new("libra")
.arg("remote")
.arg("add")
.arg("origin")
.arg(format!("http://localhost:8000{}", mr.path))
.output()
.await
.expect("Failed to execute libra remote add");
// libra fetch origin QB0X1X1K
Command::new("libra")
.arg("fetch")
.arg("origin")
.arg(mr_link)
.output()
.await
.expect("Failed to execute libra fetch");
// libra branch QB0X1X1K origin/QB0X1X1K
Command::new("libra")
.arg("branch")
.arg(mr_link)
.arg(format!("origin/{}", mr_link))
.output()
.await
.expect("Failed to execute libra branch");
// libra switch QB0X1X1K
Command::new("libra")
.arg("switch")
.arg(mr_link)
.output()
.await
.expect("Failed to execute libra switch");
// libra diff --old 14899d8b9c36334a640c2e17255a546b0b9df105
let output = Command::new("libra")
.arg("diff")
.arg("--old")
.arg(mr.from_hash)
.output()
.await
.expect("Failed to execute libra diff");
if output.status.success() {
return Ok(String::from_utf8_lossy(&output.stdout).to_string());
} else {
tracing::error!(
"Command failed: {}",
String::from_utf8_lossy(&output.stderr)
);
}
}
Ok(String::new())
}
}

pub struct TreeComparation {
Expand Down
28 changes: 13 additions & 15 deletions ceres/src/pack/import_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl PackHandler for ImportRepo {
self.find_head_hash(refs)
}

async fn handle_receiver(&self, receiver: Receiver<Entry>) -> Result<String, GitError> {
async fn handle_receiver(&self, receiver: Receiver<Entry>) -> Result<Option<Commit>, GitError> {
let storage = self.context.services.git_db_storage.clone();
let mut entry_list = vec![];
let mut join_tasks = vec![];
Expand All @@ -65,25 +65,19 @@ impl PackHandler for ImportRepo {
if entry_list.len() >= 10000 {
let stg_clone = storage.clone();
let handle = tokio::spawn(async move {
stg_clone
.save_entry(repo_id, entry_list)
.await
.unwrap();
stg_clone.save_entry(repo_id, entry_list).await.unwrap();
});
join_tasks.push(handle);
entry_list = vec![];
}
}
join_all(join_tasks).await;
storage
.save_entry(repo_id, entry_list)
.await
.unwrap();
storage.save_entry(repo_id, entry_list).await.unwrap();
self.attach_to_monorepo_parent().await.unwrap();
Ok(String::new())
Ok(None)
}

async fn full_pack(&self) -> Result<ReceiverStream<Vec<u8>>, GitError> {
async fn full_pack(&self, _: Vec<String>) -> Result<ReceiverStream<Vec<u8>>, GitError> {
let pack_config = &self.context.config.pack;
let (entry_tx, entry_rx) = mpsc::channel(pack_config.channel_message_size);
let (stream_tx, stream_rx) = mpsc::channel(pack_config.channel_message_size);
Expand Down Expand Up @@ -294,12 +288,16 @@ impl PackHandler for ImportRepo {
.await
}

async fn handle_mr(&self, _: &str) -> Result<(), GitError> {
// do nothing in import_repo
Ok(())
async fn handle_mr(&self, _: &str) -> Result<String, GitError> {
unreachable!()
}

async fn update_refs(&self, refs: &RefCommand) -> Result<(), GitError> {
async fn update_refs(
&self,
_: Option<String>,
_: Option<Commit>,
refs: &RefCommand,
) -> Result<(), GitError> {
let storage = self.context.services.git_db_storage.clone();
match refs.command_type {
CommandType::Create => {
Expand Down
15 changes: 10 additions & 5 deletions ceres/src/pack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use common::{
errors::{MegaError, ProtocolError},
utils::ZERO_ID,
};
use mercury::internal::pack::Pack;
use mercury::internal::{object::commit::Commit, pack::Pack};
use mercury::{
errors::GitError,
internal::{
Expand All @@ -38,7 +38,7 @@ pub mod monorepo;
pub trait PackHandler: Send + Sync {
async fn head_hash(&self) -> (String, Vec<Refs>);

async fn handle_receiver(&self, rx: Receiver<Entry>) -> Result<String, GitError>;
async fn handle_receiver(&self, rx: Receiver<Entry>) -> Result<Option<Commit>, GitError>;

/// Asynchronously retrieves the full pack data for the specified repository path.
/// This function collects commits and nodes from the storage and packs them into
Expand All @@ -48,7 +48,7 @@ pub trait PackHandler: Send + Sync {
/// # Returns
/// * `Result<Vec<u8>, GitError>` - The packed binary data as a vector of bytes.
///
async fn full_pack(&self) -> Result<ReceiverStream<Vec<u8>>, GitError>;
async fn full_pack(&self, want: Vec<String>) -> Result<ReceiverStream<Vec<u8>>, GitError>;

async fn incremental_pack(
&self,
Expand All @@ -63,9 +63,14 @@ pub trait PackHandler: Send + Sync {
hashes: Vec<String>,
) -> Result<Vec<raw_blob::Model>, MegaError>;

async fn handle_mr(&self, title: &str) -> Result<(), GitError>;
async fn handle_mr(&self, title: &str) -> Result<String, GitError>;

async fn update_refs(&self, refs: &RefCommand) -> Result<(), GitError>;
async fn update_refs(
&self,
mr_link: Option<String>,
commit: Option<Commit>,
refs: &RefCommand,
) -> Result<(), GitError>;

async fn check_commit_exist(&self, hash: &str) -> bool;

Expand Down
Loading