1
1
mirror of https://github.com/orhun/git-cliff.git synced 2025-01-05 15:58:24 +03:00

fix(git): derive the tag order from commits instead of timestamp (#139)

This commit is contained in:
Orhun Parmaksız 2023-01-20 14:24:39 +03:00
parent 08ea900de0
commit 4df5656c12
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90

View File

@ -5,6 +5,7 @@ use crate::error::{
use git2::{
Commit,
DescribeOptions,
Oid,
Repository as GitRepository,
Sort,
};
@ -122,7 +123,15 @@ impl Repository {
}
}
if !topo_order {
tags.sort_by(|a, b| a.0.time().seconds().cmp(&b.0.time().seconds()));
let mut revwalk = self.inner.revwalk()?;
revwalk.set_sorting(Sort::TIME | Sort::TOPOLOGICAL)?;
revwalk.push_head()?;
let oids: Vec<Oid> = revwalk.filter_map(|id| id.ok()).collect();
tags.sort_by(|a, b| {
oids.iter()
.position(|v| v == &b.0.id())
.cmp(&oids.iter().position(|v| v == &a.0.id()))
});
}
Ok(tags
.into_iter()