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

Re: [PATCH 1/2] push: make non-fast-forward help message configurable

From
Jeff King <peff@peff.net>
Date
Sep 9, 2009, 20:39 UTC
Message-ID
<20090909203939.GA10438@sigill.intra.peff.net>
In-Reply-To
<7vr5ugszte.fsf@alter.siamese.dyndns.org>
On Wed, Sep 09, 2009 at 12:06:21PM -0700, Junio C Hamano wrote:
Show 21 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > diff --git a/advice.c b/advice.c
> > new file mode 100644
> > index 0000000..b5216a2
> > --- /dev/null
> > +++ b/advice.c
> > @@ -0,0 +1,25 @@
> > +#include "cache.h"
> > +
> > +int advice_push_nonfastforward = 1;
> > +
> > +static struct {
> > +	const char *name;
> > +	int *preference;
> > +} advice_config[] = {
> > +	{ "pushnonfastforward", &advice_push_nonfastforward },
> > +};
> 
> Can we have the value inside this struct, instead of having a pointer
> to another variable, and get rid of that variable altogether?

We could, but then callers need some way of indexing into the array. Which means either:

  - a constant offset (like "#define ADVICE_PUSH_NONFASTFORWARD 0"). The
    problem with that is you get no compile-time support for making sure
    that your index matches the variable you want. I.e., you have:
      { "pushnonfastforward", 1 } /* ADVICE_PUSH_NONFASTFORWARD */
    with the position in the array implicitly matching the manually
    assigned numbers.  We do have precedent in things like diff_colors.
    I don't remember if we have ever screwed it up.
  - a dynamic offset, like (as you noted):
Show 6 quoted lines
> If we did so, this part needs to become
> 
> 	if (nonfastforward && check_advice("pushnonfastforward")) {
> 
> which would be less efficient, but by definition advices are on the slow
> path, right?

which, as you note, is less efficient. It also turns typo-checking into a run-time error rather than a compile-time error, which is IMHO a bad idea. And if you care about such things, it is worse for using something like ctags to find variable uses.

I went the way I did because it provides compile-time checking, and because the variable is referred to by name in the table, the matching is explicit and thus harder to screw up.

One final option would be to get rid of the table altogether. Its function is to allow you to iterate over all of the variables. Now that the "advice.all" option has been dropped, the only use is during config parsing. We could simply unroll that loop to:

  if (!strcmp(k, "pushnonfastforward")) {
          advice_push_nonfastforward = git_config_bool(var, value);
          return 0;
  }
  if (!strcmp(k, "statushints")) {
          advice_status_hints = git_config_bool(var, value);
          return 0;
  }
as we do in other config parsing.
-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 44 of 48 in “push: point to 'git pull' and 'git push --force' in case of non-fast forward”
  1. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 6, 2009
  2. Michael J GruberAug 6, 2009
  3. Matthieu MoyAug 7, 2009
  4. Michael J GruberAug 7, 2009
  5. Junio C HamanoAug 6, 2009
  6. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 6, 2009
  7. Junio C HamanoAug 6, 2009
  8. Matthieu MoyAug 7, 2009
  9. Junio C HamanoAug 7, 2009
  10. Matthieu MoyAug 7, 2009
  11. push: point to 'git pull' and 'git push --force' in case of non-fast forwardMatthieu Moy, Aug 8, 2009
  12. Teemu LikonenAug 8, 2009
  13. Matthieu MoyAug 8, 2009
  14. Junio C HamanoAug 8, 2009
  15. Re: push: point to 'git pull' and 'git push --force' in case of non-fast forwardNicolas Sebrecht, Aug 8, 2009
  16. Matthieu MoyAug 9, 2009
  17. Junio C HamanoAug 9, 2009
  18. Matthieu MoyAug 10, 2009
  19. Junio C HamanoAug 10, 2009
  20. Matthieu MoyAug 10, 2009
  21. Nanako ShiraishiAug 11, 2009
  22. 0/4 make helpful messages optionalJeff King, Sep 6, 2009
  23. 1/4 push: fix english in non-fast-forward messageJeff King, Sep 6, 2009
  24. 2/4 push: re-flow non-fast-forward messageJeff King, Sep 6, 2009
  25. 3/4 push: make non-fast-forward help message configurableJeff King, Sep 6, 2009
  26. Junio C HamanoSep 6, 2009
  27. Jeff KingSep 6, 2009
  28. Junio C HamanoSep 6, 2009
  29. Jeff KingSep 6, 2009
  30. Junio C HamanoSep 6, 2009
  31. Sverre RabbelierSep 6, 2009
  32. Nanako ShiraishiSep 7, 2009
  33. Johannes SixtSep 7, 2009
  34. Mike HommeySep 7, 2009
  35. Jeff KingSep 7, 2009
  36. Matthieu MoySep 7, 2009
  37. Jeff KingSep 7, 2009
  38. Matthieu MoySep 7, 2009
  39. Uri OkrentSep 8, 2009
  40. Jeff KingSep 9, 2009
  41. 0/2 configurable advice messagesJeff King, Sep 9, 2009
  42. 1/2 push: make non-fast-forward help message configurableJeff King, Sep 9, 2009
  43. Junio C HamanoSep 9, 2009
  44. Jeff KingSep 9, 2009
  45. Junio C HamanoSep 9, 2009
  46. 2/2 status: make "how to stage" messages optionalJeff King, Sep 9, 2009
  47. 4/4 status: make "how to stage" messages optionalJeff King, Sep 6, 2009
  48. Matthieu MoySep 6, 2009

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.