aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2026-02-07 20:04:34 +0000
committerJunio C Hamano <gitster@pobox.com>2026-02-07 17:41:01 -0800
commitb674d1036a3a82aaccfd5586007006f1f08648ef (patch)
tree65d2ef1eadb7b34ca9b83ced4bc0b026cf46ab07 /src
parent67e526c33e025918c146c7cb61007cc2ffc46661 (diff)
downloadgit-b674d1036a3a82aaccfd5586007006f1f08648ef.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/hash.rs21
-rw-r--r--src/lib.rs1
-rw-r--r--src/meson.build1
3 files changed, 23 insertions, 0 deletions
diff --git a/src/hash.rs b/src/hash.rs
new file mode 100644
index 0000000000..0219391820
--- /dev/null
+++ b/src/hash.rs
@@ -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,
+}
diff --git a/src/lib.rs b/src/lib.rs
index 9da70d8b57..cf7c962509 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1 +1,2 @@
+pub mod hash;
pub mod varint;
diff --git a/src/meson.build b/src/meson.build
index 25b9ad5a14..c77041a3fa 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,4 +1,5 @@
libgit_rs_sources = [
+ 'hash.rs',
'lib.rs',
'varint.rs',
]