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

Re: [PATCH] color.h: document and modernize header

From
Stefan Beller <sbeller@google.com>
Date
Feb 8, 2018, 21:04 UTC
Message-ID
<CAGZ79kb+xEVZagqqNCHCPQUbfH89N7fdrO7dp6WHRGgJJje28Q@mail.gmail.com>
In-Reply-To
<20180208204309.GA4541@sigill.intra.peff.net>
On Thu, Feb 8, 2018 at 12:43 PM, Jeff King <peff@peff.net> wrote:
Show 23 quoted lines
> On Thu, Feb 08, 2018 at 12:15:46PM -0800, Stefan Beller wrote:
>
>>  int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
>>  {
>>       va_list args;
>> diff --git a/color.h b/color.h
>> index fd2b688dfb..8c7e6c41c2 100644
>> --- a/color.h
>> +++ b/color.h
>> @@ -72,26 +72,50 @@ extern int color_stdout_is_tty;
>>   * Use the first one if you need only color config; the second is a convenience
>>   * if you are just going to change to git_default_config, too.
>>   */
>> -int git_color_config(const char *var, const char *value, void *cb);
>> -int git_color_default_config(const char *var, const char *value, void *cb);
>> +extern int git_color_config(const char *var, const char *value, void *cb);
>> +extern int git_color_default_config(const char *var, const char *value, void *cb);
>
> Hmph, I thought we weren't adding "extern" everywhere. See:
>
>   https://public-inbox.org/git/xmqq8tea5hxi.fsf@gitster.mtv.corp.google.com/
>
> Other than that, these changes mostly look like improvements. A few
...
> Those are all suggestions. Given that there's no documentation currently
> on most of these, I think even if you don't take any of my suggestions,
> this would still be a net improvement (modulo the "extern" thing).
A funny and sad rant about why clear communication matters:

[Once upon a time, maybe 2 years ago] I had the impression that the old code is nicely written and was consistently marked extern in header files. (which btw is consistent with variable declarations, they need the extern). All the new code doesn't make use of extern, so I had this on my low prio todo list, that eventually all code converges to have 'extern' functions in headers.

C.f. the following commits, found via
  git log -p --author=Beller -S extern
  5ec8274b84 (xdiff-interface: export comparing and hashing strings,
  2017-10-25) adding new externs
  1ecbf31d02 (hashmap: migrate documentation from Documentation/technical
  into header, 2017-06-30), a cleanup, which doesn't touch externs
  a6d7eb2c7a (pull: optionally rebase submodules (remote submodule
  changes only), 2017-06-23) new code using externs
  bd26756112 (submodule.h: add extern keyword to functions, 2016-12-20)
  (The commit message is as accurate as it gets)

You may sense a pattern here: I currently have the very firm understanding we use the extern keyword in our codebase.

And I can also attest that this was not always the case, as back in the day I remember writing patches without the extern keyword only to be told: (A) be similar to the function in the next lines (B) the standard is to use extern and I was convinced it was a bad decision to prefix declarations with the extern keyword, but followed along as I don't want to have style in the way of writing features.

  $ cat Documentation/CodingGuidelines |grep extern
  $ # oh no it's empty!
Care to add a section to our coding guidelines?

Thanks, Stefan

Previous: Jeff KingNext: Jeff King
Message 3 of 16 in “color.h: document and modernize header”
  1. color.h: document and modernize headerStefan Beller, Feb 8, 2018
  2. Jeff KingFeb 8, 2018
  3. Stefan BellerFeb 8, 2018
  4. CodingGuidelines: mention "static" and "extern"Jeff King, Feb 8, 2018
  5. Stefan BellerFeb 8, 2018
  6. Eric SunshineFeb 8, 2018
  7. Jonathan TanFeb 9, 2018
  8. Jeff KingFeb 9, 2018
  9. Eric SunshineFeb 8, 2018
  10. Jeff KingFeb 8, 2018
  11. color.h: document and modernize headerStefan Beller, Feb 12, 2018
  12. Eric SunshineFeb 12, 2018
  13. color.h: document and modernize headerStefan Beller, Feb 13, 2018
  14. Eric SunshineFeb 13, 2018
  15. Eric SunshineFeb 14, 2018
  16. Stefan BellerFeb 14, 2018

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.