+74
-4
lines changedFilter options
+74
-4
lines changed Original file line number Diff line number Diff line change
@@ -82,6 +82,12 @@ impl ChangeRef<'_, '_> {
82
82
/// Return all shared fields among all variants: `(location, index, entry_mode, id)`
83
83
///
84
84
/// In case of rewrites, the fields return to the current change.
85
+
///
86
+
/// Note that there are also more specific accessors in case you only need to access to one of
87
+
/// these fields individually.
88
+
///
89
+
/// See [`ChangeRef::location()`], [`ChangeRef::index()`], [`ChangeRef::entry_mode()`] and
90
+
/// [`ChangeRef::id()`].
85
91
pub fn fields(&self) -> (&BStr, usize, gix_index::entry::Mode, &gix_hash::oid) {
86
92
match self {
87
93
ChangeRef::Addition {
@@ -114,6 +120,46 @@ impl ChangeRef<'_, '_> {
114
120
} => (location.as_ref(), *index, *entry_mode, id),
115
121
}
116
122
}
123
+
124
+
/// Return the `location`, in the case of rewrites referring to the current change.
125
+
pub fn location(&self) -> &BStr {
126
+
match self {
127
+
ChangeRef::Addition { location, .. }
128
+
| ChangeRef::Deletion { location, .. }
129
+
| ChangeRef::Modification { location, .. }
130
+
| ChangeRef::Rewrite { location, .. } => location.as_ref(),
131
+
}
132
+
}
133
+
134
+
/// Return the `index`, in the case of rewrites referring to the current change.
135
+
pub fn index(&self) -> usize {
136
+
match self {
137
+
ChangeRef::Addition { index, .. }
138
+
| ChangeRef::Deletion { index, .. }
139
+
| ChangeRef::Modification { index, .. }
140
+
| ChangeRef::Rewrite { index, .. } => *index,
141
+
}
142
+
}
143
+
144
+
/// Return the `entry_mode`, in the case of rewrites referring to the current change.
145
+
pub fn entry_mode(&self) -> gix_index::entry::Mode {
146
+
match self {
147
+
ChangeRef::Addition { entry_mode, .. }
148
+
| ChangeRef::Deletion { entry_mode, .. }
149
+
| ChangeRef::Modification { entry_mode, .. }
150
+
| ChangeRef::Rewrite { entry_mode, .. } => *entry_mode,
151
+
}
152
+
}
153
+
154
+
/// Return the `id`, in the case of rewrites referring to the current change.
155
+
pub fn id(&self) -> &gix_hash::oid {
156
+
match self {
157
+
ChangeRef::Addition { id, .. }
158
+
| ChangeRef::Deletion { id, .. }
159
+
| ChangeRef::Modification { id, .. }
160
+
| ChangeRef::Rewrite { id, .. } => id,
161
+
}
162
+
}
117
163
}
118
164
119
165
impl rewrites::tracker::Change for ChangeRef<'_, '_> {
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
1
+
use std::str::FromStr;
2
+
1
3
use gix_diff::{
2
4
index::Change,
3
5
rewrites::{Copies, CopySource},
@@ -313,8 +315,30 @@ fn renames_by_similarity_with_limit() -> crate::Result {
313
315
0,
314
316
"fuzzy tracking is effectively disabled due to limit"
315
317
);
316
-
let actual: Vec<_> = changes.iter().map(|c| c.fields().0).collect();
317
-
assert_eq!(actual, ["f1", "f1-renamed", "f2", "f2-renamed"]);
318
+
319
+
use gix_diff::index::ChangeRef;
320
+
321
+
let actual_locations: Vec<_> = changes.iter().map(ChangeRef::location).collect();
322
+
assert_eq!(actual_locations, ["f1", "f1-renamed", "f2", "f2-renamed"]);
323
+
324
+
let actual_indices: Vec<_> = changes.iter().map(ChangeRef::index).collect();
325
+
assert_eq!(actual_indices, [6, 6, 7, 7]);
326
+
327
+
use gix_index::entry::Mode;
328
+
329
+
let actual_entry_modes: Vec<_> = changes.iter().map(ChangeRef::entry_mode).collect();
330
+
assert_eq!(actual_entry_modes, [Mode::FILE, Mode::FILE, Mode::FILE, Mode::FILE]);
331
+
332
+
let actual_ids: Vec<_> = changes.iter().map(ChangeRef::id).collect();
333
+
assert_eq!(
334
+
actual_ids,
335
+
[
336
+
gix_hash::ObjectId::from_str("f00c965d8307308469e537302baa73048488f162")?,
337
+
gix_hash::ObjectId::from_str("683cfcc0f47566c332aa45d81c5cc98acb4aab49")?,
338
+
gix_hash::ObjectId::from_str("3bb459b831ea471b9cd1cbb7c6d54a74251a711b")?,
339
+
gix_hash::ObjectId::from_str("0a805f8e02d72bd354c1f00607906de2e49e00d6")?,
340
+
]
341
+
);
318
342
319
343
let out = out.expect("tracking enabled");
320
344
assert_eq!(out.num_similarity_checks, 0);
@@ -481,7 +505,7 @@ fn copies_in_entire_tree_by_similarity() -> crate::Result {
481
505
0,
482
506
"needs --find-copies-harder to detect rewrites here"
483
507
);
484
-
let actual: Vec<_> = changes.iter().map(|c| c.fields().0).collect();
508
+
let actual: Vec<_> = changes.iter().map(gix_diff::index::ChangeRef::location).collect();
485
509
assert_eq!(actual, ["b", "c6", "c7", "newly-added"]);
486
510
487
511
let out = out.expect("tracking enabled");
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ impl Item {
135
135
pub fn location(&self) -> &BStr {
136
136
match self {
137
137
Item::IndexWorktree(change) => change.rela_path(),
138
-
Item::TreeIndex(change) => change.fields().0,
138
+
Item::TreeIndex(change) => change.location(),
139
139
}
140
140
}
141
141
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4