Skip to content

Amended IndexConflict to make it sensitive to the possibility that gi… #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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