threads / patch / 30210

patchfetch: Only call a new ref a "branch" if it's under refs/heads/.

Subject: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

## tl;dr

8 messages between Apr 11, 2012 and Apr 13, 2012. Diffs are folded; open one to read it.

replies: 7people: 3as markdown or json

marcnarc@xiplink.com· Apr 11, 2012, 14:29 UTC · lore
From: Marc Branchaud <marcnarc@xiplink.com>
Signed-off-by: Marc Branchaud <marcnarc@xiplink.com>
---
This has been a minor irritant in my life for a while now...  :)
 builtin/fetch.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Show changes to builtin/fetch.c +7 −2
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 65f5f9b..57be58a 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
 			what = _("[new tag]");
 		}
 		else {
-			msg = "storing head";
-			what = _("[new branch]");
+			if (!prefixcmp(ref->name, "refs/heads/")) {
+				msg = "storing head";
+				what = _("[new branch]");
+			} else {
+				msg = "storing ref";
+				what = _("[new ref]");
+			}
 			if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 			    (recurse_submodules != RECURSE_SUBMODULES_ON))
 				check_for_new_submodule_commits(ref->new_sha1);
-- 
1.7.10.1.g2bbc8
Jeff King· Apr 12, 2012, 05:52 UTC · re: marcnarc@xiplink.com · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

On Wed, Apr 11, 2012 at 10:29:29AM -0400, marcnarc@xiplink.com wrote:
Show 23 quoted lines
>  builtin/fetch.c |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 65f5f9b..57be58a 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
>  			what = _("[new tag]");
>  		}
>  		else {
> -			msg = "storing head";
> -			what = _("[new branch]");
> +			if (!prefixcmp(ref->name, "refs/heads/")) {
> +				msg = "storing head";
> +				what = _("[new branch]");
> +			} else {
> +				msg = "storing ref";
> +				what = _("[new ref]");
> +			}
>  			if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
>  			    (recurse_submodules != RECURSE_SUBMODULES_ON))
>  				check_for_new_submodule_commits(ref->new_sha1);

It looks like you kept the behavior the same with respect to recurse_submodules, which will continue to run for everything except tags. Which is probably a good choice, since your patch only wanted to deal with the status message, but I am left to wonder: if submodules were intended to be recursed for branches but not tags, what should happen for other types of refs? Was it intentional that they fell into the "branch" category here, or were they following the same failure to distinguish that the message-writing code had?

This code block handles only new refs. If you look at the code below, updates of existing refs (forced or not) will happen for all refs, including tags.

Jens, can you double-check the intended logic?
-Peff
Jens Lehmann· Apr 12, 2012, 20:15 UTC · re: Jeff King · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

Am 12.04.2012 07:52, schrieb Jeff King:
Show 40 quoted lines
> On Wed, Apr 11, 2012 at 10:29:29AM -0400, marcnarc@xiplink.com wrote:
> 
>>  builtin/fetch.c |    9 +++++++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/builtin/fetch.c b/builtin/fetch.c
>> index 65f5f9b..57be58a 100644
>> --- a/builtin/fetch.c
>> +++ b/builtin/fetch.c
>> @@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
>>  			what = _("[new tag]");
>>  		}
>>  		else {
>> -			msg = "storing head";
>> -			what = _("[new branch]");
>> +			if (!prefixcmp(ref->name, "refs/heads/")) {
>> +				msg = "storing head";
>> +				what = _("[new branch]");
>> +			} else {
>> +				msg = "storing ref";
>> +				what = _("[new ref]");
>> +			}
>>  			if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
>>  			    (recurse_submodules != RECURSE_SUBMODULES_ON))
>>  				check_for_new_submodule_commits(ref->new_sha1);
> 
> It looks like you kept the behavior the same with respect to
> recurse_submodules, which will continue to run for everything except
> tags. Which is probably a good choice, since your patch only wanted to
> deal with the status message, but I am left to wonder: if submodules
> were intended to be recursed for branches but not tags, what should
> happen for other types of refs? Was it intentional that they fell into
> the "branch" category here, or were they following the same failure to
> distinguish that the message-writing code had?
> 
> This code block handles only new refs.  If you look at the code below,
> updates of existing refs (forced or not) will happen for all refs,
> including tags.
> 
> Jens, can you double-check the intended logic?

