From 2a1c92d10a62c5da72a5c7fe94be65901ccb9b8f Mon Sep 17 00:00:00 2001 From: iancormac84 Date: Sun, 10 Mar 2019 11:16:44 -0400 Subject: [PATCH 1/2] Amended IndexConflict to make it sensitive to the possibility that git_index_conflict_iterator returns a NULL pointer for one of the trio of IndexEntries. Also added Reference::find_reference_dwim to make it a little easier to find refs. --- libgit2-sys/lib.rs | 3 +++ src/index.rs | 21 +++++++++++++++------ src/repo.rs | 13 +++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index b1c4bdf5eb..d9d692cfb5 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -1886,6 +1886,9 @@ extern { pub fn git_reference_lookup(out: *mut *mut git_reference, repo: *mut git_repository, name: *const c_char) -> c_int; + pub fn git_reference_dwim(out: *mut *mut git_reference, + repo: *mut git_repository, + refname: *const c_char) -> c_int; pub fn git_reference_name(r: *const git_reference) -> *const c_char; pub fn git_reference_name_to_id(out: *mut git_oid, repo: *mut git_repository, diff --git a/src/index.rs b/src/index.rs index 1071db3978..765a20c202 100644 --- a/src/index.rs +++ b/src/index.rs @@ -33,13 +33,13 @@ pub struct IndexConflicts<'index> { /// A structure to represent the information returned when a conflict is detected in an index entry pub struct IndexConflict { /// The ancestor index entry of the two conflicting index entries - pub ancestor: IndexEntry, + pub ancestor: Option, /// The index entry originating from the user's copy of the repository. /// Its contents conflict with 'their' index entry - pub our: IndexEntry, + pub our: Option, /// The index entry originating from the external repository. /// Its contents conflict with 'our' index entry - pub their: IndexEntry, + pub their: Option, } /// A callback function to filter index matches. @@ -588,9 +588,18 @@ impl<'index> Iterator for IndexConflicts<'index> { self.conflict_iter )); Some(Ok(IndexConflict { - ancestor: IndexEntry::from_raw(*ancestor), - our: IndexEntry::from_raw(*our), - their: IndexEntry::from_raw(*their), + ancestor: match ancestor.is_null() { + false => Some(IndexEntry::from_raw(*ancestor)), + true => None, + }, + our: match our.is_null() { + false => Some(IndexEntry::from_raw(*our)), + true => None, + }, + their: match their.is_null() { + false => Some(IndexEntry::from_raw(*their)), + true => None, + }, })) } } diff --git a/src/repo.rs b/src/repo.rs index 263beb7006..0972ca12cc 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1218,6 +1218,19 @@ impl Repository { } } + /// Lookup a reference to one of the objects in a repository. + /// `Repository::find_reference` with teeth; give the method your reference in + /// human-readable format e.g. 'master' instead of 'refs/heads/master', and it + /// will do-what-you-mean, returning the `Reference`. + pub fn find_reference_dwim(&self, refname: &str) -> Result { + let refname = try!(CString::new(refname)); + let mut raw = ptr::null_mut(); + unsafe { + try_call!(raw::git_reference_dwim(&mut raw, self.raw(), refname)); + Ok(Binding::from_raw(raw)) + } + } + /// Lookup a reference by name and resolve immediately to OID. /// /// This function provides a quick way to resolve a reference name straight From f35dd8fb8314532164beebc31a8abe878199f7f7 Mon Sep 17 00:00:00 2001 From: iancormac84 Date: Tue, 26 Mar 2019 18:13:41 -0400 Subject: [PATCH 2/2] Changed Repository::find_reference_dwim to Repository::resolve_reference_from_short_name. --- src/repo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repo.rs b/src/repo.rs index 0972ca12cc..4cb1b9c77b 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1222,7 +1222,7 @@ impl Repository { /// `Repository::find_reference` with teeth; give the method your reference in /// human-readable format e.g. 'master' instead of 'refs/heads/master', and it /// will do-what-you-mean, returning the `Reference`. - pub fn find_reference_dwim(&self, refname: &str) -> Result { + pub fn resolve_reference_from_short_name(&self, refname: &str) -> Result { let refname = try!(CString::new(refname)); let mut raw = ptr::null_mut(); unsafe {