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

Re: [PATCH v3 00/20] refs backend rebase on pu

From
Jeff King <peff@peff.net>
Date
Feb 4, 2016, 02:58 UTC
Message-ID
<20160204025821.GA21105@sigill.intra.peff.net>
In-Reply-To
<56B2AF64.5020502@ramsayjones.plus.com>
On Thu, Feb 04, 2016 at 01:54:44AM +0000, Ramsay Jones wrote:
Show 11 quoted lines
> > They were working for me as-of the time I sent them.  I guess something
> > must have broken since.  I'll rebase, test, and send a new series.
> 
> I didn't spend too long looking at it, but I think this interacts with
> Jeff's patch a2d5156c ("resolve_gitlink_ref: ignore non-repository paths",
> 22-01-2016) which introduces the new test in 't3000-ls-files-others.sh'
> which fails for me.
> 
> The change which Jeff made to resolve_gitlink_ref() is effectively side-stepped
> by the call to check_submodule_backend() in the new resolve_gitlink_ref().
> (Jeff's change is now in the 'files' backend version of resolve_gitlink_ref()).

Yeah. The check_submodule_backend() function calls strbuf_git_path_submodule(), which unconditionally requires that the path be an actual submodule (the irony being that we are using it to find out whether we have a submodule!). So I don't think there's a conflict between our code, so much as that the new code has the same bug I fixed in a2d5156c (and we didn't notice earlier, because there was no test).

The solution in a2d5156 is to use is_nonbare_repository_dir() before assuming we have a submodule. I think check_submodule_backend() would want to do the same thing. This is the minimal fix:

diff --git a/refs.c b/refs.c
index 3d4c0a6..7f86c49 100644
--- a/refs.c
+++ b/refs.c
@@ -313,9 +313,8 @@ static void check_submodule_backend(const char *submodule)
 	if (!submodule)
 		goto done;
 
-	strbuf_git_path_submodule(&sb, submodule, "%s", "");
-
-	if (!is_git_directory(sb.buf))
+	strbuf_addstr(&sb, submodule);
+	if (!is_nonbare_repository_dir(&sb))
 		goto done;
 
 	strbuf_reset(&sb);


That gets the test passing. But I noticed a few other things, some
related and some unrelated, while looking at this function:

  - in files_resolve_gitlink_ref, if we do find a submodule, we cache
    the result with the ref_cache code. But here, we would read the .git
    file repeatedly (and in fact, it happens twice per call, as
    submodule_git_path has to read it itself).

    I don't know if it would be worth adding any kind of caching at this
    layer.  It may be that we don't typically resolve more than one ref
    (or do more than one for_each_ref iteration) for a submodule, so the
    cache is pointless. I didn't implement it specifically in a2d5156,
    it just came for free with the existing ref_cache code.

  - check_submodule_backend knows whether we have a submodule at all and
    is worth proceeding, but does not tell its callers. So we'll end up
    in the backend files_resolve_gitlink_ref and make the same check.
    It's probably worth moving this logic to the outer layer so each
    backend doesn't have to implement it (and then the check in
    files_resolve_gitlink_ref can actually go away).

  - for the common case of submodule==NULL (i.e., the main repository),
    check_submodule_backend should be a noop, but it allocates and frees
    the submodule_storage_backend string. Probably not a huge deal, but
    it can be easily bumped down, and the first "goto done" turned into
    a "return".

  - if the submodule does have a backend configured, we leak the memory
    for the default string. I think the submodule_backend() config
    callback needs to free() the previous value.

  - the config callback unconditionally dereferences "value", which will
    segfault if the submodule's extensions.refstorage is a pure boolean
    like:

        [extensions]
	refstorage

    That should never happen, of course, but we should be checking and
    dying for "!value" rather than segfaulting. Using
    git_config_string() will do this for you.

Hope that helps.

-Peff
Previous: Ramsay JonesNext: David Turner
Message 42 of 49 in “refs backend rebase on pu”
  1. 00/20 refs backend rebase on puDavid Turner, Jan 14, 2016
  2. 01/20 refs: add a backend method structure with transaction functionsDavid Turner, Jan 14, 2016
  3. 02/20 refs: add methods for misc ref operationsDavid Turner, Jan 14, 2016
  4. 03/20 refs: add methods for the ref iteratorsDavid Turner, Jan 14, 2016
  5. 04/20 refs: add do_for_each_per_worktree_refDavid Turner, Jan 14, 2016
  6. 05/20 refs: add methods for reflogDavid Turner, Jan 14, 2016
  7. 06/20 refs: add method for initial ref transaction commitDavid Turner, Jan 14, 2016
  8. 07/20 refs: add method for delete_refsDavid Turner, Jan 14, 2016
  9. 08/20 refs: add methods to init refs dbDavid Turner, Jan 14, 2016
  10. 09/20 refs: add method to rename refsDavid Turner, Jan 14, 2016
  11. 10/20 refs: make lock genericDavid Turner, Jan 14, 2016
  12. 11/20 refs: move duplicate check to common codeDavid Turner, Jan 14, 2016
  13. 12/20 refs: allow log-only updatesDavid Turner, Jan 14, 2016
  14. 13/20 refs: resolve symbolic refs firstDavid Turner, Jan 14, 2016
  15. Jeff KingFeb 4, 2016
  16. David TurnerFeb 4, 2016
  17. 14/20 refs: always handle non-normal refs in files backendDavid Turner, Jan 14, 2016
  18. 15/20 init: allow alternate backends to be set for new reposDavid Turner, Jan 14, 2016
  19. SZEDER GáborJan 15, 2016
  20. Thomas GummererJan 15, 2016
  21. David TurnerJan 19, 2016
  22. Duy NguyenFeb 4, 2016
  23. David TurnerFeb 4, 2016
  24. 16/20 refs: check submodules ref storage configDavid Turner, Jan 14, 2016
  25. 17/20 refs: allow ref backend to be set for cloneDavid Turner, Jan 14, 2016
  26. SZEDER GáborJan 15, 2016
  27. David TurnerJan 19, 2016
  28. SZEDER GáborJan 21, 2016
  29. 18/20 svn: learn ref-storage argumentDavid Turner, Jan 14, 2016
  30. SZEDER GáborJan 15, 2016
  31. 19/20 refs: add LMDB refs backendDavid Turner, Jan 14, 2016
  32. Thomas GummererJan 15, 2016
  33. David TurnerJan 19, 2016
  34. Duy NguyenFeb 4, 2016
  35. David TurnerFeb 4, 2016
  36. 20/20 refs: tests for lmdb backendDavid Turner, Jan 14, 2016
  37. David TurnerFeb 2, 2016
  38. Junio C HamanoFeb 2, 2016
  39. Junio C HamanoFeb 4, 2016
  40. David TurnerFeb 4, 2016
  41. Ramsay JonesFeb 4, 2016
  42. Jeff KingFeb 4, 2016
  43. David TurnerFeb 4, 2016
  44. Duy NguyenFeb 4, 2016
  45. David TurnerFeb 4, 2016
  46. Duy NguyenFeb 4, 2016
  47. David TurnerFeb 4, 2016
  48. Ramsay JonesFeb 4, 2016
  49. David TurnerFeb 4, 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.