You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 27, 2026. It is now read-only.
let commit1 = git_ops.get_previous_commit(&commit2)?;
58
-
59
-
// Print the commits being used for the comparison
60
-
println!(
61
-
"Comparing commit {} with its parent commit {}.",
62
-
&commit2[..12.min(commit2.len())],
63
-
&commit1[..12.min(commit1.len())]
64
-
);
65
-
66
51
(commit1, commit2)
67
-
}else{
68
-
if args.commit1.is_none() || args.commit2.is_none(){
69
-
eprintln!("You must either provide two commit hashes using --commit1 and --commit2, or use the -b option to compare against another branch, or use -p with -c to compare with the previous commit.");
70
-
process::exit(1);
52
+
53
+
}elseifletSome(commit_to_compare) = args.commit{
54
+
// Commit comparison logic (using --commit and --previous)
55
+
match args.previous{
56
+
Some(Some(prev_commit_hash)) => {
57
+
// -p <hash> provided: Compare commit_to_compare with prev_commit_hash
58
+
let commit1 = prev_commit_hash;
59
+
let commit2 = commit_to_compare;
60
+
println!(
61
+
"Comparing specified commit {} with previous commit {}.",
62
+
&commit2[..12.min(commit2.len())],
63
+
&commit1[..12.min(commit1.len())]
64
+
);
65
+
(commit1, commit2)
66
+
}
67
+
Some(None) => {
68
+
// -p flag provided without value: Compare commit_to_compare with its parent
69
+
let commit2 = commit_to_compare;
70
+
let commit1 = git_ops.get_previous_commit(&commit2)?;
71
+
println!(
72
+
"Comparing specified commit {} with its parent commit {}.",
73
+
&commit2[..12.min(commit2.len())],
74
+
&commit1[..12.min(commit1.len())]
75
+
);
76
+
(commit1, commit2)
77
+
}
78
+
None => {
79
+
// Only -c provided, which is not enough for comparison.
80
+
eprintln!("Missing comparison target. Use --previous (-p) to compare with a parent or specific commit when using --commit, or use --branch (-b) to compare with another branch.");
81
+
process::exit(1);
82
+
}
71
83
}
72
-
73
-
(args.commit1.unwrap(), args.commit2.unwrap())
74
-
};
75
-
76
-
// Set output file or default to the user's temporary directory
77
-
let output_file = ifletSome(output_file) = args.output_file{
78
-
output_file
79
84
}else{
80
-
let default_output = "repodiff_output.txt".to_string();// Default filename in the working directory
81
-
default_output
85
+
// Neither --branch nor --commit specified.
86
+
eprintln!("You must specify either a branch to compare (--branch) or a commit to compare (--commit) along with a comparison target (--previous).");
87
+
process::exit(1);
82
88
};
83
89
90
+
// Set output file or default
91
+
let output_file = args.output_file.unwrap_or_else(|| "repodiff_output.txt".to_string());
92
+
84
93
// Process the diff and get the token count
85
94
let token_count = repodiff.process_diff(&commit1,&commit2,&output_file)?;
86
95
@@ -89,4 +98,4 @@ pub fn run() -> Result<()> {
89
98
println!("Total number of tokens: {}", token_count);
0 commit comments