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

Re* [PATCH v4] submodule: port subcommand 'set-url' from shell to C

From
Junio C Hamano <gitster@pobox.com>
Date
May 8, 2020, 15:18 UTC
Message-ID
<xmqq8si21mlz.fsf_-_@gitster.c.googlers.com>
In-Reply-To
<CAP8UFD0=_8D8hkT5VVPV_F++dr131bkjby357fA+QfhQxktcMg@mail.gmail.com>
Christian Couder <christian.couder@gmail.com> writes:
Show 14 quoted lines
> On Fri, May 8, 2020 at 7:51 AM Shourya Shukla
> <shouryashukla.oo@gmail.com> wrote:
>>
>> On 06/05 10:08, Junio C Hamano wrote:
>
>> > Specifically, I would write "!path", not "path == NULL".  I thought
>> > a rule for that is in the CodingGuidelines (I didn't double check,
>> > though).
>>
>> I could not find a rule like that in the CodingGuidelines.
>> Should I add it?
>> https://github.com/git/git/blob/master/Documentation/CodingGuidelines
>
> Sure.

I'd rather not see too many unrelated things piled up on Shourya's plate. Without guidance, the new entry we'll see would be only about comparing with NULL, and we'd need to spend review cycles correcting that, too.

How about something like this, perhaps?
-- >8 --
CodingGuidelines: do not ==/!= compare with 0/NULL
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/CodingGuidelines | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 390ceece52..41a89dd845 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -236,6 +236,19 @@ For C programs:
         while( condition )
 		func (bar+1);
 
+ - Do not explicitly compare an integral value with constant 0 or a
+   pointer value with constant NULL for equality; just say !value
+   instead.  To validate a counted array at ptr that has cnt elements
+   in it, write:
+
+	if (!ptr || !cnt)
+		BUG("array should not be empty at this point");
+
+   and not:
+
+	if (ptr == NULL || cnt == 0);
+		BUG("array should not be empty at this point");
+
  - We avoid using braces unnecessarily.  I.e.
 
 	if (bla) {
Previous: Christian CouderNext: Eric Sunshine
Message 12 of 22 in “submodule: port subcommand 'set-url' from shell to C”
  1. submodule: port subcommand 'set-url' from shell to CShourya Shukla, May 6, 2020
  2. Christian CouderMay 6, 2020
  3. Shourya ShuklaMay 6, 2020
  4. Junio C HamanoMay 6, 2020
  5. Junio C HamanoMay 6, 2020
  6. Shourya ShuklaMay 6, 2020
  7. Junio C HamanoMay 6, 2020
  8. Shourya ShuklaMay 7, 2020
  9. Junio C HamanoMay 7, 2020
  10. Shourya ShuklaMay 8, 2020
  11. Christian CouderMay 8, 2020
  12. Re* [PATCH v4] submodule: port subcommand 'set-url' from shell to CJunio C Hamano, May 8, 2020
  13. Eric SunshineMay 8, 2020
  14. Junio C HamanoMay 8, 2020
  15. Eric SunshineMay 8, 2020
  16. Junio C HamanoMay 8, 2020
  17. Eric SunshineMay 8, 2020
  18. submodule: port subcommand 'set-url' from shell to CShourya Shukla, May 8, 2020
  19. Denton LiuMay 8, 2020
  20. Junio C HamanoMay 8, 2020
  21. Junio C HamanoMay 8, 2020
  22. submodule: port subcommand 'set-url' from shell to CJunio C Hamano, May 8, 2020

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.