diff --git a/src/libcinnabar.rs b/src/libcinnabar.rs index 25dd2bc75..72900758e 100644 --- a/src/libcinnabar.rs +++ b/src/libcinnabar.rs @@ -16,7 +16,7 @@ use crate::libgit::{ HG2GIT_OID, }; use crate::oid::{Abbrev, ObjectId}; -use crate::store::{store_git_commit, FILES_META, METADATA_FLAGS}; +use crate::store::{store_git_commit, MetadataFlags, METADATA_FLAGS}; #[allow(non_camel_case_types)] #[derive(Clone, Debug)] @@ -174,7 +174,7 @@ unsafe fn ensure_notes(t: *mut cinnabar_notes_tree) { oid = HG2GIT_OID; } else if ptr::eq(t, &files_meta.0) { oid = FILES_META_OID; - if METADATA_FLAGS & FILES_META == 0 { + if METADATA_FLAGS.contains(MetadataFlags::FILES_META) { flags = NOTES_INIT_EMPTY; } } else { diff --git a/src/main.rs b/src/main.rs index 05d9b0a54..c0b0ac637 100644 --- a/src/main.rs +++ b/src/main.rs @@ -260,7 +260,7 @@ fn do_done_and_check(args: &[&[u8]]) -> bool { do_cleanup(0); set_metadata_to( Some(new_metadata), - MetadataFlags::FORCE | MetadataFlags::KEEP_REFS, + SetMetadataFlags::FORCE | SetMetadataFlags::KEEP_REFS, "update", ) .unwrap(); @@ -652,7 +652,7 @@ fn get_previous_metadata(metadata: CommitId) -> Option { bitflags! { #[derive(Debug)] - pub struct MetadataFlags: i32 { + pub struct SetMetadataFlags: i32 { const FORCE = 0x1; const KEEP_REFS = 0x2; } @@ -660,12 +660,12 @@ bitflags! { fn set_metadata_to( new_metadata: Option, - flags: MetadataFlags, + flags: SetMetadataFlags, msg: &str, ) -> Result, String> { let mut refs = HashMap::new(); for_each_ref_in(REFS_PREFIX, |r, oid| { - if flags.contains(MetadataFlags::KEEP_REFS) + if flags.contains(SetMetadataFlags::KEEP_REFS) && (r.as_bytes().starts_with_str("refs/") || r.as_bytes().starts_with_str("hg/") || r == "HEAD") @@ -724,7 +724,7 @@ fn set_metadata_to( let mut m = metadata; let found = flags - .contains(MetadataFlags::FORCE) + .contains(SetMetadataFlags::FORCE) .then(|| { state = MetadataState::Unknown; new @@ -1526,9 +1526,9 @@ fn do_rollback( return Err("Nothing to rollback.".to_string()); }; let flags = if force { - MetadataFlags::FORCE + SetMetadataFlags::FORCE } else { - MetadataFlags::empty() + SetMetadataFlags::empty() }; set_metadata_to(wanted_metadata, flags, "rollback").map(|_| ()) } diff --git a/src/store.rs b/src/store.rs index 6ecf787e3..1de99dd91 100644 --- a/src/store.rs +++ b/src/store.rs @@ -16,6 +16,7 @@ use std::rc::Rc; use std::sync::Mutex; use bit_vec::BitVec; +use bitflags::bitflags; use bstr::{BStr, BString, ByteSlice}; use derive_more::Deref; use either::Either; @@ -65,13 +66,18 @@ pub const CHECKED_REF: &str = "refs/cinnabar/checked"; pub const BROKEN_REF: &str = "refs/cinnabar/broken"; pub const NOTES_REF: &str = "refs/notes/cinnabar"; -pub static mut METADATA_FLAGS: c_int = 0; +bitflags! { + #[derive(Debug, Copy, Clone)] + pub struct MetadataFlags: i32 { + const FILES_META = 0x1; + const UNIFIED_MANIFESTS_V2 = 0x2; -pub const FILES_META: c_int = 0x1; -pub const UNIFIED_MANIFESTS_V2: c_int = 0x2; + } +} +pub static mut METADATA_FLAGS: MetadataFlags = MetadataFlags::empty(); pub fn has_metadata() -> bool { - unsafe { METADATA_FLAGS != 0 } + unsafe { !METADATA_FLAGS.is_empty() } } macro_rules! hg2git { @@ -2098,16 +2104,19 @@ pub unsafe extern "C" fn init_metadata(c: *const commit) { for flag in c.body().split(|&b| b == b' ') { match flag { b"files-meta" => { - METADATA_FLAGS |= FILES_META; + METADATA_FLAGS.insert(MetadataFlags::FILES_META); } b"unified-manifests" => old_metadata(), b"unified-manifests-v2" => { - METADATA_FLAGS |= UNIFIED_MANIFESTS_V2; + METADATA_FLAGS.insert(MetadataFlags::UNIFIED_MANIFESTS_V2); } _ => new_metadata(), } } - if METADATA_FLAGS != FILES_META | UNIFIED_MANIFESTS_V2 { + if !METADATA_FLAGS + .difference(MetadataFlags::FILES_META | MetadataFlags::UNIFIED_MANIFESTS_V2) + .is_empty() + { old_metadata(); } let mut count = 0;