Skip to content

Commit 2ea6acb

Browse files
committed
Change walk order from ByCommitTime to topological order
This is preparation for a graph implementation. If sorted by commit time, a graph may have to draw a parent before its child. This is confusing to the user and require extra memory for the graph render algorithm.
1 parent b2a655e commit 2ea6acb

2 files changed

Lines changed: 9 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
* open the external editor from the status diff view [[@WaterWhisperer](https://github.com/WaterWhisperer)] ([#2805](https://github.com/gitui-org/gitui/issues/2805))
1616
* automatically convert spaces to dashes when creating or renaming a branch [[@pbouillon]](https//pbouillon.github.io)] ([#2916](https://github.com/gitui-org/gitui/pull/2916))
1717
* support rewording non-HEAD commits when `commit.gpgsign` is enabled (gpg format only) [[@guerinoni](https://github.com/guerinoni)] ([#2959](https://github.com/gitui-org/gitui/pull/2959))
18+
* change commit order from commit time to topology order
1819

1920
### Fixes
2021
* crash when opening submodule ([#2895](https://github.com/gitui-org/gitui/issues/2895))

asyncgit/src/sync/logwalker.rs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,11 @@ use super::{CommitId, SharedCommitFilterFn};
22
use crate::error::Result;
33
use git2::{Commit, Oid, Repository};
44
use gix::revision::Walk;
5-
use std::{
6-
cmp::Ordering,
7-
collections::{BinaryHeap, HashSet},
8-
};
9-
10-
struct TimeOrderedCommit<'a>(Commit<'a>);
11-
12-
impl Eq for TimeOrderedCommit<'_> {}
13-
14-
impl PartialEq for TimeOrderedCommit<'_> {
15-
fn eq(&self, other: &Self) -> bool {
16-
self.0.time().eq(&other.0.time())
17-
}
18-
}
19-
20-
impl PartialOrd for TimeOrderedCommit<'_> {
21-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
22-
Some(self.cmp(other))
23-
}
24-
}
25-
26-
impl Ord for TimeOrderedCommit<'_> {
27-
fn cmp(&self, other: &Self) -> Ordering {
28-
self.0.time().cmp(&other.0.time())
29-
}
30-
}
5+
use std::collections::HashSet;
316

327
///
338
pub struct LogWalker<'a> {
34-
commits: BinaryHeap<TimeOrderedCommit<'a>>,
9+
commits: Vec<Commit<'a>>,
3510
visited: HashSet<Oid>,
3611
limit: usize,
3712
repo: &'a Repository,
@@ -43,8 +18,8 @@ impl<'a> LogWalker<'a> {
4318
pub fn new(repo: &'a Repository, limit: usize) -> Result<Self> {
4419
let c = repo.head()?.peel_to_commit()?;
4520

46-
let mut commits = BinaryHeap::with_capacity(10);
47-
commits.push(TimeOrderedCommit(c));
21+
let mut commits = Vec::with_capacity(10);
22+
commits.push(c);
4823

4924
Ok(Self {
5025
commits,
@@ -74,11 +49,11 @@ impl<'a> LogWalker<'a> {
7449
let mut count = 0_usize;
7550

7651
while let Some(c) = self.commits.pop() {
77-
for p in c.0.parents() {
52+
for p in c.parents() {
7853
self.visit(p);
7954
}
8055

81-
let id: CommitId = c.0.id().into();
56+
let id: CommitId = c.id().into();
8257
let commit_should_be_included =
8358
if let Some(ref filter) = self.filter {
8459
filter(self.repo, &id)?
@@ -102,7 +77,7 @@ impl<'a> LogWalker<'a> {
10277
//
10378
fn visit(&mut self, c: Commit<'a>) {
10479
if self.visited.insert(c.id()) {
105-
self.commits.push(TimeOrderedCommit(c));
80+
self.commits.push(c);
10681
}
10782
}
10883
}
@@ -137,10 +112,7 @@ impl<'a> LogWalkerWithoutFilter<'a> {
137112

138113
let tips = [commit.id];
139114

140-
let platform = repo
141-
.rev_walk(tips)
142-
.sorting(gix::revision::walk::Sorting::ByCommitTime(gix::traverse::commit::simple::CommitTimeOrder::NewestFirst))
143-
.use_commit_graph(false);
115+
let platform = repo.rev_walk(tips);
144116

145117
let walk = platform.all()?;
146118

0 commit comments

Comments
 (0)