Thanks for spotting this inconsistency. I think it makes sense to check for new submodule commits no matter if we fetched a new tag, branch or other ref. I can't remember a reason why I put that code into the refs & branches part instead of doing that for every new ref. Patch following ...

Marc Branchaud· Apr 12, 2012, 20:36 UTC · re: Jens Lehmann · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

On 12-04-12 04:15 PM, Jens Lehmann wrote:
Show 47 quoted lines
> Am 12.04.2012 07:52, schrieb Jeff King:
>> On Wed, Apr 11, 2012 at 10:29:29AM -0400, marcnarc@xiplink.com wrote:
>>
>>>  builtin/fetch.c |    9 +++++++--
>>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/builtin/fetch.c b/builtin/fetch.c
>>> index 65f5f9b..57be58a 100644
>>> --- a/builtin/fetch.c
>>> +++ b/builtin/fetch.c
>>> @@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
>>>  			what = _("[new tag]");
>>>  		}
>>>  		else {
>>> -			msg = "storing head";
>>> -			what = _("[new branch]");
>>> +			if (!prefixcmp(ref->name, "refs/heads/")) {
>>> +				msg = "storing head";
>>> +				what = _("[new branch]");
>>> +			} else {
>>> +				msg = "storing ref";
>>> +				what = _("[new ref]");
>>> +			}
>>>  			if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
>>>  			    (recurse_submodules != RECURSE_SUBMODULES_ON))
>>>  				check_for_new_submodule_commits(ref->new_sha1);
>>
>> It looks like you kept the behavior the same with respect to
>> recurse_submodules, which will continue to run for everything except
>> tags. Which is probably a good choice, since your patch only wanted to
>> deal with the status message, but I am left to wonder: if submodules
>> were intended to be recursed for branches but not tags, what should
>> happen for other types of refs? Was it intentional that they fell into
>> the "branch" category here, or were they following the same failure to
>> distinguish that the message-writing code had?
>>
>> This code block handles only new refs.  If you look at the code below,
>> updates of existing refs (forced or not) will happen for all refs,
>> including tags.
>>
>> Jens, can you double-check the intended logic?
> 
> Thanks for spotting this inconsistency. I think it makes sense to
> check for new submodule commits no matter if we fetched a new tag,
> branch or other ref. I can't remember a reason why I put that code
> into the refs & branches part instead of doing that for every new
> ref. Patch following ...

I assumed it was an optimization of some sort -- that since tags are normally only fetched when they're part of a requested branch's history (right?), there was no point in doing submodule recursion on the fetched tags since those tagged tree-ishes had already been submodule-recursed.

Or something like that.  :)
		M.
Jens Lehmann· Apr 12, 2012, 20:42 UTC · re: Marc Branchaud · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

Am 12.04.2012 22:36, schrieb Marc Branchaud:
> I assumed it was an optimization of some sort -- that since tags are normally
> only fetched when they're part of a requested branch's history (right?),
> there was no point in doing submodule recursion on the fetched tags since
> those tagged tree-ishes had already been submodule-recursed.

If that is the case the patch I just sent is pointless, but adding a comment there explaining that would be a good thing ;-)

Jeff King· Apr 12, 2012, 21:05 UTC · re: Jens Lehmann · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

On Thu, Apr 12, 2012 at 10:42:20PM +0200, Jens Lehmann wrote:
Show 8 quoted lines
> Am 12.04.2012 22:36, schrieb Marc Branchaud:
> > I assumed it was an optimization of some sort -- that since tags are normally
> > only fetched when they're part of a requested branch's history (right?),
> > there was no point in doing submodule recursion on the fetched tags since
> > those tagged tree-ishes had already been submodule-recursed.
> 
> If that is the case the patch I just sent is pointless, but adding a comment
> there explaining that would be a good thing ;-)

