Skip to content

Commit 15614af

Browse files
committed
feat: handle ReflogLookup::Date
Handles the missing Date based reflog lookup. The target date is compared against the signature time field
1 parent db5c9cf commit 15614af

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

gix/src/revision/spec/parse/delegate/revision.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,48 @@ impl delegate::Revision for Delegate<'_> {
106106
fn reflog(&mut self, query: ReflogLookup) -> Option<()> {
107107
self.unset_disambiguate_call();
108108
match query {
109-
ReflogLookup::Date(_date) => {
110-
// TODO: actually do this - this should be possible now despite incomplete date parsing
111-
self.err.push(Error::Planned {
112-
dependency: "remote handling and ref-specs are fleshed out more",
113-
});
114-
None
109+
ReflogLookup::Date(date) => {
110+
let r = match &mut self.refs[self.idx] {
111+
Some(r) => r.clone().attach(self.repo),
112+
val @ None => match self.repo.head().map(crate::Head::try_into_referent) {
113+
Ok(Some(r)) => {
114+
*val = Some(r.clone().detach());
115+
r
116+
}
117+
Ok(None) => {
118+
self.err.push(Error::UnbornHeadsHaveNoRefLog);
119+
return None;
120+
}
121+
Err(err) => {
122+
self.err.push(err.into());
123+
return None;
124+
}
125+
},
126+
};
127+
128+
let mut platform = r.log_iter();
129+
match platform.rev().ok().flatten() {
130+
Some(it) => match it.filter_map(Result::ok).min_by_key(|l| l.signature.time.cmp(&date)) {
131+
Some(closest_line) => {
132+
self.objs[self.idx]
133+
.get_or_insert_with(HashSet::default)
134+
.insert(closest_line.new_oid);
135+
Some(())
136+
}
137+
None => {
138+
// do we need an another error variant?
139+
self.err.push(Error::SingleNotFound);
140+
None
141+
}
142+
},
143+
None => {
144+
self.err.push(Error::MissingRefLog {
145+
reference: r.name().as_bstr().into(),
146+
action: "lookup entry",
147+
});
148+
None
149+
}
150+
}
115151
}
116152
ReflogLookup::Entry(no) => {
117153
let r = match &mut self.refs[self.idx] {

0 commit comments

Comments
 (0)