-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.rs
More file actions
76 lines (75 loc) · 2.29 KB
/
Copy pathdiff.rs
File metadata and controls
76 lines (75 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! # Diff Module
//!
//! The diff module provides functionality for comparing files and parsing unified diff output.
//! It supports both Git diff and standard GNU diff formats, parsing them into a structured
//! representation for further processing.
//!
//! ## Overview
//!
//! This module is organized into three main components:
//!
//! - **models**: Data structures representing diff output, hunks, and individual lines
//! - **utils**: Utilities for executing diff commands (git diff or standard diff)
//! - **parser**: Functionality for parsing unified diff output into structured data
//!
//! ## Diff Types
//!
//! The module supports two diff formats:
//!
//! - **GitDiff**: Output from `git diff --no-index`, which includes `a/` and `b/` prefixes
//! - **GNUDiff**: Output from the standard `diff -u` command
//!
//! The module automatically attempts to use git diff first, falling back to standard diff
//! if git is not available.
//!
//! ## Data Flow
//!
//! ```text
//! File 1 & File 2
//! ↓
//! run_diff() ← Executes diff command
//! ↓
//! DiffOutput ← Raw diff output with metadata
//! ↓
//! parse_unified_diff() ← Parses diff text
//! ↓
//! DiffResult ← Structured representation
//! ↓
//! Hunks & Lines ← Individual changes
//! ```
//!
//! ## Usage Example
//!
//! ```ignore
//! use diff::utils;
//! use diff::parser;
//! use diff::models::LineType;
//!
//! // Run a diff on two files
//! let diff_output = utils::run_diff("file1.txt", "file2.txt")?;
//!
//! // Parse the diff output into a structured format
//! let diff_result = parser::parse_unified_diff(diff_output)?;
//!
//! // Check if there are any changes
//! if diff_result.has_changes() {
//! println!("Files differ");
//! } else {
//! println!("Files are identical");
//! }
//!
//! // Process hunks and lines
//! for hunk in diff_result.hunks {
//! println!("Hunk at old line {}: {} changes", hunk.old_start, hunk.lines.len());
//! for line in hunk.lines {
//! match line.line_type {
//! LineType::Added => println!("+ {}", line.content),
//! LineType::Deleted => println!("- {}", line.content),
//! LineType::Context => println!(" {}", line.content),
//! }
//! }
//! }
//! ```
pub mod models;
pub mod parser;
pub mod utils;