delta: 🐛 [format.pretty] breaks delta

Hi, thanks for making this! Still got a few bugs but once they are fixed, that would be an indispensable tool!

I have in my .gitconfig:

[format]
	pretty = %C(blue)%H%C(red) %an %C(green)%ad%C(yellow)%d%n%B
[core]
	pager = delta --commit-color=blue --file-color=yellow --file-style=box --hunk-color=purple --hunk-style=plain --theme=none

The [format] part seems to break delta. When I do a git log -p, the first line (commit hash, committer, date) is fine however the rest are colorless. The style is preserved as I’ve specified in format though. What can I do about it?

Delta 0.1.1.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

That seems to have been a simple change. https://github.com/dandavison/delta/pull/558 if you would like to try it out. So for your example, something like git -c delta.commit-regex='^[0-9a-f]{7,} ' log should work.

image

Sounds to me like we would get the most gain for the least effort by allowing users to supply their own regular expressions.

Ah, OK. Right, your example challenges delta to explain itself a bit! I mean, delta (being GIT_PAGER) has to handle every single line of output from git; not just diffs. And it promises to parse that output and decorate things. And yet, git itself encourages the structure of the output to be heavily customized. You can see that what delta does is extremely simple:

https://github.com/dandavison/delta/blob/e7d1e281ea539adb91a57c6945dea123fff1bd16/src/delta.rs#L114

So, what shall we do? I’m open to delta having fairly crazy technical options – it is a tool for programmers after all – as long as it doesn’t affect performance / UX in the default case. We could perhaps allow users to supply their own regular expression to match key sections of the output such as the commit line to be decorated? Or perhaps delta could inspect the format.pretty and derive a regular expression from that? But there’s perhaps no way to make that work for [alias] entries? If anyone reading feels like this area sounds fun to have a go at, please do shout out.

commit-regex is released now (delta 0.8.0)

@kbd I think you could use a record separator character (thanks, I do sometimes use zero-width space for hacks but I wasn’t familiar with the ASCII record separators). On the other hand something ad-hoc like this works for your l alias:

git -c delta.commit-regex='> [0-9a-f]{7,}$'

I’ve often thought it’s a shame that the separator characters included in ASCII are never used. They’d be a natural fit here if git had used them to delimit structure in git log. Eg. if a record separator preceded every commit it would save ad-hoc “starts with 'commit '” parsing.

I suppose that’d be the best way to use the regex with a custom log format? Add a separator character to the beginning of your log format and look for that in the regex?

Confirmed the behavior is fixed in 0.4.4 vs 0.4.3. Thanks!