Re: [RFC/PATCH 07/11] branch: move 'current' check down to the presentation layer
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Jul 29, 2015, 18:52 UTC
- Message-ID
- <CAOLa=ZRUnF12gO=AKg3E373XETqoykqOXSkPvr7DHCVrOeggAA@mail.gmail.com>
- In-Reply-To
- <vpqk2tjmgeg.fsf@anie.imag.fr>
On Wed, Jul 29, 2015 at 3:31 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:
Show 34 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes: > >> On Tue, Jul 28, 2015 at 6:39 PM, Matthieu Moy >> <Matthieu.Moy@grenoble-inp.fr> wrote: >>> Karthik Nayak <karthik.188@gmail.com> writes: >>> >>>> We check if given ref is the current branch in print_ref_list(). Move >>>> this check to print_ref_item() where it is checked right before >>>> printing. >>> >>> This means that the '*' and the different color are coded in C, hence >>> it's not possible to mimick this using "git for-each-ref --format ...". >>> >>> I do not consider this as blocking, but I think the ultimate goal should >>> be to allow this, so that all the goodies of "git branch" can be made >>> available to other ref-listing commands. >>> >> >> Not sure what you mean here. > > What you already know, but probably badly explained ;-). > > Eventually, the output of "git branch" should correspond to a format > string (so git branch would be almost an alias for "git for-each-ref > refs/heads/ --format '...'"). Internally, this would mean using > show_ref_array_item instead of print_ref_item. This is what you managed > to do for "git tag". > > You already identified one difficulty with sha1 alignment in "git branch > -v". I'm pointing out another which is that displaying the "*" in front > of the current branch is currently not possible with a format string. > You would need an atom like %(displayAStarIfTheBranchIsTheCurrentOne) > (for which you'd need to find a short-and-sweet name ;-) ). >
What I was thinking of was something like this :
struct strbuf format = STRBUF_INIT;
char c = ' ';
if (current)
c = '*';
strbuf_addf(&format, "%c....", c, other format options...);
show_ref_array_item(item, format.buf, quote_style, 0);
strbuf_release(&format);This would remove the need of making the printing of the "*" to be needed by ref-filter. As this is only needed in branch.c
If going on what you're saying we could have a "%(starifcurrent)" atom or something, but I don't see a general use for this.
-- Regards, Karthik Nayak