Skip to content

Commit ac56526

Browse files
authoredJun 3, 2019
Merge pull request #409 from iancormac84/optionize-indexconflict
Amended IndexConflict to make it sensitive to the possibility that gi…
2 parents 738e8e3 + f35dd8f commit ac56526

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed
 

‎libgit2-sys/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,9 @@ extern {
18721872
pub fn git_reference_lookup(out: *mut *mut git_reference,
18731873
repo: *mut git_repository,
18741874
name: *const c_char) -> c_int;
1875+
pub fn git_reference_dwim(out: *mut *mut git_reference,
1876+
repo: *mut git_repository,
1877+
refname: *const c_char) -> c_int;
18751878
pub fn git_reference_name(r: *const git_reference) -> *const c_char;
18761879
pub fn git_reference_name_to_id(out: *mut git_oid,
18771880
repo: *mut git_repository,

‎src/index.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ pub struct IndexConflicts<'index> {
3333
/// A structure to represent the information returned when a conflict is detected in an index entry
3434
pub struct IndexConflict {
3535
/// The ancestor index entry of the two conflicting index entries
36-
pub ancestor: IndexEntry,
36+
pub ancestor: Option<IndexEntry>,
3737
/// The index entry originating from the user's copy of the repository.
3838
/// Its contents conflict with 'their' index entry
39-
pub our: IndexEntry,
39+
pub our: Option<IndexEntry>,
4040
/// The index entry originating from the external repository.
4141
/// Its contents conflict with 'our' index entry
42-
pub their: IndexEntry,
42+
pub their: Option<IndexEntry>,
4343
}
4444

4545
/// A callback function to filter index matches.
@@ -588,9 +588,18 @@ impl<'index> Iterator for IndexConflicts<'index> {
588588
self.conflict_iter
589589
));
590590
Some(Ok(IndexConflict {
591-
ancestor: IndexEntry::from_raw(*ancestor),
592-
our: IndexEntry::from_raw(*our),
593-
their: IndexEntry::from_raw(*their),
591+
ancestor: match ancestor.is_null() {
592+
false => Some(IndexEntry::from_raw(*ancestor)),
593+
true => None,
594+
},
595+
our: match our.is_null() {
596+
false => Some(IndexEntry::from_raw(*our)),
597+
true => None,
598+
},
599+
their: match their.is_null() {
600+
false => Some(IndexEntry::from_raw(*their)),
601+
true => None,
602+
},
594603
}))
595604
}
596605
}

‎src/repo.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,19 @@ impl Repository {
12181218
}
12191219
}
12201220

1221+
/// Lookup a reference to one of the objects in a repository.
1222+
/// `Repository::find_reference` with teeth; give the method your reference in
1223+
/// human-readable format e.g. 'master' instead of 'refs/heads/master', and it
1224+
/// will do-what-you-mean, returning the `Reference`.
1225+
pub fn resolve_reference_from_short_name(&self, refname: &str) -> Result<Reference, Error> {
1226+
let refname = try!(CString::new(refname));
1227+
let mut raw = ptr::null_mut();
1228+
unsafe {
1229+
try_call!(raw::git_reference_dwim(&mut raw, self.raw(), refname));
1230+
Ok(Binding::from_raw(raw))
1231+
}
1232+
}
1233+
12211234
/// Lookup a reference by name and resolve immediately to OID.
12221235
///
12231236
/// This function provides a quick way to resolve a reference name straight

0 commit comments

Comments
 (0)