Skip to content

Commit 810b018

Browse files
committed
Cleanup FileStatus
1 parent 94bd5bd commit 810b018

File tree

3 files changed

+56
-47
lines changed

3 files changed

+56
-47
lines changed

src/git/commit_diff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ mod tests {
109109
let diff = CommitDiffBuilder::new(CommitBuilder::new("0123456789ABCDEF").build())
110110
.file_statuses(file_statuses)
111111
.build();
112-
assert_eq!(diff.file_statuses()[0].source_path.to_string_lossy(), "foo");
112+
assert_eq!(diff.file_statuses()[0].source_path().to_string_lossy(), "foo");
113113
}
114114

115115
#[test]

src/git/file_status.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ use crate::git::{Delta, FileMode, Status};
55
/// Represents a file change within a Git repository
66
#[derive(Debug, Clone, PartialEq, Eq)]
77
pub(crate) struct FileStatus {
8-
pub(crate) deltas: Vec<Delta>,
9-
pub(crate) destination_is_binary: bool,
10-
pub(crate) destination_mode: FileMode,
11-
pub(crate) destination_path: PathBuf,
12-
pub(crate) largest_new_line_number: u32,
13-
pub(crate) largest_old_line_number: u32,
14-
pub(crate) source_is_binary: bool,
15-
pub(crate) source_mode: FileMode,
16-
pub(crate) source_path: PathBuf,
17-
pub(crate) status: Status,
8+
deltas: Vec<Delta>,
9+
destination_is_binary: bool,
10+
destination_mode: FileMode,
11+
destination_path: PathBuf,
12+
largest_new_line_number: u32,
13+
largest_old_line_number: u32,
14+
source_is_binary: bool,
15+
source_mode: FileMode,
16+
source_path: PathBuf,
17+
status: Status,
1818
}
1919

