Skip to main content

java_diff_utils_rs/unifieddiff/
unified_diff_file.rs

1//! Data structure representing one patched file in a unified diff document.
2
3use crate::patch::patch::Patch;
4
5/// Holds metadata and the patch for a single file in a unified diff.
6#[derive(Debug, Clone, Default, PartialEq, Eq)]
7pub struct UnifiedDiffFile {
8    diff_command: Option<String>,
9    from_file: Option<String>,
10    from_timestamp: Option<String>,
11    to_file: Option<String>,
12    rename_from: Option<String>,
13    rename_to: Option<String>,
14    copy_from: Option<String>,
15    copy_to: Option<String>,
16    to_timestamp: Option<String>,
17    index: Option<String>,
18    new_file_mode: Option<String>,
19    old_mode: Option<String>,
20    new_mode: Option<String>,
21    deleted_file_mode: Option<String>,
22    binary_added: Option<String>,
23    binary_deleted: Option<String>,
24    binary_edited: Option<String>,
25    patch: Patch<String>,
26    no_new_line_at_the_end_of_the_file: bool,
27    similarity_index: Option<i32>,
28}
29
30impl UnifiedDiffFile {
31    /// Constructs a new, empty `UnifiedDiffFile`.
32    pub fn new() -> Self {
33        Self::default()
34    }
35
36    /// Constructs a `UnifiedDiffFile` with initial `from_file`, `to_file`, and `patch`.
37    pub fn from(
38        from_file: impl Into<String>,
39        to_file: impl Into<String>,
40        patch: Patch<String>,
41    ) -> Self {
42        Self {
43            from_file: Some(from_file.into()),
44            to_file: Some(to_file.into()),
45            patch,
46            ..Default::default()
47        }
48    }
49
50    pub fn diff_command(&self) -> Option<&str> {
51        self.diff_command.as_deref()
52    }
53
54    pub fn set_diff_command(&mut self, diff_command: impl Into<String>) {
55        self.diff_command = Some(diff_command.into());
56    }
57
58    pub fn from_file(&self) -> Option<&str> {
59        self.from_file.as_deref()
60    }
61
62    pub fn set_from_file(&mut self, from_file: impl Into<String>) {
63        self.from_file = Some(from_file.into());
64    }
65
66    pub fn to_file(&self) -> Option<&str> {
67        self.to_file.as_deref()
68    }
69
70    pub fn set_to_file(&mut self, to_file: impl Into<String>) {
71        self.to_file = Some(to_file.into());
72    }
73
74    pub fn index(&self) -> Option<&str> {
75        self.index.as_deref()
76    }
77
78    pub fn set_index(&mut self, index: impl Into<String>) {
79        self.index = Some(index.into());
80    }
81
82    pub fn patch(&self) -> &Patch<String> {
83        &self.patch
84    }
85
86    pub fn patch_mut(&mut self) -> &mut Patch<String> {
87        &mut self.patch
88    }
89
90    pub fn set_patch(&mut self, patch: Patch<String>) {
91        self.patch = patch;
92    }
93
94    pub fn from_timestamp(&self) -> Option<&str> {
95        self.from_timestamp.as_deref()
96    }
97
98    pub fn set_from_timestamp(&mut self, from_timestamp: impl Into<String>) {
99        self.from_timestamp = Some(from_timestamp.into());
100    }
101
102    pub fn to_timestamp(&self) -> Option<&str> {
103        self.to_timestamp.as_deref()
104    }
105
106    pub fn set_to_timestamp(&mut self, to_timestamp: impl Into<String>) {
107        self.to_timestamp = Some(to_timestamp.into());
108    }
109
110    pub fn similarity_index(&self) -> Option<i32> {
111        self.similarity_index
112    }
113
114    pub fn set_similarity_index(&mut self, similarity_index: Option<i32>) {
115        self.similarity_index = similarity_index;
116    }
117
118    pub fn rename_from(&self) -> Option<&str> {
119        self.rename_from.as_deref()
120    }
121
122    pub fn set_rename_from(&mut self, rename_from: impl Into<String>) {
123        self.rename_from = Some(rename_from.into());
124    }
125
126    pub fn rename_to(&self) -> Option<&str> {
127        self.rename_to.as_deref()
128    }
129
130    pub fn set_rename_to(&mut self, rename_to: impl Into<String>) {
131        self.rename_to = Some(rename_to.into());
132    }
133
134    pub fn copy_from(&self) -> Option<&str> {
135        self.copy_from.as_deref()
136    }
137
138    pub fn set_copy_from(&mut self, copy_from: impl Into<String>) {
139        self.copy_from = Some(copy_from.into());
140    }
141
142    pub fn copy_to(&self) -> Option<&str> {
143        self.copy_to.as_deref()
144    }
145
146    pub fn set_copy_to(&mut self, copy_to: impl Into<String>) {
147        self.copy_to = Some(copy_to.into());
148    }
149
150    pub fn new_file_mode(&self) -> Option<&str> {
151        self.new_file_mode.as_deref()
152    }
153
154    pub fn set_new_file_mode(&mut self, new_file_mode: impl Into<String>) {
155        self.new_file_mode = Some(new_file_mode.into());
156    }
157
158    pub fn deleted_file_mode(&self) -> Option<&str> {
159        self.deleted_file_mode.as_deref()
160    }
161
162    pub fn set_deleted_file_mode(&mut self, deleted_file_mode: impl Into<String>) {
163        self.deleted_file_mode = Some(deleted_file_mode.into());
164    }
165
166    pub fn old_mode(&self) -> Option<&str> {
167        self.old_mode.as_deref()
168    }
169
170    pub fn set_old_mode(&mut self, old_mode: impl Into<String>) {
171        self.old_mode = Some(old_mode.into());
172    }
173
174    pub fn new_mode(&self) -> Option<&str> {
175        self.new_mode.as_deref()
176    }
177
178    pub fn set_new_mode(&mut self, new_mode: impl Into<String>) {
179        self.new_mode = Some(new_mode.into());
180    }
181
182    pub fn binary_added(&self) -> Option<&str> {
183        self.binary_added.as_deref()
184    }
185
186    pub fn set_binary_added(&mut self, binary_added: impl Into<String>) {
187        self.binary_added = Some(binary_added.into());
188    }
189
190    pub fn binary_deleted(&self) -> Option<&str> {
191        self.binary_deleted.as_deref()
192    }
193
194    pub fn set_binary_deleted(&mut self, binary_deleted: impl Into<String>) {
195        self.binary_deleted = Some(binary_deleted.into());
196    }
197
198    pub fn binary_edited(&self) -> Option<&str> {
199        self.binary_edited.as_deref()
200    }
201
202    pub fn set_binary_edited(&mut self, binary_edited: impl Into<String>) {
203        self.binary_edited = Some(binary_edited.into());
204    }
205
206    pub fn is_no_new_line_at_the_end_of_the_file(&self) -> bool {
207        self.no_new_line_at_the_end_of_the_file
208    }
209
210    pub fn set_no_new_line_at_the_end_of_the_file(&mut self, val: bool) {
211        self.no_new_line_at_the_end_of_the_file = val;
212    }
213}