All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>
Cc: David Turner <dturner@twopensource.com>,
	Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org, mhagger@alum.mit.edu
Subject: Re: [PATCH v3 00/20] refs backend rebase on pu
Date: Wed, 3 Feb 2016 21:58:21 -0500	[thread overview]
Message-ID: <20160204025821.GA21105@sigill.intra.peff.net> (raw)
In-Reply-To: <56B2AF64.5020502@ramsayjones.plus.com>

On Thu, Feb 04, 2016 at 01:54:44AM +0000, Ramsay Jones wrote:

> > 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

  reply	other threads:[~2016-02-04  2:58 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14 16:25 [PATCH v3 00/20] refs backend rebase on pu David Turner
2016-01-14 16:25 ` [PATCH v3 01/20] refs: add a backend method structure with transaction functions David Turner
2016-01-14 16:25 ` [PATCH v3 02/20] refs: add methods for misc ref operations David Turner
2016-01-14 16:26 ` [PATCH v3 03/20] refs: add methods for the ref iterators David Turner
2016-01-14 16:26 ` [PATCH v3 04/20] refs: add do_for_each_per_worktree_ref David Turner
2016-01-14 16:26 ` [PATCH v3 05/20] refs: add methods for reflog David Turner
2016-01-14 16:26 ` [PATCH v3 06/20] refs: add method for initial ref transaction commit David Turner
2016-01-14 16:26 ` [PATCH v3 07/20] refs: add method for delete_refs David Turner
2016-01-14 16:26 ` [PATCH v3 08/20] refs: add methods to init refs db David Turner
2016-01-14 16:26 ` [PATCH v3 09/20] refs: add method to rename refs David Turner
2016-01-14 16:26 ` [PATCH v3 10/20] refs: make lock generic David Turner
2016-01-14 16:26 ` [PATCH v3 11/20] refs: move duplicate check to common code David Turner
2016-01-14 16:26 ` [PATCH v3 12/20] refs: allow log-only updates David Turner
2016-01-14 16:26 ` [PATCH v3 13/20] refs: resolve symbolic refs first David Turner
2016-02-04  7:37   ` Jeff King
2016-02-04 19:24     ` David Turner
2016-01-14 16:26 ` [PATCH v3 14/20] refs: always handle non-normal refs in files backend David Turner
2016-01-14 16:26 ` [PATCH v3 15/20] init: allow alternate backends to be set for new repos David Turner
2016-01-15 11:33   ` SZEDER Gábor
2016-01-15 12:51   ` Thomas Gummerer
2016-01-19 19:12     ` David Turner
2016-02-04  9:48   ` Duy Nguyen
2016-02-04 20:05     ` David Turner
2016-01-14 16:26 ` [PATCH v3 16/20] refs: check submodules ref storage config David Turner
2016-01-14 16:26 ` [PATCH v3 17/20] refs: allow ref backend to be set for clone David Turner
2016-01-15 11:32   ` SZEDER Gábor
2016-01-19 17:06     ` David Turner
2016-01-21  9:08       ` SZEDER Gábor
2016-01-14 16:26 ` [PATCH v3 18/20] svn: learn ref-storage argument David Turner
2016-01-15 11:34   ` SZEDER Gábor
2016-01-14 16:26 ` [PATCH v3 19/20] refs: add LMDB refs backend David Turner
2016-01-15 13:33   ` Thomas Gummerer
2016-01-19 18:55     ` David Turner
2016-02-04  9:58   ` Duy Nguyen
2016-02-04 19:33     ` David Turner
2016-01-14 16:26 ` [PATCH v3 20/20] refs: tests for lmdb backend David Turner
2016-02-02 20:08 ` [PATCH v3 00/20] refs backend rebase on pu David Turner
2016-02-02 22:13   ` Junio C Hamano
2016-02-04  0:09     ` Junio C Hamano
2016-02-04  1:12       ` David Turner
2016-02-04  1:54         ` Ramsay Jones
2016-02-04  2:58           ` Jeff King [this message]
2016-02-04 22:44             ` David Turner
2016-02-04 10:09   ` Duy Nguyen
2016-02-04 21:39     ` David Turner
2016-02-04 11:42   ` Duy Nguyen
2016-02-04 20:25     ` David Turner
2016-02-04 20:39       ` Ramsay Jones
2016-02-04 21:23         ` David Turner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160204025821.GA21105@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    --cc=ramsay@ramsayjones.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.