Skip to content

Commit

Permalink
Inline-ish notes_initialized on the Rust side
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 10, 2023
1 parent 1ea9528 commit bf45065
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/cinnabar-notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const struct object_id *get_abbrev_note(struct cinnabar_notes_tree *t,
struct leaf_node *found;

assert(t);
assert(notes_initialized(t));
assert(t->current.initialized);
found = note_tree_abbrev_find(&t->current, t->current.root, 0,
object_oid->hash, len);
if (!found)
Expand All @@ -109,11 +109,6 @@ const struct object_id *get_abbrev_note(struct cinnabar_notes_tree *t,
return found ? &found->val_oid : NULL;
}

int notes_initialized(struct cinnabar_notes_tree *notes)
{
return notes->current.initialized;
}

int notes_dirty(struct cinnabar_notes_tree *notes)
{
return notes->current.dirty || notes->additions.dirty;
Expand Down
2 changes: 0 additions & 2 deletions src/cinnabar-notes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ struct cinnabar_notes_tree {
#define for_each_note cinnabar_for_each_note
#define write_notes_tree cinnabar_write_notes_tree

int notes_initialized(struct notes_tree *notes);

int notes_dirty(struct notes_tree *notes);

extern const struct object_id *get_abbrev_note(
Expand Down
7 changes: 3 additions & 4 deletions src/libcinnabar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub struct cinnabar_notes_tree {
impl Drop for cinnabar_notes_tree {
fn drop(&mut self) {
unsafe {
if notes_initialized(self) != 0 {
if self.current.initialized() {
free_notes(&mut self.current);
free_notes(&mut self.additions);
}
Expand Down Expand Up @@ -176,7 +176,6 @@ extern "C" {

fn cinnabar_remove_note(notes: *mut cinnabar_notes_tree, object_sha1: *const u8);

fn notes_initialized(notes: *const cinnabar_notes_tree) -> c_int;
fn notes_dirty(notes: *const cinnabar_notes_tree) -> c_int;

fn cinnabar_write_notes_tree(
Expand All @@ -189,7 +188,8 @@ extern "C" {
const NOTES_INIT_EMPTY: c_int = 1;

unsafe fn ensure_notes(t: *mut cinnabar_notes_tree) {
if notes_initialized(t) == 0 {
let t = t.as_mut().unwrap();
if !t.current.initialized() {
let oid;
let mut flags = 0;
if ptr::eq(t, &GIT2HG.0) {
Expand All @@ -209,7 +209,6 @@ unsafe fn ensure_notes(t: *mut cinnabar_notes_tree) {
flags = NOTES_INIT_EMPTY;
}
let oid = CString::new(oid.to_string()).unwrap();
let t = t.as_mut().unwrap();
init_notes(&mut t.current, oid.as_ptr(), combine_notes_ignore, flags);
init_notes(
&mut t.additions,
Expand Down
4 changes: 4 additions & 0 deletions src/libgit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,4 +1285,8 @@ impl notes_tree {
dirty: 0,
}
}

pub const fn initialized(&self) -> bool {
self.initialized != 0
}
}

0 comments on commit bf45065

Please sign in to comment.