2020
impl FileStatus {
@@ -70,12 +70,14 @@ impl FileStatus {
7070

7171
/// Get the destination file mode for this change.
7272
#[must_use]
73+
#[allow(dead_code)]
7374
pub(crate) const fn destination_mode(&self) -> FileMode {
7475
self.destination_mode
7576
}
7677

7778
/// Is the destination file a binary file.
7879
#[must_use]
80+
#[allow(dead_code)]
7981
pub(crate) const fn destination_is_binary(&self) -> bool {
8082
self.destination_is_binary
8183
}
@@ -88,12 +90,14 @@ impl FileStatus {
8890

8991
/// Get the source file mode for this change.
9092
#[must_use]
93+
#[allow(dead_code)]
9194
pub(crate) const fn source_mode(&self) -> FileMode {
9295
self.source_mode
9396
}
9497

9598
/// Is the source file a binary file.
9699
#[must_use]
100+
#[allow(dead_code)]
97101
pub(crate) const fn source_is_binary(&self) -> bool {
98102
self.source_is_binary
99103
}

src/test_helpers/builders/file_status.rs

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,103 +5,108 @@ use crate::git::{Delta, FileMode, FileStatus, Status};
55
/// Builder for creating a new reference.
66
#[derive(Debug)]
77
pub(crate) struct FileStatusBuilder {
8-
file_status: FileStatus,
8+
deltas: Vec<Delta>,
9+
destination_is_binary: bool,
10+
destination_mode: FileMode,
11+
destination_path: PathBuf,
12+
source_is_binary: bool,
13+
source_mode: FileMode,
14+
source_path: PathBuf,
15+
status: Status,
916
}
1017

1118
impl FileStatusBuilder {
1219
/// Create a new instance of the builder. The new instance will default to an empty file status.
1320
#[must_use]
1421
pub(crate) fn new() -> Self {
1522
Self {
16-
file_status: FileStatus {
17-
deltas: vec![],
18-
destination_is_binary: false,
19-
destination_mode: FileMode::Normal,
20-
destination_path: PathBuf::default(),
21-
largest_new_line_number: 0,
22-
largest_old_line_number: 0,
23-
source_is_binary: false,
24-
source_mode: FileMode::Normal,
25-
source_path: PathBuf::default(),
26-
status: Status::Added,
27-
},
23+
deltas: vec![],
24+
destination_is_binary: false,
25+
destination_mode: FileMode::Normal,
26+
destination_path: PathBuf::default(),
27+
source_is_binary: false,
28+
source_mode: FileMode::Normal,
29+
source_path: PathBuf::default(),
30+
status: Status::Added,
2831
}
2932
}
3033

3134
/// Push a `Delta`.
3235
#[must_use]
3336
pub(crate) fn push_delta(mut self, delta: Delta) -> Self {
34-
self.file_status.add_delta(delta);
37+
self.deltas.push(delta);
3538
self
3639
}
3740

3841
/// Set if the destination is binary.
3942
#[must_use]
43+
#[allow(dead_code)]
4044
pub(crate) const fn destination_is_binary(mut self, binary: bool) -> Self {
41-
self.file_status.destination_is_binary = binary;
45+
self.destination_is_binary = binary;
4246
self
4347
}
4448

4549
/// Set the destination file mode.
4650
#[must_use]
4751
pub(crate) const fn destination_mode(mut self, mode: FileMode) -> Self {
48-
self.file_status.destination_mode = mode;
52+
self.destination_mode = mode;
4953
self
5054
}
5155

5256
/// Set the destination file path.
5357
#[must_use]
5458
pub(crate) fn destination_path<F: AsRef<Path>>(mut self, path: F) -> Self {
55-
self.file_status.destination_path = PathBuf::from(path.as_ref());
56-
self
57-
}
58-
59-
/// Set the largest new line number.
60-
#[must_use]
61-
pub(crate) const fn largest_new_line_number(mut self, largest_new_line_number: u32) -> Self {
62-
self.file_status.largest_new_line_number = largest_new_line_number;
63-
self
64-
}
65-
66-
/// Set the largest old line number.
67-
#[must_use]
68-
pub(crate) const fn largest_old_line_number(mut self, largest_old_line_number: u32) -> Self {
69-
self.file_status.largest_old_line_number = largest_old_line_number;
59+
self.destination_path = PathBuf::from(path.as_ref());
7060
self
7161
}
7262

7363
/// Set if the source is binary.
7464
#[must_use]
65+
#[allow(dead_code)]
7566
pub(crate) const fn source_is_binary(mut self, binary: bool) -> Self {
76-
self.file_status.source_is_binary = binary;
67+
self.source_is_binary = binary;
7768
self
7869
}
7970

8071
/// Set if the source file mode.
8172
#[must_use]
73+
#[allow(dead_code)]
8274
pub(crate) const fn source_mode(mut self, mode: FileMode) -> Self {
83-
self.file_status.source_mode = mode;
75+
self.source_mode = mode;
8476
self
8577
}
8678

8779
/// Set the destination file path.
8880
#[must_use]
8981
pub(crate) fn source_path<F: AsRef<Path>>(mut self, path: F) -> Self {
90-
self.file_status.source_path = PathBuf::from(path.as_ref());
82+
self.source_path = PathBuf::from(path.as_ref());
9183
self
9284
}
9385

9486
/// Set the status.
9587
#[must_use]
9688
pub(crate) const fn status(mut self, status: Status) -> Self {
97-
self.file_status.status = status;
89+
self.status = status;
9890
self
9991
}
10092

10193
/// Build the `FileStatus`
10294
#[must_use]
10395
#[allow(clippy::missing_const_for_fn)]
10496
pub(crate) fn build(self) -> FileStatus {
105-
self.file_status
97+
let mut file_status = FileStatus::new(
98+
self.source_path,
99+
self.source_mode,
100+
self.source_is_binary,
101+
self.destination_path,
102+
self.destination_mode,
103+
self.destination_is_binary,
104+
self.status,
105+
);
106+
for delta in self.deltas {
107+
file_status.add_delta(delta);
108+
}
109+
110+
file_status
106111
}
107112
}

0 commit comments

Comments
 (0)