That is often the case, but not always (I might explicitly fetch a tag, or have refs/tags/ in my refspec). So I think you want to handle both to cover all cases. I haven't looked at the submodule recursion code, but I would hope that it would eliminate duplicates (so if I get a branch and a tag that is on the branch, we would look at the commit in question only once).

-Peff
Jeff King· Apr 13, 2012, 07:04 UTC · re: Jeff King · lore

Re: [PATCH] fetch: Only call a new ref a "branch" if it's under refs/heads/.

On Thu, Apr 12, 2012 at 05:05:42PM -0400, Jeff King wrote:
Show 15 quoted lines
> > Am 12.04.2012 22:36, schrieb Marc Branchaud:
> > > I assumed it was an optimization of some sort -- that since tags are normally
> > > only fetched when they're part of a requested branch's history (right?),
> > > there was no point in doing submodule recursion on the fetched tags since
> > > those tagged tree-ishes had already been submodule-recursed.
> > 
> > If that is the case the patch I just sent is pointless, but adding a comment
> > there explaining that would be a good thing ;-)
> 
> That is often the case, but not always (I might explicitly fetch a tag,
> or have refs/tags/ in my refspec). So I think you want to handle both to
> cover all cases. I haven't looked at the submodule recursion code, but I
> would hope that it would eliminate duplicates (so if I get a branch and
> a tag that is on the branch, we would look at the commit in question
> only once).

OK, I checked. Yes, we handle this just fine. After my 6859de4, we collect the ref tips before and after the fetch and run only a single rev-list. So processing the tags will result in just an extra interesting commit, which was either:

  1. accessible by another fetched branch, in which case it was going to
     be processed as interesting anyway
  2. not accessible, in which case we have fixed a bug. :)
So I think we should check all incoming refs, including tags.
-Peff
Jens Lehmann· Apr 13, 2012, 16:25 UTC · re: Jeff King · lore

[PATCH] submodules: recursive fetch also checks new tags for submodule commits

Since 88a21979c (fetch/pull: recurse into submodules when necessary) all fetched commits are examined if they contain submodule changes (unless configuration or command line options inhibit that). If a newly recorded submodule commit is not present in the submodule, a fetch is run inside it to download that commit.

Checking new refs was done in an else branch where it wasn't executed for tags. This normally isn't a problem because tags are only fetched with the branches they live on, then checking the new commits in the fetched branches for submodule commits will also process all tags. But when a specific tag is fetched (or the refspec contains refs/tags/) commits only reachable by tags won't be searched for submodule commits, which is a bug.

Fix that by moving the code outside the if/else construct to handle new tags just like any other ref. The performance impact of adding tags that most of the time lie on a branch which is checked anyway for new submodule commit should be minimal, as since 6859de4 (fetch: avoid quadratic loop checking for updated submodules) all ref-tips are collected first and then fed to a single rev-list.

Spotted-by: Jeff King <peff@peff.net>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
Am 13.04.2012 09:04, schrieb Jeff King:
Show 11 quoted lines
> OK, I checked. Yes, we handle this just fine. After my 6859de4, we
> collect the ref tips before and after the fetch and run only a single
> rev-list. So processing the tags will result in just an extra
> interesting commit, which was either:
> 
>   1. accessible by another fetched branch, in which case it was going to
>      be processed as interesting anyway
> 
>   2. not accessible, in which case we have fixed a bug. :)
> 
> So I think we should check all incoming refs, including tags.
Thanks for you analysis!
 builtin/fetch.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to builtin/fetch.c +3 −3
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 65f5f9b..cfb43df 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -300,11 +300,11 @@ static int update_local_ref(struct ref *ref,
 		else {
 			msg = "storing head";
 			what = _("[new branch]");
-			if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
-			    (recurse_submodules != RECURSE_SUBMODULES_ON))
-				check_for_new_submodule_commits(ref->new_sha1);
 		}

+		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
+		    (recurse_submodules != RECURSE_SUBMODULES_ON))
+			check_for_new_submodule_commits(ref->new_sha1);
 		r = s_update_ref(msg, ref, 0);
 		strbuf_addf(display, "%c %-*s %-*s -> %s%s",
 			    r ? '!' : '*',
-- 
1.7.10.131.gd0e498

← back to recent threads