Skip to content

Commit 39f46c5

Browse files
committed
feat: entry::Stage can now be converted into entry::Flags.
This makes it easier to change the stage of an entry.
1 parent 465e4b1 commit 39f46c5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

gix-index/src/entry/flags.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ bitflags! {
6060
}
6161

6262
impl Flags {
63+
/// Create a new instance whose stage is set to `stage`.
64+
pub fn from_stage(stage: Stage) -> Self {
65+
Flags::from_bits((stage as u32) << 12).expect("stage can only be valid flags")
66+
}
67+
6368
/// Return the stage as extracted from the bits of this instance.
6469
pub fn stage(&self) -> Stage {
6570
match self.stage_raw() {
@@ -96,6 +101,12 @@ impl Flags {
96101
}
97102
}
98103

104+
impl From<Stage> for Flags {
105+
fn from(value: Stage) -> Self {
106+
Flags::from_stage(value)
107+
}
108+
}
109+
99110
pub(crate) mod at_rest {
100111
use bitflags::bitflags;
101112

gix-index/tests/index/entry/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
mod flags {
2+
use gix_index::entry::{Flags, Stage};
3+
4+
#[test]
5+
fn from_stage() {
6+
for stage in [Stage::Unconflicted, Stage::Base, Stage::Ours, Stage::Theirs] {
7+
let actual = Flags::from_stage(stage);
8+
assert_eq!(actual.stage(), stage);
9+
let actual: Flags = stage.into();
10+
assert_eq!(actual.stage(), stage);
11+
}
12+
}
13+
}
114
mod mode;
215
mod stat;
316
mod time;

0 commit comments

Comments
 (0)