Skip to content

Commit

Permalink
Merge pull request #409 from iancormac84/optionize-indexconflict
Browse files Browse the repository at this point in the history
Amended IndexConflict to make it sensitive to the possibility that gi…
  • Loading branch information
alexcrichton committed Jun 3, 2019
2 parents 738e8e3 + f35dd8f commit ac56526
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,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,
Expand Down
21 changes: 15 additions & 6 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndexEntry>,
/// 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<IndexEntry>,
/// The index entry originating from the external repository.
/// Its contents conflict with 'our' index entry
pub their: IndexEntry,
pub their: Option<IndexEntry>,
}

/// A callback function to filter index matches.
Expand Down Expand Up @@ -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,
},
}))
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 resolve_reference_from_short_name(&self, refname: &str) -> Result<Reference, Error> {
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
Expand Down

0 comments on commit ac56526

Please sign in to comment.