rust: add a ObjectID struct

We'd like to be able to write some Rust code that can work with object
IDs.  Add a structure here that's identical to struct object_id in C,
for easy use in sharing across the FFI boundary.  We will use this
structure in several places in hot paths, such as index-pack or
pack-objects when converting between algorithms, so prioritize efficient
interchange over a more idiomatic Rust approach.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson 2025-11-17 22:16:10 +00:00 committed by Junio C Hamano
parent f97c49398b
commit 0404613aa0
4 changed files with 24 additions and 0 deletions

View File

@ -1528,6 +1528,7 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
RUST_SOURCES += src/hash.rs
RUST_SOURCES += src/lib.rs
RUST_SOURCES += src/varint.rs

21
src/hash.rs Normal file
View File

@ -0,0 +1,21 @@
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation: version 2 of the License, dated June 1991.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, see <https://www.gnu.org/licenses/>.
pub const GIT_MAX_RAWSZ: usize = 32;
/// A binary object ID.
#[repr(C)]
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub struct ObjectID {
pub hash: [u8; GIT_MAX_RAWSZ],
pub algo: u32,
}

View File

@ -1 +1,2 @@
pub mod hash;
pub mod varint;

View File

@ -1,4 +1,5 @@
libgit_rs_sources = [
'hash.rs',
'lib.rs',
'varint.rs',
]