|
1 | 1 | use std::{ |
2 | 2 | collections::{HashMap, HashSet}, |
3 | | - path::{Component, Path, PathBuf}, |
| 3 | + path::{Component, PathBuf}, |
4 | 4 | str::FromStr, |
5 | 5 | sync::{ |
6 | 6 | Arc, |
@@ -39,9 +39,9 @@ use tokio::sync::{RwLock, mpsc}; |
39 | 39 | use tokio_stream::wrappers::ReceiverStream; |
40 | 40 |
|
41 | 41 | use crate::{ |
42 | | - api_service::{ApiHandler, cache::GitObjectCache, mono_api_service::MonoApiService, tree_ops}, |
| 42 | + api_service::{ApiHandler, cache::GitObjectCache, mono_api_service::MonoApiService}, |
43 | 43 | code_edit::{on_push::OnpushCodeEdit, utils::get_changed_files}, |
44 | | - model::change_list::{BuckFile, ClDiffFile}, |
| 44 | + model::change_list::ClDiffFile, |
45 | 45 | pack::RepoHandler, |
46 | 46 | protocol::import_refs::{RefCommand, Refs}, |
47 | 47 | }; |
@@ -589,93 +589,6 @@ impl MonoRepo { |
589 | 589 | Ok(cl_link) |
590 | 590 | } |
591 | 591 |
|
592 | | - #[allow(dead_code)] |
593 | | - async fn search_buck_under_cl(&self, cl_path: &Path) -> Result<Vec<BuckFile>, MegaError> { |
594 | | - let mut res = vec![]; |
595 | | - let mono_stg = self.storage.mono_storage(); |
596 | | - let mono_api_service: MonoApiService = self.into(); |
597 | | - |
598 | | - let mut path = Some(cl_path); |
599 | | - let mut path_q = Vec::new(); |
600 | | - while let Some(p) = path { |
601 | | - path_q.push(p); |
602 | | - path = p.parent(); |
603 | | - } |
604 | | - if path_q.len() > 2 { |
605 | | - path_q.pop(); |
606 | | - path_q.pop(); |
607 | | - |
608 | | - let p = path_q[path_q.len() - 1]; |
609 | | - if p.parent().is_some() |
610 | | - && let Some(tree) = tree_ops::search_tree_by_path(&mono_api_service, p, None) |
611 | | - .await |
612 | | - .ok() |
613 | | - .flatten() |
614 | | - && let Some(buck) = self.try_extract_buck(tree, cl_path) |
615 | | - { |
616 | | - return Ok(vec![buck]); |
617 | | - }; |
618 | | - return Ok(vec![]); |
619 | | - } |
620 | | - |
621 | | - let mut search_trees: Vec<(PathBuf, Tree)> = vec![]; |
622 | | - |
623 | | - let diff_trees = self.diff_trees_from_cl().await?; |
624 | | - for (path, new, old) in diff_trees { |
625 | | - match (new, old) { |
626 | | - (None, _) => { |
627 | | - continue; |
628 | | - } |
629 | | - (Some(sha1), _) => { |
630 | | - let tree = mono_stg.get_tree_by_hash(&sha1.to_string()).await?.unwrap(); |
631 | | - search_trees.push((path, Tree::from_mega_model(tree))); |
632 | | - } |
633 | | - } |
634 | | - } |
635 | | - |
636 | | - for (path, tree) in search_trees { |
637 | | - if let Some(buck) = self.try_extract_buck(tree, &cl_path.join(path)) { |
638 | | - res.push(buck); |
639 | | - } |
640 | | - } |
641 | | - |
642 | | - Ok(res) |
643 | | - } |
644 | | - |
645 | | - fn try_extract_buck(&self, tree: Tree, cl_path: &Path) -> Option<BuckFile> { |
646 | | - let mut buck = None; |
647 | | - let mut buck_config = None; |
648 | | - for item in tree.tree_items { |
649 | | - if item.is_blob() && item.name == "BUCK" { |
650 | | - buck = Some(item.id) |
651 | | - } |
652 | | - if item.is_blob() && item.name == ".buckconfig" { |
653 | | - buck_config = Some(item.id) |
654 | | - } |
655 | | - } |
656 | | - match (buck, buck_config) { |
657 | | - (Some(buck), Some(buck_config)) => Some(BuckFile { |
658 | | - buck, |
659 | | - buck_config, |
660 | | - path: cl_path.to_path_buf(), |
661 | | - }), |
662 | | - _ => None, |
663 | | - } |
664 | | - } |
665 | | - |
666 | | - async fn diff_trees_from_cl( |
667 | | - &self, |
668 | | - ) -> Result<Vec<(PathBuf, Option<ObjectHash>, Option<ObjectHash>)>, MegaError> { |
669 | | - let mono_stg = self.storage.mono_storage(); |
670 | | - let from_c = mono_stg.get_commit_by_hash(&self.from_hash).await?.unwrap(); |
671 | | - let from_tree: Tree = |
672 | | - Tree::from_mega_model(mono_stg.get_tree_by_hash(&from_c.tree).await?.unwrap()); |
673 | | - let to_c = mono_stg.get_commit_by_hash(&self.to_hash).await?.unwrap(); |
674 | | - let to_tree: Tree = |
675 | | - Tree::from_mega_model(mono_stg.get_tree_by_hash(&to_c.tree).await?.unwrap()); |
676 | | - diff_trees(&to_tree, &from_tree) |
677 | | - } |
678 | | - |
679 | 592 | pub fn username(&self) -> String { |
680 | 593 | self.username.clone().unwrap_or(String::from("Anonymous")) |
681 | 594 | } |
@@ -841,35 +754,3 @@ impl MonoRepo { |
841 | 754 | Ok(()) |
842 | 755 | } |
843 | 756 | } |
844 | | - |
845 | | -#[allow(dead_code)] |
846 | | -type DiffResult = Vec<(PathBuf, Option<ObjectHash>, Option<ObjectHash>)>; |
847 | | - |
848 | | -#[allow(dead_code)] |
849 | | -fn diff_trees(theirs: &Tree, base: &Tree) -> Result<DiffResult, MegaError> { |
850 | | - let their_items: HashMap<_, _> = get_plain_items(theirs).into_iter().collect(); |
851 | | - let base_items: HashMap<_, _> = get_plain_items(base).into_iter().collect(); |
852 | | - let all_paths: HashSet<_> = their_items.keys().chain(base_items.keys()).collect(); |
853 | | - |
854 | | - let mut diffs = Vec::new(); |
855 | | - |
856 | | - for path in all_paths { |
857 | | - let their_hash = their_items.get(path).cloned(); |
858 | | - let base_hash = base_items.get(path).cloned(); |
859 | | - if their_hash != base_hash { |
860 | | - diffs.push((path.clone(), their_hash, base_hash)); |
861 | | - } |
862 | | - } |
863 | | - Ok(diffs) |
864 | | -} |
865 | | - |
866 | | -#[allow(dead_code)] |
867 | | -fn get_plain_items(tree: &Tree) -> Vec<(PathBuf, ObjectHash)> { |
868 | | - let mut items = Vec::new(); |
869 | | - for item in tree.tree_items.iter() { |
870 | | - if item.is_tree() { |
871 | | - items.push((PathBuf::from(item.name.clone()), item.id)); |
872 | | - } |
873 | | - } |
874 | | - items |
875 | | -} |
0 commit comments