From a9d86f47021886147d46e2a8d9248f94edc45321 Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Wed, 22 Jul 2020 21:47:31 +0800 Subject: [PATCH] Add bindings for `git_index_version()` and `git_index_set_version()` (#597) --- libgit2-sys/lib.rs | 2 ++ src/index.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 813e905d05..19759e396b 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -2619,6 +2619,8 @@ extern "C" { ) -> c_int; // index + pub fn git_index_version(index: *mut git_index) -> c_uint; + pub fn git_index_set_version(index: *mut git_index, version: c_uint) -> c_int; pub fn git_index_add(index: *mut git_index, entry: *const git_index_entry) -> c_int; pub fn git_index_add_all( index: *mut git_index, diff --git a/src/index.rs b/src/index.rs index 1bee22ec17..5612f43a30 100644 --- a/src/index.rs +++ b/src/index.rs @@ -117,6 +117,27 @@ impl Index { } } + /// Get index on-disk version. + /// + /// Valid return values are 2, 3, or 4. If 3 is returned, an index + /// with version 2 may be written instead, if the extension data in + /// version 3 is not necessary. + pub fn version(&self) -> u32 { + unsafe { raw::git_index_version(self.raw) } + } + + /// Set index on-disk version. + /// + /// Valid values are 2, 3, or 4. If 2 is given, git_index_write may + /// write an index with version 3 instead, if necessary to accurately + /// represent the index. + pub fn set_version(&mut self, version: u32) -> Result<(), Error> { + unsafe { + try_call!(raw::git_index_set_version(self.raw, version)); + } + Ok(()) + } + /// Add or update an index entry from an in-memory struct /// /// If a previous index entry exists that has the same path and stage as the