Skip to content

Commit

Permalink
Inline store_notes in store_metadata_notes
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 9, 2023
1 parent 92d7475 commit 1778057
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/libcinnabar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::mem::MaybeUninit;
use std::os::raw::{c_char, c_int, c_uint, c_void};
use std::ptr;

use crate::git::GitObjectId;
use crate::git::{GitObjectId, TreeId};
use crate::hg::HgObjectId;
use crate::libgit::{child_process, object_id, strbuf, FileMode, RawTree};
use crate::oid::{Abbrev, ObjectId};
Expand Down Expand Up @@ -207,35 +207,28 @@ pub unsafe extern "C" fn add_files_meta(
}

#[no_mangle]
pub unsafe extern "C" fn store_notes(notes: *mut cinnabar_notes_tree, result: *mut object_id) {
pub unsafe extern "C" fn store_metadata_notes(
notes: *mut cinnabar_notes_tree,
reference: *const object_id,
result: *mut object_id,
) {
*result = object_id::default();
let mut tree = object_id::default();
if notes_dirty(notes) != 0 {
let mode = if ptr::eq(notes, &hg2git.0) {
FileMode::GITLINK
} else {
FileMode::REGULAR | FileMode::RW
};
cinnabar_write_notes_tree(notes, result, u16::from(mode).into());
cinnabar_write_notes_tree(notes, &mut tree, u16::from(mode).into());
}
}

#[no_mangle]
pub unsafe extern "C" fn store_metadata_notes(
notes: *mut cinnabar_notes_tree,
reference: *const object_id,
result: *mut object_id,
) {
*result = object_id::default();
let mut tree = object_id::default();
store_notes(notes, &mut tree);

if GitObjectId::from(tree.clone()).is_null() {
let mut tree = TreeId::from_unchecked(GitObjectId::from(tree));
if tree.is_null() {
*result = reference.as_ref().unwrap().clone();
if GitObjectId::from(result.as_ref().unwrap().clone()).is_null() {
tree = RawTree::EMPTY_OID.into();
tree = RawTree::EMPTY_OID;
}
}
let tree = GitObjectId::from(tree);
if !tree.is_null() {
let mut buf = strbuf::new();
writeln!(buf, "tree {}", tree).ok();
Expand Down

0 comments on commit 1778057

Please sign in to comment.