Skip to content

Commit 59a6d0c

Browse files
committed
wip: b
1 parent 1b526f3 commit 59a6d0c

File tree

7 files changed

+4
-263
lines changed

7 files changed

+4
-263
lines changed

src/cli/src/cmd_setup.rs

-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub const CHECKOUT: &str = "checkout";
1111
pub const CLONE: &str = "clone";
1212
pub const COMMIT_CACHE: &str = "commit-cache";
1313
pub const COMMIT: &str = "commit";
14-
pub const COMPARE: &str = "compare";
1514
pub const CONFIG: &str = "config";
1615
pub const CREATE_REMOTE: &str = "create-remote";
1716
pub const DF: &str = "df";
@@ -798,13 +797,6 @@ pub fn pull() -> Command {
798797

799798
pub fn diff() -> Command {
800799
Command::new(DIFF)
801-
.about("Compare two files against each other or against versions. The first parameter can be one of three things 1) another file 2) a commit hash 3) a branch name. If the first parameter is a revision it will compare the second parameter path to that version of the file.")
802-
.arg(Arg::new("FILE_OR_REVISION").required(true))
803-
.arg(Arg::new("PATH").required(false))
804-
}
805-
806-
pub fn compare() -> Command {
807-
Command::new(COMPARE)
808800
.about("Compare two tabular files with some schematic overlap. The two resource paramaters can be specified by filepath or `file:revision` syntax.")
809801
.arg(Arg::new("RESOURCE1")
810802
.required(true)

src/cli/src/dispatch.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,7 @@ pub async fn pull(remote: &str, branch: &str, all: bool) -> Result<(), OxenError
498498
Ok(())
499499
}
500500

501-
pub async fn diff(commit_id: Option<&str>, path: &str, remote: bool) -> Result<(), OxenError> {
502-
let repo_dir = env::current_dir().unwrap();
503-
let repository = LocalRepository::from_dir(&repo_dir)?;
504-
let path = Path::new(path);
505-
506-
let result = if remote {
507-
command::remote::diff(&repository, commit_id, path).await?
508-
} else {
509-
command::diff(&repository, commit_id, path)?
510-
};
511-
println!("{result}");
512-
Ok(())
513-
}
514-
515-
pub fn compare(
501+
pub fn diff(
516502
file_1: PathBuf,
517503
revision_1: Option<&str>,
518504
file_2: Option<PathBuf>,

src/cli/src/main.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ async fn main() {
2121
.subcommand(cmd_setup::clone())
2222
.subcommand(cmd_setup::commit_cache())
2323
.subcommand(cmd_setup::commit())
24-
.subcommand(cmd_setup::compare())
2524
.subcommand(cmd_setup::config())
2625
.subcommand(cmd_setup::create_remote())
2726
.subcommand(cmd_setup::df())
@@ -56,13 +55,12 @@ async fn main() {
5655
parse_and_run::compute_commit_cache(sub_matches).await
5756
}
5857
Some((cmd_setup::COMMIT, sub_matches)) => parse_and_run::commit(sub_matches).await,
59-
Some((cmd_setup::COMPARE, sub_matches)) => parse_and_run::compare(sub_matches).await,
58+
Some((cmd_setup::DIFF, sub_matches)) => parse_and_run::diff(sub_matches).await,
6059
Some((cmd_setup::CONFIG, sub_matches)) => parse_and_run::config(sub_matches),
6160
Some((cmd_setup::CREATE_REMOTE, sub_matches)) => {
6261
parse_and_run::create_remote(sub_matches).await
6362
}
6463
Some((cmd_setup::DF, sub_matches)) => parse_and_run::df(sub_matches),
65-
Some((cmd_setup::DIFF, sub_matches)) => parse_and_run::diff(sub_matches).await,
6664
Some((cmd_setup::DOWNLOAD, sub_matches)) => parse_and_run::download(sub_matches).await,
6765
Some((cmd_setup::INIT, sub_matches)) => parse_and_run::init(sub_matches).await,
6866
Some((cmd_setup::INFO, sub_matches)) => parse_and_run::info(sub_matches),

src/cli/src/parse_and_run.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -944,10 +944,9 @@ pub async fn pull(sub_matches: &ArgMatches) {
944944

945945
pub async fn remote_diff(sub_matches: &ArgMatches) {
946946
let is_remote = true;
947-
p_diff(sub_matches, is_remote).await
948947
}
949948

950-
pub async fn compare(sub_matches: &ArgMatches) {
949+
pub async fn diff(sub_matches: &ArgMatches) {
951950
let resource1 = sub_matches
952951
.get_one::<String>("RESOURCE1")
953952
.expect("required");
@@ -977,42 +976,14 @@ pub async fn compare(sub_matches: &ArgMatches) {
977976

978977
let output = sub_matches.get_one::<String>("output").map(PathBuf::from);
979978

980-
match dispatch::compare(file1, revision1, file2, revision2, keys, targets, output) {
979+
match dispatch::diff(file1, revision1, file2, revision2, keys, targets, output) {
981980
Ok(_) => {}
982981
Err(err) => {
983982
eprintln!("{err}")
984983
}
985984
}
986985
}
987986

988-
pub async fn diff(sub_matches: &ArgMatches) {
989-
let is_remote = false;
990-
p_diff(sub_matches, is_remote).await
991-
}
992-
993-
async fn p_diff(sub_matches: &ArgMatches, is_remote: bool) {
994-
// First arg is optional
995-
let file_or_commit_id = sub_matches
996-
.get_one::<String>("FILE_OR_REVISION")
997-
.expect("required");
998-
let path = sub_matches.get_one::<String>("PATH");
999-
if let Some(path) = path {
1000-
match dispatch::diff(Some(file_or_commit_id), path, is_remote).await {
1001-
Ok(_) => {}
1002-
Err(err) => {
1003-
eprintln!("{err}")
1004-
}
1005-
}
1006-
} else {
1007-
match dispatch::diff(None, file_or_commit_id, is_remote).await {
1008-
Ok(_) => {}
1009-
Err(err) => {
1010-
eprintln!("{err}")
1011-
}
1012-
}
1013-
}
1014-
}
1015-
1016987
pub async fn clone(sub_matches: &ArgMatches) {
1017988
let url = sub_matches.get_one::<String>("URL").expect("required");
1018989
let shallow = sub_matches.get_flag("shallow");

src/lib/src/api/local/diff.rs

-128
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,6 @@ struct DiffCommitEntry {
3939
pub base_entry: Option<CommitEntry>,
4040
}
4141

42-
/// Get a String representation of a diff between two commits given a file
43-
pub fn diff_one(
44-
repo: &LocalRepository,
45-
original: &Commit,
46-
compare: &Commit,
47-
path: impl AsRef<Path>,
48-
) -> Result<String, OxenError> {
49-
let base_path = get_version_file_from_commit(repo, original, &path)?;
50-
let head_path = get_version_file_from_commit(repo, compare, &path)?;
51-
diff_files(base_path, head_path)
52-
}
53-
54-
/// Compare a file between commits
55-
pub fn diff_one_2(
56-
repo: &LocalRepository,
57-
original: &Commit,
58-
compare: &Commit,
59-
path: impl AsRef<Path>,
60-
) -> Result<GenericDiff, OxenError> {
61-
let base_path = get_version_file_from_commit(repo, original, &path)?;
62-
let head_path = get_version_file_from_commit(repo, compare, &path)?;
63-
diff_files_2(base_path, head_path)
64-
}
65-
6642
pub fn get_version_file_from_commit(
6743
repo: &LocalRepository,
6844
commit: &Commit,
@@ -101,110 +77,6 @@ pub fn get_version_file_from_commit_id(
10177
Ok(util::fs::version_path(repo, &entry))
10278
}
10379

104-
pub fn diff_files(
105-
original: impl AsRef<Path>,
106-
compare: impl AsRef<Path>,
107-
) -> Result<String, OxenError> {
108-
let original = original.as_ref();
109-
let compare = compare.as_ref();
110-
if util::fs::is_tabular(original) && util::fs::is_tabular(compare) {
111-
let tabular_diff = diff_tabular(original, compare)?;
112-
return Ok(tabular_diff.to_string());
113-
} else if util::fs::is_utf8(original) && util::fs::is_utf8(compare) {
114-
return diff_utf8(original, compare);
115-
}
116-
Err(OxenError::basic_str(format!(
117-
"Diff not supported for files: {original:?} and {compare:?}"
118-
)))
119-
}
120-
121-
// TODO: this should be the one that is returned instead of a string
122-
pub fn diff_files_2(
123-
original: impl AsRef<Path>,
124-
compare: impl AsRef<Path>,
125-
) -> Result<GenericDiff, OxenError> {
126-
let original = original.as_ref();
127-
let compare = compare.as_ref();
128-
if util::fs::is_tabular(original) && util::fs::is_tabular(compare) {
129-
// TODO: consolidate TabularDiff and DataFrameDiff
130-
// let tabular_diff = diff_tabular(original, compare)?;
131-
// return Ok(GenericDiff::TabularDiff(tabular_diff));
132-
}
133-
Err(OxenError::basic_str(format!(
134-
"Diff not supported for files: {original:?} and {compare:?}"
135-
)))
136-
}
137-
138-
pub fn diff_utf8(
139-
original: impl AsRef<Path>,
140-
compare: impl AsRef<Path>,
141-
) -> Result<String, OxenError> {
142-
let original = original.as_ref();
143-
let compare = compare.as_ref();
144-
let original_data = util::fs::read_from_path(original)?;
145-
let compare_data = util::fs::read_from_path(compare)?;
146-
let Changeset { diffs, .. } = Changeset::new(&original_data, &compare_data, "\n");
147-
148-
let mut outputs: Vec<String> = vec![];
149-
for diff in diffs {
150-
match diff {
151-
Difference::Same(ref x) => {
152-
for split in x.split('\n') {
153-
outputs.push(format!(" {split}\n").normal().to_string());
154-
}
155-
}
156-
Difference::Add(ref x) => {
157-
for split in x.split('\n') {
158-
outputs.push(format!("+{split}\n").green().to_string());
159-
}
160-
}
161-
Difference::Rem(ref x) => {
162-
for split in x.split('\n') {
163-
outputs.push(format!("-{split}\n").red().to_string());
164-
}
165-
}
166-
}
167-
}
168-
169-
Ok(outputs.join(""))
170-
}
171-
172-
pub fn diff_tabular(
173-
base_path: impl AsRef<Path>,
174-
head_path: impl AsRef<Path>,
175-
) -> Result<DataFrameDiff, OxenError> {
176-
let base_path = base_path.as_ref();
177-
let head_path = head_path.as_ref();
178-
// Make sure files exist
179-
if !base_path.exists() {
180-
return Err(OxenError::entry_does_not_exist(base_path));
181-
}
182-
183-
if !head_path.exists() {
184-
return Err(OxenError::entry_does_not_exist(head_path));
185-
}
186-
187-
// Read DFs and get schemas
188-
let base_df = tabular::read_df(base_path, DFOpts::empty())?;
189-
let head_df = tabular::read_df(head_path, DFOpts::empty())?;
190-
let base_schema = Schema::from_polars(&base_df.schema());
191-
let head_schema = Schema::from_polars(&head_df.schema());
192-
193-
log::debug!(
194-
"Original df {} {base_path:?}\n{base_df:?}",
195-
base_schema.hash
196-
);
197-
log::debug!("Compare df {} {head_path:?}\n{head_df:?}", head_schema.hash);
198-
199-
// If schemas don't match, figure out which columns are different
200-
if base_schema.hash != head_schema.hash {
201-
compute_new_columns_from_paths(base_path, head_path, &base_schema, &head_schema)
202-
} else {
203-
log::debug!("Computing diff for {base_path:?} to {head_path:?}");
204-
compute_new_rows(&base_df, &head_df, &base_schema)
205-
}
206-
}
207-
20880
pub fn count_added_rows(base_df: DataFrame, head_df: DataFrame) -> Result<usize, OxenError> {
20981
// Hash the rows
21082
let base_df = tabular::df_hash_rows(base_df)?;

src/lib/src/command.rs

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod compare;
1212
pub mod config;
1313
pub mod db_inspect;
1414
pub mod df;
15-
pub mod diff;
1615
pub mod fetch;
1716
pub mod helpers;
1817
pub mod info;
@@ -37,7 +36,6 @@ pub use crate::command::clone::{clone, clone_url, deep_clone_url, shallow_clone_
3736
pub use crate::command::commit::commit;
3837
pub use crate::command::compare::compare;
3938
pub use crate::command::df::{df, schema};
40-
pub use crate::command::diff::diff;
4139
pub use crate::command::fetch::fetch;
4240
pub use crate::command::info::info;
4341
pub use crate::command::init::init;

src/lib/src/command/diff.rs

-76
This file was deleted.

0 commit comments

Comments
 (0)