repo: implement list_refs and list_refs_ext

This commit is contained in:
Felix Krull 2018-10-09 21:13:13 +02:00 committed by Colin Walters
parent ae9413343d
commit dff1cf631b
3 changed files with 76 additions and 7 deletions

View File

@ -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;

View File

@ -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<HashSet<ObjectName>, Error>;
cancellable: P
) -> Result<HashSet<ObjectName>, Error>;
fn list_refs<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
&self,
refspec_prefix: P,
cancellable: Q
) -> Result<HashMap<String, String>, Error>;
fn list_refs_ext<'a, 'b, P: Into<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
&self,
refspec_prefix: P,
flags: RepoListRefsExtFlags,
cancellable: Q
) -> Result<HashMap<String, String>, Error>;
}
impl<O: IsA<Repo> + IsA<glib::Object> + Clone + 'static> RepoExtManual for O {
@ -57,7 +69,61 @@ impl<O: IsA<Repo> + IsA<glib::Object> + 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<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
&self,
refspec_prefix: P,
cancellable: Q
) -> Result<HashMap<String, String>, 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<Option<&'a str>>, Q: Into<Option<&'b gio::Cancellable>>>(
&self,
refspec_prefix: P,
flags: RepoListRefsExtFlags,
cancellable: Q
) -> Result<HashMap<String, String>, 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))
}
}
}
}

View File

@ -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());