Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: sort commits by template-aliases.commit_timestamp #5273

Open
avamsi opened this issue Jan 6, 2025 · 3 comments
Open

FR: sort commits by template-aliases.commit_timestamp #5273

avamsi opened this issue Jan 6, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@avamsi
Copy link
Member

avamsi commented Jan 6, 2025

I tried the new commit_timestamp knob and I think I like author timestamp better -- but the log graph still uses committer timestamp to sort commits. It would be nice to somehow use commit_timestamp directly or at least provide another knob to sort by author timestamp.

I think @yuja's #2078 (that adds CommitByCommitterTimestamp) would be a good reference for a potential implementation.

@avamsi avamsi added the enhancement New feature or request label Jan 6, 2025
@yuja
Copy link
Contributor

yuja commented Jan 6, 2025

Do you mean the order of graph nodes? It's basically creation order in non-linear part (with some tweaks to group nodes topologically.)

We could add an option to sort non-graph log, but implementation-wise, there would be no relation to templater.

@avamsi
Copy link
Member Author

avamsi commented Jan 6, 2025

Yes, I mean the order of sibling graph nodes.

Consider this example:

$ jj new xo -m 1
$ jj new xo -m 2
$ jj new xo

These result in the following state:

@  p avamsi07 27 seconds ago e7b2447
│  (empty) (no description set)
│ ○  y avamsi07 32 seconds ago 05cc689
├─╯  (empty) 2
│ ○  xs avamsi07 45 seconds ago dd2786d
├─╯  (empty) 1
◆  xo avamsi07 1 week ago main git_head() 2a24fd2
│  initial commit
~

Now if we run jj desc xs -m 11:

@  p avamsi07 3 minutes ago e7b2447
│  (empty) (no description set)
│ ○  xs avamsi07 3 minutes ago fa5fec9
├─╯  (empty) 11
│ ○  y avamsi07 3 minutes ago 05cc689
├─╯  (empty) 2
◆  xo avamsi07 1 week ago main git_head() 2a24fd2
│  initial commit
~

xs and y are swapped, presumably because they're being sorted by committer timestamp -- I want to sort them by author timestamp instead. Does that make sense?

@yuja
Copy link
Contributor

yuja commented Jan 6, 2025

Ok, relevant code is here:

jj/cli/src/commands/log.rs

Lines 187 to 194 in 6c14ccd

let mut forward_iter = TopoGroupedGraphIterator::new(revset.iter_graph());
// Emit the working-copy branch first, which is usually most
// interesting. This also helps stabilize output order.
if let Some(id) = workspace_command.get_wc_commit_id() {
let has_commit = revset.containing_fn();
if has_commit(id)? {
forward_iter.prioritize_branch(id.clone());
}

I have no idea how to expose the feature, but we'll probably need to

  • collect heads of the graph filtered by the current revset
  • sort them by some criteria
  • add them to the prioritized list

It is now displayed in order of appearance (or indexed order.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants