Skip to content

Commit 0a7776b

Browse files
committed
refactor!: Make describe::Format more consistent with other builder APIs (#298)
Configuration methods now take an argument which makes it more straightforward to use for most.
1 parent 654f4af commit 0a7776b

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

Diff for: git-revision/src/describe.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,10 @@ impl<'a> Format<'a> {
6464

6565
/// Set this instance to print in long mode, that is if `depth` is 0, it will still print the whole
6666
/// long form even though it's not quite necessary.
67-
pub fn long(&mut self) -> &mut Self {
68-
self.long = true;
69-
self
70-
}
71-
72-
/// This is set by default, and causes the describe string to be shortened `id` lies directly on `name`.
73-
pub fn short(&mut self) -> &mut Self {
74-
self.long = false;
67+
///
68+
/// Otherwise, it is allowed to shorten itself.
69+
pub fn long(&mut self, long: bool) -> &mut Self {
70+
self.long = long;
7571
self
7672
}
7773
}

Diff for: git-revision/tests/describe/format.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ fn exact_match_with_dirty_and_long() {
1515
.into_format(7);
1616
assert!(format.is_exact_match());
1717
assert_eq!(format.to_string(), "main");
18-
assert_eq!(format.long().to_string(), "main-0-gb920bbb");
18+
assert_eq!(format.long(true).to_string(), "main-0-gb920bbb");
1919

2020
format.dirty_suffix = Some("dirty".into());
21-
assert_eq!(format.short().to_string(), "main-dirty");
22-
assert_eq!(format.long().to_string(), "main-0-gb920bbb-dirty");
21+
assert_eq!(format.long(false).to_string(), "main-dirty");
22+
assert_eq!(format.long(true).to_string(), "main-0-gb920bbb-dirty");
2323

2424
format.dirty_suffix = None;
2525
format.depth = 42;
2626
assert!(!format.is_exact_match());
27-
assert_eq!(format.short().to_string(), "main-42-gb920bbb");
27+
assert_eq!(format.long(false).to_string(), "main-42-gb920bbb");
2828

2929
format.dirty_suffix = Some("dirty".into());
3030
assert_eq!(format.to_string(), "main-42-gb920bbb-dirty");
31-
assert_eq!(format.long().to_string(), "main-42-gb920bbb-dirty");
31+
assert_eq!(format.long(true).to_string(), "main-42-gb920bbb-dirty");
3232
}
3333

3434
#[test]
@@ -44,10 +44,10 @@ fn show_abbrev_hash_if_no_name_is_known() {
4444
format.is_exact_match(),
4545
"it reports true as it is only dependent on the depth which plays no role here"
4646
);
47-
assert_eq!(format.short().to_string(), "b920bbb");
48-
assert_eq!(format.long().to_string(), "b920bbb");
47+
assert_eq!(format.long(false).to_string(), "b920bbb");
48+
assert_eq!(format.long(true).to_string(), "b920bbb");
4949

5050
format.dirty_suffix = Some("dirty".into());
51-
assert_eq!(format.short().to_string(), "b920bbb-dirty");
52-
assert_eq!(format.long().to_string(), "b920bbb-dirty");
51+
assert_eq!(format.long(false).to_string(), "b920bbb-dirty");
52+
assert_eq!(format.long(true).to_string(), "b920bbb-dirty");
5353
}

0 commit comments

Comments
 (0)