Skip to content

Commit

Permalink
Move metadata_flags to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 10, 2023
1 parent 79a0406 commit 59723b1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/cinnabar-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ struct notes_tree git2hg, hg2git, files_meta;
struct object_id metadata_oid, changesets_oid, manifests_oid, git2hg_oid,
hg2git_oid, files_meta_oid;

int metadata_flags = 0;

struct object_id *commit_oid(struct commit *c) {
return &c->object.oid;
}
Expand Down Expand Up @@ -491,7 +489,6 @@ void do_reload(struct object_id *oid)

dump_ref_updates();

metadata_flags = 0;
reset_replace_map();
if (oid) {
if (!is_null_oid(oid)) {
Expand Down
5 changes: 0 additions & 5 deletions src/cinnabar-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
extern struct object_id metadata_oid, changesets_oid, manifests_oid, git2hg_oid,
hg2git_oid, files_meta_oid;

#define FILES_META 0x1
#define UNIFIED_MANIFESTS_v2 0x2

extern int metadata_flags;

#define CHECK_HELPER 0x1
#define CHECK_MANIFESTS 0x2

Expand Down
4 changes: 2 additions & 2 deletions src/libcinnabar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::libgit::{
RawTree,
};
use crate::oid::{Abbrev, ObjectId};
use crate::store::{metadata_flags, store_git_commit, FILES_META};
use crate::store::{store_git_commit, FILES_META, METADATA_FLAGS};

#[allow(non_camel_case_types)]
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -176,7 +176,7 @@ unsafe fn ensure_notes(t: *mut cinnabar_notes_tree) {
oid = hg2git_oid.clone();
} else if ptr::eq(t, &files_meta.0) {
oid = files_meta_oid.clone();
if metadata_flags & FILES_META == 0 {
if METADATA_FLAGS & FILES_META == 0 {
flags = NOTES_INIT_EMPTY;
}
} else {
Expand Down
12 changes: 5 additions & 7 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,13 @@ pub const CHECKED_REF: &str = "refs/cinnabar/checked";
pub const BROKEN_REF: &str = "refs/cinnabar/broken";
pub const NOTES_REF: &str = "refs/notes/cinnabar";

extern "C" {
pub static mut metadata_flags: c_int;
}
pub static mut METADATA_FLAGS: c_int = 0;

pub const FILES_META: c_int = 0x1;
pub const UNIFIED_MANIFESTS_V2: c_int = 0x2;

pub fn has_metadata() -> bool {
unsafe { metadata_flags != 0 }
unsafe { METADATA_FLAGS != 0 }
}

macro_rules! hg2git {
Expand Down Expand Up @@ -2092,16 +2090,16 @@ 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 |= FILES_META;
}
b"unified-manifests" => old_metadata(),
b"unified-manifests-v2" => {
metadata_flags |= UNIFIED_MANIFESTS_V2;
METADATA_FLAGS |= UNIFIED_MANIFESTS_V2;
}
_ => new_metadata(),
}
}
if metadata_flags != FILES_META | UNIFIED_MANIFESTS_V2 {
if METADATA_FLAGS != FILES_META | UNIFIED_MANIFESTS_V2 {
old_metadata();
}
let mut count = 0;
Expand Down

0 comments on commit 59723b1

Please sign in to comment.