ok/jj
1
0
Fork 0
forked from mirrors/jj

log: use index for walking revisions

This updates `jj log` to walk the index for doing the topological
walk, which is much faster than walking the object graph. This speeds
up `jj log | head -1` in the git.git repo from ~1.9s to ~0.27s (most
of the remaining time is spent calculating the evolve state).

A consequence of walking the index instead is that the order of
commits in the output is by by generation number. That's nice in some
ways, but it also means that the newest commit isn't always at the
top.
This commit is contained in:
Martin von Zweigbergk 2021-02-07 23:45:14 -08:00
parent 4c5dd740fd
commit 7e012ad84f

View file

@ -1049,27 +1049,24 @@ fn cmd_log(
let mut styler = styler.as_mut(); let mut styler = styler.as_mut();
styler.add_label(String::from("log")); styler.add_label(String::from("log"));
let store = repo.store();
let mut heads: HashSet<_> = repo let mut heads: HashSet<_> = repo
.view() .view()
.heads() .heads()
.iter() .iter()
.map(|id| repo.store().get_commit(id).unwrap()) .map(|id| store.get_commit(id).unwrap())
.collect(); .collect();
if !sub_matches.is_present("all") { if !sub_matches.is_present("all") {
heads = skip_uninteresting_heads(&repo, heads); heads = skip_uninteresting_heads(&repo, heads);
}; };
let mut heads: Vec<_> = heads.into_iter().collect();
heads.sort_by_key(|commit| commit.committer().timestamp.clone());
heads.reverse();
let commits = topo_order_reverse( let head_ids: Vec<_> = heads.iter().map(|commit| commit.id().clone()).collect();
heads, let index = repo.index();
Box::new(|commit: &Commit| commit.id().clone()), let index_entries = index.walk_revs(&head_ids, &[]);
Box::new(|commit: &Commit| commit.parents()),
);
if use_graph { if use_graph {
let mut graph = AsciiGraphDrawer::new(&mut styler); let mut graph = AsciiGraphDrawer::new(&mut styler);
for commit in commits { for index_entry in index_entries {
let commit = store.get_commit(&index_entry.commit_id()).unwrap();
let mut edges = vec![]; let mut edges = vec![];
for parent in commit.parents() { for parent in commit.parents() {
edges.push(Edge::direct(parent.id().clone())); edges.push(Edge::direct(parent.id().clone()));
@ -1087,7 +1084,8 @@ fn cmd_log(
graph.add_node(commit.id(), &edges, b"o", &buffer); graph.add_node(commit.id(), &edges, b"o", &buffer);
} }
} else { } else {
for commit in commits { for index_entry in index_entries {
let commit = store.get_commit(&index_entry.commit_id()).unwrap();
template.format(&commit, styler); template.format(&commit, styler);
} }
} }