Skip to content

Commit eec4151

Browse files
bk2204gitster
authored andcommitted
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. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e5c744e commit eec4151

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
15281528

15291529
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
15301530

1531+
RUST_SOURCES += src/hash.rs
15311532
RUST_SOURCES += src/lib.rs
15321533
RUST_SOURCES += src/varint.rs
15331534

src/hash.rs

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

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
pub mod hash;
12
pub mod varint;

src/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
libgit_rs_sources = [
2+
'hash.rs',
23
'lib.rs',
34
'varint.rs',
45
]

0 commit comments

Comments
 (0)