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

Re: [PATCH v2 16/21] Make sha1_array_append take a struct object_id *

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Mar 29, 2017, 00:06 UTC
Message-ID
<20170329000648.vb2hdqfizjqjyryr@genre.crustytoothpaste.net>
In-Reply-To
<xmqq7f39e2gi.fsf@gitster.mtv.corp.google.com>
On Tue, Mar 28, 2017 at 10:27:41AM -0700, Junio C Hamano wrote:
Show 46 quoted lines
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > Convert the callers to pass struct object_id by changing the function
> > declaration and definition and applying the following semantic patch:
> >
> > @@
> > expression E1, E2, E3;
> > @@
> > - sha1_array_append(E1, E2[E3].hash)
> > + sha1_array_append(E1, E2 + E3)
> >
> > @@
> > expression E1, E2;
> > @@
> > - sha1_array_append(E1, E2.hash)
> > + sha1_array_append(E1, &E2)
> 
> I noticed something similar in the change to bisect.c while reading
> the previous step, and I suspect that the above two rules leave
> somewhat inconsistent and harder-to-read result.  Wouldn't it make
> the result more readable if the former rule were
> 
>     -sha1_array_append(E1, E2[E3].hash)
>     +sha1_array_append(E1, &E2[E3])
> 
> 
> FWIW, the bit that made me read it twice in the previous step was
> this change
> 
> -		strbuf_addstr(&joined_hexs, sha1_to_hex(array->sha1[i]));
> +		strbuf_addstr(&joined_hexs, oid_to_hex(array->oid + i));
> 
> which I would have written &(array->oid[i]) instead.
> 
> After all, the original written by a human said E2[E3].hash (or
> array->sha1[i]) because to the human's mind, E2 is a series of
> things that can be indexed with an int E3, and even though 
> 
>     *(E2 + E3)
>     E2[E3]
>     E3[E2]
> 
> all mean the same thing, the human decided that E2[E3] is the most
> natural way to express this particular reference to an item in the
> array.  &E2[E3] would keep that intention by the original author
> better than E2 + E3.

I'm happy to make that change. I'm an experienced C programmer, so a pointer addition seems very readable and natural to me, but if you think it's better or more readable as &E2[E3], I can certainly reroll.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 40 in “object_id part 7”
  1. 00/21 object_id part 7brian m. carlson, Mar 26, 2017
  2. 08/21 fsck: convert init_skiplist to struct object_idbrian m. carlson, Mar 26, 2017
  3. 12/21 sha1_name: convert disambiguate_hint_fn to take object_idbrian m. carlson, Mar 26, 2017
  4. 16/21 Make sha1_array_append take a struct object_id *brian m. carlson, Mar 26, 2017
  5. Jeff KingMar 28, 2017
  6. Junio C HamanoMar 28, 2017
  7. brian m. carlsonMar 29, 2017
  8. Junio C HamanoMar 29, 2017
  9. brian m. carlsonMar 29, 2017
  10. 09/21 parse-options-cb: convert sha1_array_append caller to struct object_idbrian m. carlson, Mar 26, 2017
  11. 18/21 Convert sha1_array_lookup to take struct object_idbrian m. carlson, Mar 26, 2017
  12. 17/21 Convert remaining callers of sha1_array_lookup to object_idbrian m. carlson, Mar 26, 2017
  13. 10/21 test-sha1-array: convert most code to struct object_idbrian m. carlson, Mar 26, 2017
  14. 21/21 Documentation: update and rename api-sha1-array.txtbrian m. carlson, Mar 26, 2017
  15. 07/21 builtin/receive-pack: convert portions to struct object_idbrian m. carlson, Mar 26, 2017
  16. Jeff KingMar 28, 2017
  17. brian m. carlsonMar 29, 2017
  18. Jeff KingMar 30, 2017
  19. 20/21 Rename sha1_array to oid_arraybrian m. carlson, Mar 26, 2017
  20. 05/21 builtin/pull: convert portions to struct object_idbrian m. carlson, Mar 26, 2017
  21. 19/21 Convert sha1_array_for_each_unique and for_each_abbrev to object_idbrian m. carlson, Mar 26, 2017
  22. 06/21 builtin/receive-pack: fix incorrect pointer arithmeticbrian m. carlson, Mar 26, 2017
  23. Jeff KingMar 28, 2017
  24. Junio C HamanoMar 28, 2017
  25. 14/21 builtin/pull: convert to struct object_idbrian m. carlson, Mar 26, 2017
  26. 01/21 Define new hash-size constants for allocating memorybrian m. carlson, Mar 26, 2017
  27. 03/21 Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZbrian m. carlson, Mar 26, 2017
  28. 11/21 sha1_name: convert struct disambiguate_state to object_idbrian m. carlson, Mar 26, 2017
  29. 15/21 sha1-array: convert internal storage for struct sha1_array to object_idbrian m. carlson, Mar 26, 2017
  30. Jeff KingMar 28, 2017
  31. 13/21 submodule: convert check_for_new_submodule_commits to object_idbrian m. carlson, Mar 26, 2017
  32. 02/21 Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZbrian m. carlson, Mar 26, 2017
  33. 04/21 builtin/diff: convert to struct object_idbrian m. carlson, Mar 26, 2017
  34. Jeff KingMar 28, 2017
  35. brian m. carlsonMar 28, 2017
  36. Jeff KingMar 28, 2017
  37. Jeff KingMar 28, 2017
  38. Junio C HamanoMar 28, 2017
  39. Jeff KingMar 28, 2017
  40. Junio C HamanoMar 28, 2017

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.