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

Re: [PATCH 25/39] sha1_file: allow alt_odb_usable to handle arbitrary repositories

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 6, 2017, 20:01 UTC
Message-ID
<xmqqd1734mvg.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170830070812.GZ153983@aiede.mtv.corp.google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 27 quoted lines
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>  sha1_file.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/sha1_file.c b/sha1_file.c
> index e7c86e5363..b854cad970 100644
> --- a/sha1_file.c
> +++ b/sha1_file.c
> @@ -25,6 +25,7 @@
>  #include "repository.h"
>  #include "object-store.h"
>  #include "streaming.h"
> +#include "path.h"
>  #include "dir.h"
>  #include "mru.h"
>  #include "list.h"
> @@ -281,17 +282,18 @@ static const char *alt_sha1_path(struct alternate_object_database *alt,
>  /*
>   * Return non-zero iff the path is usable as an alternate object database.
>   */
> -#define alt_odb_usable(r, p, n) alt_odb_usable_##r(p, n)
> -static int alt_odb_usable_the_repository(struct strbuf *path,
> -					 const char *normalized_objdir)
> +static int alt_odb_usable(struct repository *r, struct strbuf *path,
> +			  const char *normalized_objdir)

These token-pasting macros introduced in 07-24/39 were certainly cute but they may be rather misleading and useless. e.g. a natural expectaion would be

	struct repository *r = &the_repository;
	prepare_alt_odb(r);

to work, but obviously it wouldn't. And this step and later in 25-39/39 corrects them one by one.

I suspect that you used the token-pasting cuteness because you thought that the callsite would not have to change in the later step like 25/39 that removes the trick. I also suspect that you thought that it may be a good thing that prepare_alt_odb(r) does not work immediately after 07/39, as the callee is not prepared. But both of these are misguided.

If you have two functions, A and B, that we want to update to eventually take a "struct repository *" argument, and if A uses B in its implementation, the endgame would be

	A(struct repository *r, ...)
	{
		...
		B(r, ...);
		...
	}

but with the ##r approach, the call to B in A in the initial token-pasting phase would say B(the_repository, ...) so the call will need to be changed in the step you update A's implementation to take a caller-supplied respotory object anyway. And the fact that a function's first parameter is not the_repository (i.e. leaving B()'s signature unchanged while it is not ready to take a repository) is sufficient to mark that a function is not yet prepared to take a caller-supplied repository object.

I found that this aspect of the structure of the series was somewhat irritating in that (1) combining the earlier ##r thing with its fix would have made the code that needs to be reviewed much cleaner, (2) it wouldn't have made the patch that longer, and most importantly (3) it is unclear why 24-7 != 39-25, i.e. it is hard to answer "is there any ##r hack still remaining after this series? if so why?"

The end-result of the whole series makes me think that it is going in the right direction, though.

Thanks.
Previous: Jonathan NiederNext: Stefan Beller
Message 30 of 46 in “per-repository object store, part 1”
  1. 00/39 per-repository object store, part 1Jonathan Nieder, Aug 30, 2017
  2. 01/39 pack: make packed_git_mru global a value instead of a pointerJonathan Nieder, Aug 30, 2017
  3. Jeff KingAug 30, 2017
  4. Junio C HamanoSep 6, 2017
  5. 02/39 repository: introduce object store fieldJonathan Nieder, Aug 30, 2017
  6. 03/39 object-store: move alt_odb_list and alt_odb_tail to object storeJonathan Nieder, Aug 30, 2017
  7. 04/39 object-store: move packed_git and packed_git_mru to object storeJonathan Nieder, Aug 30, 2017
  8. 05/39 pack: move prepare_packed_git_run_once to object storeJonathan Nieder, Aug 30, 2017
  9. 06/39 pack: move approximate object count to object storeJonathan Nieder, Aug 30, 2017
  10. 07/39 sha1_file: add repository argument to alt_odb_usableJonathan Nieder, Aug 30, 2017
  11. Brandon WilliamsAug 30, 2017
  12. 08/39 sha1_file: add repository argument to link_alt_odb_entryJonathan Nieder, Aug 30, 2017
  13. 09/39 sha1_file: add repository argument to read_info_alternatesJonathan Nieder, Aug 30, 2017
  14. 10/39 sha1_file: add repository argument to link_alt_odb_entriesJonathan Nieder, Aug 30, 2017
  15. 11/39 sha1_file: add repository argument to stat_sha1_fileJonathan Nieder, Aug 30, 2017
  16. 12/39 sha1_file: add repository argument to open_sha1_fileJonathan Nieder, Aug 30, 2017
  17. 13/39 sha1_file: add repository argument to map_sha1_file_1Jonathan Nieder, Aug 30, 2017
  18. 14/39 sha1_file: add repository argument to sha1_loose_object_infoJonathan Nieder, Aug 30, 2017
  19. 15/39 object-store: add repository argument to prepare_alt_odbJonathan Nieder, Aug 30, 2017
  20. 16/39 object-store: add repository argument to foreach_alt_odbJonathan Nieder, Aug 30, 2017
  21. 17/39 pack: add repository argument to install_packed_gitJonathan Nieder, Aug 30, 2017
  22. 18/39 pack: add repository argument to prepare_packed_git_oneJonathan Nieder, Aug 30, 2017
  23. 19/39 pack: add repository argument to rearrange_packed_gitJonathan Nieder, Aug 30, 2017
  24. 20/39 pack: add repository argument to prepare_packed_git_mruJonathan Nieder, Aug 30, 2017
  25. 21/39 pack: add repository argument to prepare_packed_gitJonathan Nieder, Aug 30, 2017
  26. 22/39 pack: add repository argument to reprepare_packed_gitJonathan Nieder, Aug 30, 2017
  27. 23/39 pack: add repository argument to sha1_file_nameJonathan Nieder, Aug 30, 2017
  28. 24/39 pack: add repository argument to map_sha1_fileJonathan Nieder, Aug 30, 2017
  29. 25/39 sha1_file: allow alt_odb_usable to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  30. Junio C HamanoSep 6, 2017
  31. Stefan BellerSep 6, 2017
  32. 26/39 object-store: allow prepare_alt_odb to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  33. 27/39 object-store: allow foreach_alt_odb to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  34. 28/39 pack: allow install_packed_git to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  35. 29/39 pack: allow rearrange_packed_git to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  36. 30/39 pack: allow prepare_packed_git_mru to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  37. 31/39 pack: allow prepare_packed_git_one to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  38. 32/39 pack: allow prepare_packed_git to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  39. 33/39 pack: allow reprepare_packed_git to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  40. 34/39 pack: allow sha1_file_name to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  41. 35/39 pack: allow stat_sha1_file to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  42. 36/39 pack: allow open_sha1_file to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  43. 37/39 pack: allow map_sha1_file_1 to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  44. 38/39 pack: allow map_sha1_file to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  45. 39/39 pack: allow sha1_loose_object_info to handle arbitrary repositoriesJonathan Nieder, Aug 30, 2017
  46. Brandon WilliamsAug 30, 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.