git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Glen Choo <chooglen@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC PATCH 2/2] branch: add --recurse-submodules option for branch creation
Date: Wed, 22 Sep 2021 09:55:28 -0700	[thread overview]
Message-ID: <kl6lv92s35z3.fsf@chooglen-macbookpro.roam.corp.google.com> (raw)
In-Reply-To: <87k0j87tdw.fsf@evledraar.gmail.com>

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

>>  static const char *head;
>>  static struct object_id head_oid;
>> +static int recurse_submodules = 0;
>
> Nit: just s/ = 0// will do here, and is the convention typically...

Thanks for the catch!

>> +	r_start_name = strcmp(start_name, "HEAD") ? start_name :
>> +		refs_resolve_refdup(get_main_ref_store(r), start_name, 0, NULL, NULL);
>
> IMO clearer just as an if/else.

Sounds good, I'll use an if/else instead

>> +	if (!recurse_submodules) {
>> +		return;
>> +	}
>
> Can lose the braces here...

Ah, yes. Old habits die hard.. Thanks!

>> +
>> +	for (i = 0; i < r->index->cache_nr; i++) {
>> +		const struct cache_entry *ce = r->index->cache[i];
>> +		if (!S_ISGITLINK(ce->ce_mode))
>> +			continue;
>> +		sub = submodule_from_path(r, null_oid(), ce->name);
>> +		if (repo_submodule_init(&subrepo, r, sub) < 0) {
>> +			warning(_("Unable to initialize subrepo %s, skipping."), ce->name);
>> +			continue;
>> +		}
>> +		/*
>> +		 * NEEDSWORK: branch tracking is not supported for
>> +		 * submodules because it is not possible to get the
>> +		 * remotes of a submodule.
>> +		 */
>
> It isn't?
>
>     $ git -C sha1collisiondetection/ remote -v
>     origin  https://github.com/cr-marcstevens/sha1collisiondetection.git

Ah, my comment is ambiguous. I meant that we cannot get
submodule remotes in-process because remotes.c stores its state in
static variables I believe it implicitly refers to the remotes of
the_repository and can't be reused for submodules.

Of course I hope I am wrong, because that would make this task a lot
easier :)

> All this manual file checking should depend on REFFILES, but better yet
> is there a reason this can't use rev-parse? I.e. why can't we inpect
> this state with 'for-each-ref', 'rev-parse' and the like? Does this test
> need to assert that these files end up in these specific locations, or
> just the ref store? Ditto for the later ones.

> Use test_cmp, also for this sort of thing the test "x$y" = "x" idiom
> isn't needed unless you've got a computer from the mid-90s or something
> :)

The only reason the tests look this way is that I have copied the
surrounding tests. From your comments, it seems clear that these tests
are fairly out-of-date, so I should probably model them after something
else.

I will incorporate Philippe's suggestion

  Most tests for submodules are usually in separate test files. I don't think
  this is a set-in-stone rule, but if more tests are coming in the future, maybe
  a new test file t????-branch-submodule.sh would be appropriate ? Just a small suggestion.

Then at least my new tests won't look so out of place with the other
branch tests.

>> In this patchset, branching works slightly differently between the
>> superproject and submodule (skip ahead for specifics). There are two
>> very obvious alternatives that can address this:
 
>> * A: only implement --recurse-submodules behavior after we are able to
>>   eliminate any kind of dependence on the_repository/global state that
>>   shouldn't be shared.
>> * B: implement --recurse-submodules as child processes, which won't be
>>   bothered by global state.

I was wondering if you had thoughts on this bit in particular. It seems
unpleasant for branching to behave differently between superproject and
submodule, so I'd like to discard this RFC (or at least the 'disable
remotes' behavior) ASAP and start work on a version that serves us
better.

  reply	other threads:[~2021-09-22 16:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-21 23:25 [RFC PATCH 0/2] branch: implement in-process --recurse-submodules Glen Choo
2021-09-21 23:25 ` [RFC PATCH 1/2] refs: pass struct repository *r through to write_ref_to_lockfile() Glen Choo
2021-09-21 23:25 ` [RFC PATCH 2/2] branch: add --recurse-submodules option for branch creation Glen Choo
2021-09-22 11:10   ` Ævar Arnfjörð Bjarmason
2021-09-22 16:55     ` Glen Choo [this message]
2021-09-22 12:28   ` Philippe Blain
2021-09-22 17:24     ` Glen Choo

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=kl6lv92s35z3.fsf@chooglen-macbookpro.roam.corp.google.com \
    --to=chooglen@google.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).