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

Re: [PATCH v8 7/8] cache: add empty_tree_oid object

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 19, 2016, 20:31 UTC
Message-ID
<xmqqfuq01oww.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160819000031.24854-8-jacob.e.keller@intel.com>
Jacob Keller <jacob.e.keller@intel.com> writes:
Show 5 quoted lines
> From: Jacob Keller <jacob.keller@gmail.com>
>
> Add an empty_tree_oid object which can be used in place of
> EMPTY_TREE_SHA1_BIN_LITERAL for code which is being converted to struct
> object_id.

How widely do you envision the users of this symbol would be spread across the entire codebase? I am debating myself if we need a singleton in-core copy like this (if we end up referring to it from everywhere), or we only need one level higher abstraction, e.g. "is_empty_tree_oid()" helper (in which case I do not think we even need a singleton; just imitate how is_empty_blob_sha1() is implemented).

Even if we need such a singleton, I think we avoid ".field = value" struct initializations in our code.

Show 34 quoted lines
>
> Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
> ---
>  cache.h     | 2 ++
>  sha1_file.c | 3 +++
>  2 files changed, 5 insertions(+)
>
> diff --git a/cache.h b/cache.h
> index f30a4417efdf..da9f0be67d7b 100644
> --- a/cache.h
> +++ b/cache.h
> @@ -964,6 +964,8 @@ static inline void oidclr(struct object_id *oid)
>  #define EMPTY_BLOB_SHA1_BIN \
>  	((const unsigned char *) EMPTY_BLOB_SHA1_BIN_LITERAL)
>  
> +extern const struct object_id empty_tree_oid;
> +
>  static inline int is_empty_blob_sha1(const unsigned char *sha1)
>  {
>  	return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
> diff --git a/sha1_file.c b/sha1_file.c
> index 1e23fc186a02..10883d56a600 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -38,6 +38,9 @@ static inline uintmax_t sz_fmt(size_t s) { return s; }
>  
>  const unsigned char null_sha1[20];
>  const struct object_id null_oid;
> +const struct object_id empty_tree_oid = {
> +	.hash = EMPTY_TREE_SHA1_BIN_LITERAL
> +};
>  
>  /*
>   * This is meant to hold a *small* number of objects that you would
Previous: Jacob KellerNext: Jacob Keller
Message 10 of 28 in “submodule show inline diff”
  1. 0/8 submodule show inline diffJacob Keller, Aug 19, 2016
  2. 6/8 submodule: refactor show_submodule_summary with helper functionJacob Keller, Aug 19, 2016
  3. Junio C HamanoAug 19, 2016
  4. Jacob KellerAug 19, 2016
  5. 1/8 diff.c: remove output_prefix_length fieldJacob Keller, Aug 19, 2016
  6. 3/8 diff: prepare for additional submodule formatsJacob Keller, Aug 19, 2016
  7. Junio C HamanoAug 19, 2016
  8. 2/8 graph: add support for --line-prefix on all graph-aware outputJacob Keller, Aug 19, 2016
  9. 7/8 cache: add empty_tree_oid objectJacob Keller, Aug 19, 2016
  10. Junio C HamanoAug 19, 2016
  11. Jacob KellerAug 19, 2016
  12. Junio C HamanoAug 19, 2016
  13. Junio C HamanoAug 19, 2016
  14. Jacob KellerAug 19, 2016
  15. Jeff KingAug 19, 2016
  16. Junio C HamanoAug 23, 2016
  17. 5/8 submodule: convert show_submodule_summary to use struct object_id *Jacob Keller, Aug 19, 2016
  18. Junio C HamanoAug 19, 2016
  19. 8/8 diff: teach diff to display submodule difference with an inline diffJacob Keller, Aug 19, 2016
  20. Junio C HamanoAug 19, 2016
  21. Jacob KellerAug 19, 2016
  22. 4/8 submodule: allow add_submodule_odb to work even if path is not checked outJacob Keller, Aug 19, 2016
  23. Junio C HamanoAug 19, 2016
  24. Jacob KellerAug 19, 2016
  25. Junio C HamanoAug 19, 2016
  26. Jacob KellerAug 19, 2016
  27. Junio C HamanoAug 19, 2016
  28. Jacob KellerAug 19, 2016

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.