Skip to content

Conversation

@algmyr
Copy link
Member

@algmyr algmyr commented Nov 30, 2025

This allows replicating the default diff summary display in templates.

This will go well with #8183 for custom log templates. E.g. with

'diff_listing(diff)' = '''
  diff.files().map(|f|
    label(f.status(),
      separate(' ',
        f.status_char(),
        f.formatted_path(),
        if(f.source().conflict() && !f.target().conflict(),
          label('conflict_description', '(resolved conflict)'),
        )
      )
    )
  ).join("\n")
'''

'conflict_listing(commit)' = '''
  commit.conflicted_files().map(|f|
    separate(" ",
      label("conflict", f.path().display()),
      label('conflict_description', f.conflict_sides() ++ "-sided conflict"),
    )
  ).join("\n")
'''

you can create a log template looking something like

image

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added/updated tests to cover my changes

@algmyr algmyr force-pushed the algmyr/push-tyzsyxrxqntl branch from 14ad12b to 51ac932 Compare November 30, 2025 16:47
@algmyr algmyr marked this pull request as ready for review November 30, 2025 16:47
@algmyr algmyr requested a review from a team as a code owner November 30, 2025 16:47
Copy link
Contributor

@yuja yuja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

},
);
map.insert(
"formatted_path",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since this only matters for copied entries, I think the function name should include "copy", e.g. display_copied_path(). Maybe we could add copied_path() -> CopiedTreeDiffEntryPath function, but I don't think we'll add functions other than copied_path().display().

Another option is to add path.display_copy_from(source.path()) function to RepoPath template type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my head this is not a copy specific function. It only makes a difference for copies, but it has the behavior you would want in general. Still open yo name changed, but I would prefer something that doesn't suggest it's copy specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean path().display() vs formatted_path() matters only when the entry was copied/renamed. It may be confusing if we have two ways of formatting paths.

Copy link
Member Author

@algmyr algmyr Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally path().display() should take the move into account so that we only have one way of doing formatting. I guess that would involve making path() return some new type.

It would be a mildly breaking change, but code relying on the old behavior can easily migrate to use (the much more explicit) target().

});
Ok(out_property.into_dyn_wrapped())
},
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably better to rebase this on top of #8123.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant code is now in main

concat(
description.first_line() ++ ":\n",
diff.files().map(|e|
e.status_char() ++ " " ++ e.path() ++ "\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you instead update existing tests to minimize test execution time? I think there are tests for .status() in test_commit_template.rs or test_diff_command.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants