git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 8/9] branch: use ref-filter printing APIs

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Oct 6, 2015, 19:03 UTC
Message-ID
<vpqmvvvhl9m.fsf@grenoble-inp.fr>
In-Reply-To
<CAOLa=ZS5x=ksfnBt1kLp5bJJHmqeBztR7Zn7U5VKZN-56T-_5A@mail.gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
> If you look closely, thats only for the local branches, the remotes
> have `align` atom when
> printing in verbose.

Yes, but that's already one thing factored out of the if, even if it's just for local.

Actually, I think you can also factor some parts out of the %(if:notequals=remotes). In 'local', you have an %(if) to display either "* " or " ", and in remote you always start with " ". Why not always apply the %(if), and let it display " " if not displaying the current branch? Similarly, the "verbose" part of remote branches seems like a particular case of the one for local ones (remotes don't have tracking branches, so the tracking info should expand to the empty string).

To go a bit further, you can pre-build a string or strbuf aligned_short with value like "%%(align:20,left)%%(refname:short)%%(end)" and use it where needed (it's not a constant because you have to introduce maxwidth into the string, so it's not a candidate for #define).

> I could cook up this:

Your mailer broke the formatting, so it looks terrible, but from what I could parse, it's already much better than the previous one. It's not a matter of size of the function, I very much prefer reading 10 lines of nice code than 4 lines like

Show 5 quoted lines
> +                        local = xstrfmt("%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)%%(align:%d,left)%%(refname:short)%%(end)%s"
> +                                        " %%(objectname:short,7) %%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s] %%(end)"
> +                                        "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)",
> +                                        branch_get_color(BRANCH_COLOR_CURRENT), maxwidth, branch_get_color(BRANCH_COLOR_RESET),
> +                                        branch_get_color(BRANCH_COLOR_UPSTREAM), branch_get_color(BRANCH_COLOR_RESET));
;-).

One obvious issue with the initial version was this big hard-to-parse block, but another one is that the code did not make it easy to understand what was changing depending on which branch of the if, and depending on local/remote. It's getting much easier already.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Karthik NayakNext: Karthik Nayak
Message 39 of 43 in “port branch.c to use ref-filter printing APIs”
  1. 0/9 port branch.c to use ref-filter printing APIsKarthik Nayak, Oct 2, 2015
  2. 1/9 ref-filter: implement %(if), %(then), and %(else) atomsKarthik Nayak, Oct 2, 2015
  3. Junio C HamanoOct 2, 2015
  4. Karthik NayakOct 3, 2015
  5. Matthieu MoyOct 3, 2015
  6. Junio C HamanoOct 3, 2015
  7. Matthieu MoyOct 4, 2015
  8. Junio C HamanoOct 4, 2015
  9. Karthik NayakOct 4, 2015
  10. 2/9 ref-filter: implement %(if:equals=<string>) and %(if:notequals=<string>)Karthik Nayak, Oct 2, 2015
  11. Junio C HamanoOct 2, 2015
  12. Karthik NayakOct 3, 2015
  13. 3/9 ref-filter: add support for %(path) atomKarthik Nayak, Oct 2, 2015
  14. Matthieu MoyOct 3, 2015
  15. Karthik NayakOct 4, 2015
  16. Matthieu MoyOct 4, 2015
  17. Junio C HamanoOct 4, 2015
  18. Matthieu MoyOct 5, 2015
  19. Karthik NayakOct 4, 2015
  20. 4/9 ref-filter: modify "%(objectname:short)" to take lengthKarthik Nayak, Oct 2, 2015
  21. Junio C HamanoOct 2, 2015
  22. Karthik NayakOct 3, 2015
  23. 5/9 ref-filter: adopt get_head_description() from branch.cKarthik Nayak, Oct 2, 2015
  24. 6/9 ref-filter: introduce format_ref_array_item()Karthik Nayak, Oct 2, 2015
  25. Matthieu MoyOct 3, 2015
  26. Karthik NayakOct 5, 2015
  27. Matthieu MoyOct 5, 2015
  28. Karthik NayakOct 6, 2015
  29. Matthieu MoyOct 6, 2015
  30. Karthik NayakOct 6, 2015
  31. 7/9 ref-filter: make %(upstream:track) prints "[gone]" for invalid upstreamsKarthik Nayak, Oct 2, 2015
  32. Matthieu MoyOct 3, 2015
  33. Karthik NayakOct 5, 2015
  34. 8/9 branch: use ref-filter printing APIsKarthik Nayak, Oct 2, 2015
  35. Matthieu MoyOct 3, 2015
  36. Karthik NayakOct 5, 2015
  37. Matthieu MoyOct 5, 2015
  38. Karthik NayakOct 6, 2015
  39. Matthieu MoyOct 6, 2015
  40. Karthik NayakOct 7, 2015
  41. Matthieu MoyOct 7, 2015
  42. Karthik NayakOct 7, 2015
  43. 9/9 branch: implement '--format' optionKarthik Nayak, Oct 2, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.