Skip to content

Commit

Permalink
draft...
Browse files Browse the repository at this point in the history
  • Loading branch information
demidko committed Apr 3, 2024
1 parent 8d69f66 commit 3e4cf4a
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ name = "archdiff"
version = "2024.3.12"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.release]
strip = "symbols"
panic = "abort"

[dependencies]
git2 = "0.18.3"
similar = "2.5.0"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# archiff
# archdiff

The utility calculates the difference of _architecture_ changes between two git branches. This is especially useful when
analyzing large merge requests. These languages are supported:
Expand Down
5 changes: 0 additions & 5 deletions src/arch.rs

This file was deleted.

5 changes: 5 additions & 0 deletions src/arch_hunk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub struct ArchHunk {
pub filename: String,
pub old_arch: String,
pub new_arch: String,
}
10 changes: 9 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::collections::hash_set::Difference;
use std::fmt::Debug;
use std::path::Path;
use std::str;

use git2::{Diff, DiffDelta, DiffFindOptions, DiffHunk, DiffLine, Object, ObjectType, Repository};
Expand Down Expand Up @@ -27,6 +29,7 @@ pub fn diff_branches<'a>(repo: &'a Repository, old_branch: &str, new_branch: &st

pub fn print_diff_line(delta: DiffDelta, hunk: Option<DiffHunk>, line: DiffLine) -> bool {
println!();
println!("{:?} {:?}", delta.old_file().path(), delta.new_file().path());
println!("{:?}", delta.status());
println!("{:?} {:?}", line.old_lineno(), line.new_lineno());
println!("{:?}", line.origin_value());
Expand All @@ -36,6 +39,11 @@ pub fn print_diff_line(delta: DiffDelta, hunk: Option<DiffHunk>, line: DiffLine)
true
}

fn extract_path<'a>(diff_delta: &'a DiffDelta) -> &'a Path {
let new_file = diff_delta.new_file().path();
let old_file = diff_delta.old_file().path();
new_file.or(old_file).unwrap()
}

fn make_tree_object<'a>(repo: &'a Repository, arg: &str) -> Object<'a> {
let obj = repo.revparse_single(arg).unwrap();
Expand All @@ -52,7 +60,7 @@ mod tests {
#[test]
fn it_works() {
let repo = open_current_repo();
let diff = diff_branches(&repo, "main", "test_branch");
let diff = diff_branches(&repo, "test_branch", "main");
let diff_format = DiffFormat::Patch;
diff.print(DiffFormat::Patch, print_diff_line).unwrap();
}
Expand Down
7 changes: 7 additions & 0 deletions src/languages/arch_diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::fmt::Display;

use git2::DiffLine;

pub trait ArchDiff: Display {
fn arch_diff(&mut self, filename: &str, diff: &DiffLine);
}
50 changes: 50 additions & 0 deletions src/languages/java_arch_diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::fmt::Display;
use std::ops::Add;

use diffy::create_patch;
use git2::DiffLine;

use crate::languages::arch_diff::ArchDiff;

struct JavaArchDiff {
filename: String,
old_arch: String,
new_arch: String,
diff: String,
}

impl JavaArchDiff {
fn flush(&mut self) {
let old = &self.old_arch;
let new = &self.new_arch;
let diff = create_patch(old, new);
let diff = diff.to_string();
self.diff += &diff
}
}

impl Display for JavaArchDiff {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.diff)
}
}

impl ArchDiff for JavaArchDiff {
fn arch_diff(&mut self, filename: &str, diff: &DiffLine) {
todo!()
}
}

#[cfg(test)]
mod tests {
use diffy::{create_patch, DiffOptions};

#[test]
fn it_works() {
let old = "ool\nkek\njey trek\n";
let new = "lol\nkek\njey trep";
let diff = create_patch(old, new);
println!("{}", diff);
}
}

3 changes: 3 additions & 0 deletions src/languages/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod arch_diff;

mod java_arch_diff;
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
mod git;
mod arch;
mod arch_hunk;

mod languages;


fn main() {}

0 comments on commit 3e4cf4a

Please sign in to comment.