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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ saturn = { path = "saturn" }
mono = { path = "mono" }
observatory = { path = "extensions/observatory" }
orion = { path = "orion" }
bellatrix = { path = "orion-server/bellatrix" }
context = { path = "context" }
neptune = { path = "neptune" }

Expand Down
1 change: 1 addition & 0 deletions ceres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jupiter = { workspace = true }
callisto = { workspace = true }
mercury = { workspace = true }
neptune = { workspace = true }
bellatrix = { workspace = true }

anyhow = { workspace = true }
tokio = { workspace = true, features = ["net", "process"] }
Expand Down
37 changes: 15 additions & 22 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use async_trait::async_trait;
use callisto::sea_orm_active_enums::ConvTypeEnum;
use callisto::{mega_blob, mega_mr, mega_tree, raw_blob};
use common::errors::MegaError;
use neptune::neptune_engine::Diff;
use jupiter::storage::base_storage::StorageConnector;
use jupiter::storage::Storage;
use jupiter::utils::converter::generate_git_keep_with_timestamp;
Expand All @@ -53,6 +52,7 @@ use mercury::hash::SHA1;
use mercury::internal::object::blob::Blob;
use mercury::internal::object::commit::Commit;
use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode};
use neptune::neptune_engine::Diff;

use crate::api_service::ApiHandler;
use crate::model::git::CreateFileInfo;
Expand Down Expand Up @@ -378,22 +378,21 @@ impl MonoApiService {
///
/// # Returns
/// String containing the unified diff output
pub async fn content_diff(
&self,
mr_link: &str,
) -> Result<String, GitError> {
pub async fn content_diff(&self, mr_link: &str) -> Result<String, GitError> {
let stg = self.storage.mr_storage();
let mr = stg.get_mr(mr_link).await.unwrap().ok_or_else(|| {
GitError::CustomError(format!("Merge request not found: {mr_link}"))
})?;

let old_blobs = self.get_commit_blobs(&mr.from_hash).await.map_err(|e| {
GitError::CustomError(format!("Failed to get old commit blobs: {e}"))
})?;
let new_blobs = self.get_commit_blobs(&mr.to_hash).await.map_err(|e| {
GitError::CustomError(format!("Failed to get new commit blobs: {e}"))
})?;
let mr =
stg.get_mr(mr_link).await.unwrap().ok_or_else(|| {
GitError::CustomError(format!("Merge request not found: {mr_link}"))
})?;

let old_blobs = self
.get_commit_blobs(&mr.from_hash)
.await
.map_err(|e| GitError::CustomError(format!("Failed to get old commit blobs: {e}")))?;
let new_blobs = self
.get_commit_blobs(&mr.to_hash)
.await
.map_err(|e| GitError::CustomError(format!("Failed to get new commit blobs: {e}")))?;

let algo = "histogram".to_string(); // Default diff algorithm
let filter_paths: Vec<PathBuf> = Vec::new(); // No filtering by default
Expand Down Expand Up @@ -428,13 +427,7 @@ impl MonoApiService {
};

// Use the unified diff function that returns a single string
let diff_output = Diff::diff(
old_blobs,
new_blobs,
algo,
filter_paths,
read_content,
).await;
let diff_output = Diff::diff(old_blobs, new_blobs, algo, filter_paths, read_content).await;

Ok(diff_output)
}
Expand Down
7 changes: 7 additions & 0 deletions ceres/src/model/mr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ pub enum MrDiffFile {
// path, old_hash, new_hash
Modified(PathBuf, SHA1, SHA1),
}

#[derive(Serialize)]
pub struct BuckFile {
pub buck: SHA1,
pub buck_config: SHA1,
pub path: PathBuf,
}
12 changes: 10 additions & 2 deletions ceres/src/pack/import_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use mercury::{hash::SHA1, internal::pack::encode::PackEncoder};

use crate::{
api_service::{mono_api_service::MonoApiService, ApiHandler},
pack::PackHandler,
pack::RepoHandler,
protocol::{
import_refs::{CommandType, RefCommand, Refs},
repo::Repo,
Expand All @@ -38,7 +38,7 @@ pub struct ImportRepo {
}

#[async_trait]
impl PackHandler for ImportRepo {
impl RepoHandler for ImportRepo {
async fn head_hash(&self) -> (String, Vec<Refs>) {
let result = self
.storage
Expand Down Expand Up @@ -292,6 +292,14 @@ impl PackHandler for ImportRepo {
Ok(())
}

async fn save_or_update_mr(&self) -> Result<(), MegaError> {
Ok(())
}

async fn post_mr_operation(&self) -> Result<(), MegaError> {
Ok(())
}

async fn check_commit_exist(&self, hash: &str) -> bool {
self.storage
.git_db_storage()
Expand Down
6 changes: 5 additions & 1 deletion ceres/src/pack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod import_repo;
pub mod monorepo;

#[async_trait]
pub trait PackHandler: Send + Sync + 'static {
pub trait RepoHandler: Send + Sync + 'static {
async fn head_hash(&self) -> (String, Vec<Refs>);

async fn receiver_handler(
Expand Down Expand Up @@ -116,6 +116,10 @@ pub trait PackHandler: Send + Sync + 'static {

async fn update_refs(&self, refs: &RefCommand) -> Result<(), GitError>;

async fn save_or_update_mr(&self) -> Result<(), MegaError>;

async fn post_mr_operation(&self) -> Result<(), MegaError>;

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

async fn check_default_branch(&self) -> bool;
Expand Down
Loading
Loading