diff --git a/src/libcinnabar.rs b/src/libcinnabar.rs index 43e630ed3..ef519768a 100644 --- a/src/libcinnabar.rs +++ b/src/libcinnabar.rs @@ -171,11 +171,11 @@ unsafe fn ensure_notes(t: *mut cinnabar_notes_tree) { let oid; let mut flags = 0; if ptr::eq(t, &git2hg.0) { - oid = GIT2HG_OID.clone(); + oid = GIT2HG_OID; } else if ptr::eq(t, &hg2git.0) { - oid = HG2GIT_OID.clone(); + oid = HG2GIT_OID; } else if ptr::eq(t, &files_meta.0) { - oid = FILES_META_OID.clone(); + oid = FILES_META_OID; if METADATA_FLAGS & FILES_META == 0 { flags = NOTES_INIT_EMPTY; } @@ -260,7 +260,7 @@ pub unsafe extern "C" fn add_files_meta( pub unsafe fn store_metadata_notes( notes: *mut cinnabar_notes_tree, - reference: *const object_id, + reference: CommitId, ) -> CommitId { let mut result = object_id::default(); let mut tree = object_id::default(); @@ -274,7 +274,7 @@ pub unsafe fn store_metadata_notes( } let mut tree = TreeId::from_unchecked(GitObjectId::from(tree)); if tree.is_null() { - result = reference.as_ref().unwrap().clone(); + result = reference.into(); if GitObjectId::from(result.clone()).is_null() { tree = RawTree::EMPTY_OID; } diff --git a/src/libgit.rs b/src/libgit.rs index 35b8df791..f4981c8a1 100644 --- a/src/libgit.rs +++ b/src/libgit.rs @@ -62,12 +62,12 @@ impl From for GitObjectId { } } -pub static mut METADATA_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); -pub static mut CHANGESETS_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); -pub static mut MANIFESTS_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); -pub static mut GIT2HG_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); -pub static mut HG2GIT_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); -pub static mut FILES_META_OID: object_id = object_id([0; GIT_MAX_RAWSZ], GIT_HASH_SHA1); +pub static mut METADATA_OID: CommitId = CommitId::NULL; +pub static mut CHANGESETS_OID: CommitId = CommitId::NULL; +pub static mut MANIFESTS_OID: CommitId = CommitId::NULL; +pub static mut GIT2HG_OID: CommitId = CommitId::NULL; +pub static mut HG2GIT_OID: CommitId = CommitId::NULL; +pub static mut FILES_META_OID: CommitId = CommitId::NULL; #[allow(non_camel_case_types)] #[repr(C)] diff --git a/src/main.rs b/src/main.rs index 59fdefb5b..98cbffd41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -941,9 +941,9 @@ fn do_reclone(rebase: bool) -> Result<(), String> { } } - let old_changesets_oid = GitObjectId::from(unsafe { libgit::CHANGESETS_OID.clone() }); + let old_changesets_oid = unsafe { libgit::CHANGESETS_OID }; let mut old_git2hg = { - let git2hg_oid = GitObjectId::from(unsafe { libgit::GIT2HG_OID.clone() }); + let git2hg_oid = unsafe { libgit::GIT2HG_OID }; if git2hg_oid.is_null() { None } else { @@ -953,9 +953,9 @@ fn do_reclone(rebase: bool) -> Result<(), String> { }; let current_metadata_oid = unsafe { - let current_metadata_oid = METADATA_OID.clone(); + let current_metadata_oid = METADATA_OID; do_reload(&object_id::default()); - METADATA_OID = current_metadata_oid.clone(); + METADATA_OID = current_metadata_oid; current_metadata_oid }; @@ -1078,7 +1078,6 @@ fn do_reclone(rebase: bool) -> Result<(), String> { .and_then(|()| { // If all the changesets we had in store weren't pulled from the remotes // above, try fetching them from skip-default-update remotes. - let old_changesets_oid = CommitId::from_unchecked(old_changesets_oid); if old_changesets_oid.is_null() { return Ok(()); } @@ -2330,7 +2329,7 @@ fn do_fsck(force: bool, full: bool, commits: Vec) -> Result bool { transaction .update( BROKEN_REF, - unsafe { - CommitId::from_unchecked(GitObjectId::from(crate::libgit::METADATA_OID.clone())) - }, + unsafe { crate::libgit::METADATA_OID }, None, "post-pull check", ) @@ -2070,12 +2068,12 @@ pub unsafe extern "C" fn init_metadata(c: *const commit) { let cid = if let Some(c) = c.as_ref() { CommitId::from_unchecked(GitObjectId::from(commit_oid(c).as_ref().unwrap().clone())) } else { - METADATA_OID = object_id::default(); - CHANGESETS_OID = object_id::default(); - MANIFESTS_OID = object_id::default(); - HG2GIT_OID = object_id::default(); - GIT2HG_OID = object_id::default(); - FILES_META_OID = object_id::default(); + METADATA_OID = CommitId::NULL; + CHANGESETS_OID = CommitId::NULL; + MANIFESTS_OID = CommitId::NULL; + HG2GIT_OID = CommitId::NULL; + GIT2HG_OID = CommitId::NULL; + FILES_META_OID = CommitId::NULL; return; }; let c = RawCommit::read(cid).unwrap(); @@ -2091,7 +2089,7 @@ pub unsafe extern "C" fn init_metadata(c: *const commit) { &mut GIT2HG_OID, &mut FILES_META_OID, ]) { - *field = (*cid).into(); + *field = *cid; } for flag in c.body().split(|&b| b == b' ') { match flag { @@ -2177,15 +2175,13 @@ pub fn do_store_metadata() -> CommitId { let mut tree = object_id::default(); let mut previous = None; unsafe { - hg2git_ = store_metadata_notes(&mut *hg2git, &HG2GIT_OID); - git2hg_ = store_metadata_notes(&mut *git2hg, &GIT2HG_OID); - files_meta_ = store_metadata_notes(&mut *files_meta, &FILES_META_OID); + hg2git_ = store_metadata_notes(&mut *hg2git, HG2GIT_OID); + git2hg_ = store_metadata_notes(&mut *git2hg, GIT2HG_OID); + files_meta_ = store_metadata_notes(&mut *files_meta, FILES_META_OID); manifests = store_manifests_metadata(); changesets = store_changesets_metadata(); - if !GitObjectId::from(METADATA_OID.clone()).is_null() { - previous = Some(CommitId::from_unchecked(GitObjectId::from( - METADATA_OID.clone(), - ))); + if !METADATA_OID.is_null() { + previous = Some(METADATA_OID); } store_replace_map(&mut tree); }