From dff1cf631b3ace37909cec968517ea948d92b3e6 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 9 Oct 2018 21:13:13 +0200 Subject: [PATCH] repo: implement list_refs and list_refs_ext --- rust-bindings/rust/libostree/src/auto/mod.rs | 1 + rust-bindings/rust/libostree/src/repo.rs | 74 ++++++++++++++++++-- rust-bindings/rust/sample/src/main.rs | 8 ++- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/rust-bindings/rust/libostree/src/auto/mod.rs b/rust-bindings/rust/libostree/src/auto/mod.rs index 2c701c56..e2509978 100644 --- a/rust-bindings/rust/libostree/src/auto/mod.rs +++ b/rust-bindings/rust/libostree/src/auto/mod.rs @@ -59,6 +59,7 @@ pub use self::enums::StaticDeltaGenerateOpt; mod flags; #[cfg(any(feature = "v2015_7", feature = "dox"))] pub use self::flags::RepoCommitState; +pub use self::flags::RepoListRefsExtFlags; pub use self::flags::RepoPullFlags; pub use self::flags::SePolicyRestoreconFlags; diff --git a/rust-bindings/rust/libostree/src/repo.rs b/rust-bindings/rust/libostree/src/repo.rs index 1fec31a4..64e62a94 100644 --- a/rust-bindings/rust/libostree/src/repo.rs +++ b/rust-bindings/rust/libostree/src/repo.rs @@ -1,4 +1,4 @@ -use auto::Repo; +use auto::{Repo, RepoListRefsExtFlags}; use ffi; use gio; use glib; @@ -6,7 +6,7 @@ use glib::Error; use glib::IsA; use glib::translate::*; use glib_ffi; -use std::collections::HashSet; +use std::collections::{HashSet, HashMap}; use std::ptr; use std::path::Path; use ObjectName; @@ -32,7 +32,19 @@ pub trait RepoExtManual { &self, commit_checksum: &str, maxdepth: i32, - cancellable: P) -> Result, Error>; + cancellable: P + ) -> Result, Error>; + fn list_refs<'a, 'b, P: Into>, Q: Into>>( + &self, + refspec_prefix: P, + cancellable: Q + ) -> Result, Error>; + fn list_refs_ext<'a, 'b, P: Into>, Q: Into>>( + &self, + refspec_prefix: P, + flags: RepoListRefsExtFlags, + cancellable: Q + ) -> Result, Error>; } impl + IsA + Clone + 'static> RepoExtManual for O { @@ -57,7 +69,61 @@ impl + IsA + Clone + 'static> RepoExtManual for O { cancellable.into().to_glib_none().0, &mut error, ); - if error.is_null() { Ok(from_glib_container_variant_set(hashtable)) } else { Err(from_glib_full(error)) } + if error.is_null() { + Ok(from_glib_container_variant_set(hashtable)) + } else { + Err(from_glib_full(error)) + } + } + } + + fn list_refs<'a, 'b, P: Into>, Q: Into>>( + &self, + refspec_prefix: P, + cancellable: Q + ) -> Result, Error> { + unsafe { + let mut error = ptr::null_mut(); + let mut hashtable = ptr::null_mut(); + let _ = ffi::ostree_repo_list_refs( + self.to_glib_none().0, + refspec_prefix.into().to_glib_none().0, + &mut hashtable, + cancellable.into().to_glib_none().0, + &mut error, + ); + + if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_container(hashtable)) + } else { + Err(from_glib_full(error)) + } + } + } + + fn list_refs_ext<'a, 'b, P: Into>, Q: Into>>( + &self, + refspec_prefix: P, + flags: RepoListRefsExtFlags, + cancellable: Q + ) -> Result, Error> { + unsafe { + let mut error = ptr::null_mut(); + let mut hashtable = ptr::null_mut(); + let _ = ffi::ostree_repo_list_refs_ext( + self.to_glib_none().0, + refspec_prefix.into().to_glib_none().0, + &mut hashtable, + flags.to_glib(), + cancellable.into().to_glib_none().0, + &mut error, + ); + + if error.is_null() { + Ok(FromGlibPtrContainer::from_glib_container(hashtable)) + } else { + Err(from_glib_full(error)) + } } } } diff --git a/rust-bindings/rust/sample/src/main.rs b/rust-bindings/rust/sample/src/main.rs index 8e1ef5b8..02405f9c 100644 --- a/rust-bindings/rust/sample/src/main.rs +++ b/rust-bindings/rust/sample/src/main.rs @@ -10,11 +10,13 @@ use libostree::prelude::*; fn main() { let repo = libostree::Repo::new_for_path("../../../repo-bare"); - //let result = repo.create(libostree::RepoMode::Archive, Option::None); - //result.expect("we did not expect this to fail :O"); - repo.open(None).expect("should have opened"); + let refs = repo.list_refs(None, None).unwrap(); + for (refspec, checksum) in refs { + println!(" {} = {}", refspec, checksum); + } + let (file, checksum) = repo.read_commit("test", None).unwrap(); println!("path: {:?}", file.get_path());