Skip to content

Commit

Permalink
Make store_git_{commit,tree,blob} take a strslice instead of strbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Nov 12, 2023
1 parent 199d9df commit 5bc786a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 31 deletions.
16 changes: 7 additions & 9 deletions src/cinnabar-fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void store_replace_map(struct object_id *result) {
strbuf_release(&buf);
}

void store_git_tree(struct strbuf *tree_buf, const struct object_id *reference,
void store_git_tree(struct strslice tree_buf, const struct object_id *reference,
struct object_id *result)
{
struct object_entry *oe = NULL;
Expand All @@ -625,23 +625,21 @@ void store_git_tree(struct strbuf *tree_buf, const struct object_id *reference,
unsigned long len;
ref_tree.buf = gfi_unpack_entry(oe, &len);
ref_tree.len = len;
store_git_object(OBJ_TREE, strbuf_as_slice(tree_buf), result,
&ref_tree, oe);
store_git_object(OBJ_TREE, tree_buf, result, &ref_tree, oe);
free((char*)ref_tree.buf);
} else {
store_git_object(OBJ_TREE, strbuf_as_slice(tree_buf), result,
NULL, NULL);
store_git_object(OBJ_TREE, tree_buf, result, NULL, NULL);
}
}

void store_git_blob(struct strbuf *blob_buf, struct object_id *result)
void store_git_blob(struct strslice blob_buf, struct object_id *result)
{
store_git_object(OBJ_BLOB, strbuf_as_slice(blob_buf), result, NULL, NULL);
store_git_object(OBJ_BLOB, blob_buf, result, NULL, NULL);
}

void store_git_commit(struct strbuf *commit_buf, struct object_id *result)
void store_git_commit(struct strslice commit_buf, struct object_id *result)
{
store_git_object(OBJ_COMMIT, strbuf_as_slice(commit_buf), result, NULL, NULL);
store_git_object(OBJ_COMMIT, commit_buf, result, NULL, NULL);
}

void store_git_object(enum object_type type, const struct strslice buf,
Expand Down
6 changes: 3 additions & 3 deletions src/cinnabar-fast-import.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ int maybe_handle_command(struct reader *helper_input, int helper_output,

struct object_entry *get_object_entry(const struct object_id *oid);

void store_git_tree(struct strbuf *tree_buf,
void store_git_tree(struct strslice tree_buf,
const struct object_id *reference,
struct object_id *result);

void store_git_commit(struct strbuf *commit_buf, struct object_id *result);
void store_git_commit(struct strslice commit_buf, struct object_id *result);

void store_git_blob(struct strbuf *blob_buf, struct object_id *result);
void store_git_blob(struct strslice blob_buf, struct object_id *result);

void store_git_object(enum object_type type, const struct strslice buf,
struct object_id *result, const struct strslice *reference,
Expand Down
3 changes: 2 additions & 1 deletion src/cinnabar-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ static void recurse_create_git_tree(const struct object_id *tree_id,
cache_entry->ent = k.ent;
cache_entry->old_oid = k.old_oid;
}
store_git_tree(&tree_buf, reference, cache_entry ? &cache_entry->new_oid : result);
store_git_tree(strbuf_as_slice(&tree_buf), reference,
cache_entry ? &cache_entry->new_oid : result);
strbuf_release(&tree_buf);
if (!merge_tree_id) {
hashmap_add(cache, &cache_entry->ent);
Expand Down
2 changes: 1 addition & 1 deletion src/libcinnabar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ pub fn store_metadata_notes(notes: &mut cinnabar_notes_tree, reference: CommitId
b"author <cinnabar@git> 0 +0000\ncommitter <cinnabar@git> 0 +0000\n\n",
);
unsafe {
store_git_commit(&buf, &mut result);
store_git_commit(buf.as_bytes().into(), &mut result);
}
}
CommitId::from_unchecked(result.into())
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ fn do_reclone(rebase: bool) -> Result<(), String> {
buf.extend_from_slice(commit.body());
let mut new_oid = object_id::default();
unsafe {
store::store_git_commit(&buf, &mut new_oid);
store::store_git_commit(buf.as_bytes().into(), &mut new_oid);
}
let new_cid = CommitId::from_unchecked(new_oid.into());
assert!(rewritten.insert(cid, Some(new_cid)).is_none());
Expand Down Expand Up @@ -1916,7 +1916,7 @@ fn create_copy(blobid: BlobId, source_path: &BStr, source_fid: HgFileId) -> HgFi

let mut oid = object_id::default();
unsafe {
store_git_blob(&metadata, &mut oid);
store_git_blob(metadata.as_bytes().into(), &mut oid);
METADATA.set(SetWhat::FileMeta, fid.into(), oid.into());
METADATA.set(SetWhat::File, fid.into(), blobid.into());
}
Expand Down Expand Up @@ -2962,7 +2962,7 @@ fn do_fsck_full(
let mut metadata_id = object_id::default();
let mut buf = strbuf::new();
buf.extend_from_slice(&fresh_metadata.serialize());
store_git_blob(&buf, &mut metadata_id);
store_git_blob(buf.as_bytes().into(), &mut metadata_id);
METADATA.set(
SetWhat::ChangesetMeta,
changeset_id.into(),
Expand Down
28 changes: 14 additions & 14 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ fn store_changesets_metadata(metadata: &Metadata) -> CommitId {
}
let mut tid = object_id::default();
unsafe {
store_git_tree(&tree, std::ptr::null(), &mut tid);
store_git_tree(tree.as_bytes().into(), std::ptr::null(), &mut tid);
}
drop(tree);
let mut commit = strbuf::new();
Expand All @@ -1164,7 +1164,7 @@ fn store_changesets_metadata(metadata: &Metadata) -> CommitId {
}
let mut result = object_id::default();
unsafe {
store_git_commit(&commit, &mut result);
store_git_commit(commit.as_bytes().into(), &mut result);
}
CommitId::from_unchecked(result.into())
}
Expand All @@ -1180,7 +1180,7 @@ fn store_manifests_metadata(metadata: &Metadata) -> CommitId {
writeln!(commit, "committer <cinnabar@git> 0 +0000\n").ok();
let mut result = object_id::default();
unsafe {
store_git_commit(&commit, &mut result);
store_git_commit(commit.as_bytes().into(), &mut result);
}
CommitId::from_unchecked(result.into())
}
Expand All @@ -1205,9 +1205,9 @@ pub fn set_changeset_heads(metadata: &mut Metadata, new_heads: ChangesetHeads) {

extern "C" {
pub fn ensure_store_init();
pub fn store_git_blob(blob_buf: *const strbuf, result: *mut object_id);
fn store_git_tree(tree_buf: *const strbuf, reference: *const object_id, result: *mut object_id);
pub fn store_git_commit(commit_buf: *const strbuf, result: *mut object_id);
pub fn store_git_blob(blob_buf: strslice, result: *mut object_id);
fn store_git_tree(tree_buf: strslice, reference: *const object_id, result: *mut object_id);
pub fn store_git_commit(commit_buf: strslice, result: *mut object_id);
pub fn do_set_replace(replaced: *const object_id, replace_with: *const object_id);
fn create_git_tree(
tree_id: *const object_id,
Expand Down Expand Up @@ -1298,7 +1298,7 @@ fn store_changeset(
let manifest_tree_id = match changeset.manifest() {
m if m.is_null() => unsafe {
let mut tid = object_id::default();
store_git_tree(&strbuf::new(), std::ptr::null(), &mut tid);
store_git_tree([].into(), std::ptr::null(), &mut tid);
TreeId::from_unchecked(GitObjectId::from(tid))
},
m => {
Expand Down Expand Up @@ -1343,7 +1343,7 @@ fn store_changeset(
buf.extend_from_slice(&metadata.serialize());
let mut cs_metadata_oid = object_id::default();
unsafe {
store_git_blob(&buf, &mut cs_metadata_oid);
store_git_blob(buf.as_bytes().into(), &mut cs_metadata_oid);
}
let metadata_id = GitChangesetMetadataId::from_unchecked(
BlobId::from_unchecked(GitObjectId::from(cs_metadata_oid)),
Expand All @@ -1360,7 +1360,7 @@ fn store_changeset(
let result = raw_commit_for_changeset(&changeset, tree_id, &git_parents);
let mut result_oid = object_id::default();
unsafe {
store_git_commit(&result, &mut result_oid);
store_git_commit(result.as_bytes().into(), &mut result_oid);
}
let commit_id = CommitId::from_unchecked(GitObjectId::from(result_oid));

Expand All @@ -1374,7 +1374,7 @@ fn store_changeset(
buf.extend_from_slice(&metadata.serialize());
let mut cs_metadata_oid = object_id::default();
unsafe {
store_git_blob(&buf, &mut cs_metadata_oid);
store_git_blob(buf.as_bytes().into(), &mut cs_metadata_oid);
}
let metadata_id = GitChangesetMetadataId::from_unchecked(BlobId::from_unchecked(
GitObjectId::from(cs_metadata_oid),
Expand Down Expand Up @@ -1436,7 +1436,7 @@ fn handle_changeset_conflict(hg_id: HgChangesetId, git_id: &mut CommitId) {
commit_data.extend_from_slice(b"\0");
let mut new_git_id = object_id::default();
unsafe {
store_git_commit(commit_data, &mut new_git_id);
store_git_commit(commit_data.as_bytes().into(), &mut new_git_id);
}
*git_id = CommitId::from_unchecked(new_git_id.into());
}
Expand Down Expand Up @@ -1537,7 +1537,7 @@ pub fn create_changeset(
buf.extend_from_slice(&cs_metadata.serialize());
let mut blob_oid = object_id::default();
unsafe {
store_git_blob(&buf, &mut blob_oid);
store_git_blob(buf.as_bytes().into(), &mut blob_oid);
metadata.set(
SetWhat::Changeset,
cs_metadata.changeset_id.into(),
Expand Down Expand Up @@ -1819,7 +1819,7 @@ pub fn store_changegroup<R: Read>(metadata: &mut Metadata, input: R, version: u8
if !bundle.as_bytes().is_empty() {
let mut bundle_blob = object_id::default();
unsafe {
store_git_blob(&bundle, &mut bundle_blob);
store_git_blob(bundle.as_bytes().into(), &mut bundle_blob);
}
BUNDLE_BLOBS.lock().unwrap().push(bundle_blob);
}
Expand Down Expand Up @@ -2290,7 +2290,7 @@ pub fn do_store_metadata(metadata: &mut Metadata) -> CommitId {
);
unsafe {
let mut result = object_id::default();
store_git_commit(&buf, &mut result);
store_git_commit(buf.as_bytes().into(), &mut result);
CommitId::from_unchecked(result.into())
}
}

0 comments on commit 5bc786a

Please sign in to comment.