Re: [PATCH] for-each-ref: introduce color format
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- May 19, 2013, 12:05 UTC
- Message-ID
- <CACsJy8CthvpJh6QM+umxY_Gq7nc-rGZ+Tcp7zAkadez-g+FFjQ@mail.gmail.com>
- In-Reply-To
- <1368802552-16024-1-git-send-email-artagnon@gmail.com>
On Fri, May 17, 2013 at 9:55 PM, Ramkumar Ramachandra <artagnon@gmail.com> wrote:
Show 27 quoted lines
> You can now do something like > > $ git for-each-ref --format='%C(red)%(refname:short)%C(reset) > %C(blue)%(upstream:diff)%C(reset)' --count 5 --sort='-committerdate' > refs/heads > > To get output that's much more customizable 'git branch' output. Future > patches will attempt unify the semantics of 'git branch' and 'git > for-each-ref'. > > Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> > --- > So my evil plan is to keep extending this format until it's on par > with pretty-formats. Then, we can move towards unifying 'git branch' > and 'git for-each-ref'. This will involve deprecating badly > thought-out options like '-v', and replacing it with the more > powerful '--format'. > > I just have one major doubt: in the above output, how do I align all > the upstream branches to the same column? How can I achieve it with > pretty-formats? Something like %*d? But * is already taken to mean > deref in for-each-ref's --format. > > By the way, the main motivation for all this comes from the fact that > git for-each-ref is very nicely written :) Look at how it breaks > everything up into atoms and lazily gets the information it needs to > display.
If you can put energy into this, I suggest you improve pretty.c a bit, adding new format_ref_message(), similar to format_commit_message(), except that it takes a ref. You can extend "struct format_commit_context" to contain what "struct refinfo" does. I think pretty.c only lacks a few specifiers that for-each-ref has. I think I mentioned it in my for-each-ref series already, but we need to think how to specify "align to the left with the best width" and how format_ref_message() can figure the width out. A callback function might do. -- Duy