Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 3 participants 8 messages Jun 15, 2016

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

From: Marc Branchaud <[email protected]>

---

This has been a minor irritant in my life for a while now... :)

 builtin/fetch.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/fetch.c +7 -2
index 65f5f9b..57be58a 100644
@@ -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);
Signature · 1 line
1.7.10.1.g2bbc8
#1 lore raw
Quoted 13 lines · On Wed, Apr 11, 2012 at 10:29:29AM -0400, [email protected] wrote:
 builtin/fetch.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/fetch.c +0 -2
index 65f5f9b..57be58a 100644
@@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
 			what = _("[new tag]");
 		}
 		else {
-			msg = "storing head";
-			what = _("[new branch]");

builtin/fetch.c static int update_local_ref(struct ref *ref, · line 310

Quoted 10 lines
builtin/fetch.c +7 -0
+			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

#2 lore raw

Am 12.04.2012 07:52, schrieb Jeff King:

Quoted 35 lines · On Wed, Apr 11, 2012 at 10:29:29AM -0400, [email protected] wrote:
Quoted 14 lines
 builtin/fetch.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/fetch.c +0 -2
index 65f5f9b..57be58a 100644
@@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
 			what = _("[new tag]");
 		}
 		else {
-			msg = "storing head";
-			what = _("[new branch]");

builtin/fetch.c static int update_local_ref(struct ref *ref, · line 310

Quoted 10 lines
builtin/fetch.c +7 -0
+			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?

Quoted 5 lines

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

#3 lore raw
Quoted 40 lines · Jens Lehmann

Am 12.04.2012 07:52, schrieb Jeff King:

Quoted 39 lines · On Wed, Apr 11, 2012 at 10:29:29AM -0400, [email protected] wrote:
Quoted 14 lines
 builtin/fetch.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
builtin/fetch.c +0 -2
index 65f5f9b..57be58a 100644
@@ -298,8 +298,13 @@ static int update_local_ref(struct ref *ref,
 			what = _("[new tag]");
 		}
 		else {
-			msg = "storing head";
-			what = _("[new branch]");

builtin/fetch.c static int update_local_ref(struct ref *ref, · line 310

Quoted 10 lines
builtin/fetch.c +7 -0
+			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.

Quoted 7 lines
Quoted 1 line

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.
#4 lore raw

Am 12.04.2012 22:36, schrieb Marc Branchaud:

Quoted 4 lines

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

#5 lore raw
Quoted 8 lines · Jens Lehmann

Am 12.04.2012 22:36, schrieb Marc Branchaud:

Quoted 4 lines

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

#6 lore raw
Quoted 9 lines · Jeff King
Quoted 8 lines

Am 12.04.2012 22:36, schrieb Marc Branchaud:

Quoted 4 lines

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

Quoted 6 lines

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

#7 lore raw

PATCH 1/1 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.

---

Am 13.04.2012 09:04, schrieb Jeff King:

Quoted 11 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(-)
builtin/fetch.c +3 -3
index 65f5f9b..cfb43df 100644
@@ -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 ? '!' : '*',
Signature · 1 line
1.7.10.131.gd0e498