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:
parent
08ea900de0
commit
4df5656c12
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user