threads / discuss / 19736

[PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

Subject: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

## tl;dr

8 messages between Jun 8, 2009 and Jun 11, 2009.

replies: 7people: 2as markdown or json

Santi Béjar· Jun 8, 2009, 09:00 UTC · lore

The only user of get_remote_refs_for_fetch was "git pull --rebase" and it only wanted the tracking branch to be merge. So, add a simple function with this new meaning.

No behavior changes.
Signed-off-by: Santi Béjar <santi@agolina.net>
---
 git-parse-remote.sh |   33 +++++++++++++++++++++++++++++++++
 git-pull.sh         |    7 ++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index a296719..8b3ba72 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -229,6 +229,38 @@ get_remote_refs_for_fetch () {
 	esac
 }
 
+get_remote_merge_branch () {
+	case "$#" in
+	0|1)
+	    die "internal error: get-remote-merge-branch." ;;
+	*)
+	    repo=$1
+	    shift
+	    # FIXME: It should return the tracking branch
+	    #        Currently only works with the default mapping
+	    for ref
+	    do
+		case "$ref" in
+		+*)
+			ref=$(expr "z$ref" : 'z+\(.*\)')
+			;;
+		esac
+		expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
+		remote=$(expr "z$ref" : 'z\([^:]*\):')
+		case "$remote" in
+		'' | HEAD ) remote=HEAD ;;
+		heads/*) remote=${remote#heads/} ;;
+		refs/heads/*) remote=${remote#refs/heads/} ;;
+		refs/* | tags/* | remotes/* ) break
+		esac
+
+		echo "refs/remotes/$repo/$remote"
+		break
+	    done
+	    ;;
+	esac
+}
+
 resolve_alternates () {
 	# original URL (xxx.git)
 	top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'`
@@ -262,3 +294,4 @@ get_uploadpack () {
 		;;
 	esac
 }
+
diff --git a/git-pull.sh b/git-pull.sh
index 3526153..3cf2663 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -125,12 +125,9 @@ test true = "$rebase" && {
 	die "refusing to pull with rebase: your working tree is not up-to-date"
 
 	. git-parse-remote &&
-	origin="$1"
-	test -z "$origin" && origin=$(get_default_remote)
-	reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null |
-		sed "s|refs/heads/\(.*\):|\1|")" &&
+	reflist="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
 	oldremoteref="$(git rev-parse -q --verify \
-		"refs/remotes/$origin/$reflist")"
+		"$reflist")"
 }
 orig_head=$(git rev-parse -q --verify HEAD)
 git fetch $verbosity --update-head-ok "$@" || exit 1
-- 
1.6.3.1.308.g426b5
Junio C Hamano· Jun 8, 2009, 23:30 UTC · re: Santi Béjar · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

Santi Béjar <santi@agolina.net> writes:
Show 5 quoted lines
> The only user of get_remote_refs_for_fetch was "git pull --rebase" and
> it only wanted the tracking branch to be merge. So, add a simple
> function with this new meaning.
>
> No behavior changes.

I am all for code reduction, but after following the original logic that uses remote_refs_for_fetch (which knows about things like "git pull there +refs/heads/master:refs/heads/origin tag v1.6.0" from the command line) that in turn calls canon_refs_list_for_fetch (which returns a list e.g. +refs/heads/master:refs/heads/origin refs/tags/v1.6.0:refs/tags/v1.6.0), and do not quite see how you can casually say "No behaviour changes."

Santi Béjar· Jun 9, 2009, 07:29 UTC · re: Junio C Hamano · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

2009/6/9 Junio C Hamano <gitster@pobox.com>:
Show 14 quoted lines
> Santi Béjar <santi@agolina.net> writes:
>
>> The only user of get_remote_refs_for_fetch was "git pull --rebase" and
>> it only wanted the tracking branch to be merge. So, add a simple
>> function with this new meaning.
>>
>> No behavior changes.
>
> I am all for code reduction, but after following the original logic that
> uses remote_refs_for_fetch (which knows about things like "git pull there
> +refs/heads/master:refs/heads/origin tag v1.6.0" from the command line)
> that in turn calls canon_refs_list_for_fetch (which returns a list e.g.
> +refs/heads/master:refs/heads/origin refs/tags/v1.6.0:refs/tags/v1.6.0),
> and do not quite see how you can casually say "No behaviour changes."

Ups, you are right. But even in you case the only important branch is the first, so the only possible change in behavior is:

git pull --rebase tags v1.6.0
I'll see what I can do.

Thanks for the review, Santi

Santi Béjar· Jun 9, 2009, 08:07 UTC · re: Santi Béjar · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

2009/6/9 Santi Béjar <santi@agolina.net>:
Show 20 quoted lines
> 2009/6/9 Junio C Hamano <gitster@pobox.com>:
>> Santi Béjar <santi@agolina.net> writes:
>>
>>> The only user of get_remote_refs_for_fetch was "git pull --rebase" and
>>> it only wanted the tracking branch to be merge. So, add a simple
>>> function with this new meaning.
>>>
>>> No behavior changes.
>>
>> I am all for code reduction, but after following the original logic that
>> uses remote_refs_for_fetch (which knows about things like "git pull there
>> +refs/heads/master:refs/heads/origin tag v1.6.0" from the command line)
>> that in turn calls canon_refs_list_for_fetch (which returns a list e.g.
>> +refs/heads/master:refs/heads/origin refs/tags/v1.6.0:refs/tags/v1.6.0),
>> and do not quite see how you can casually say "No behaviour changes."
>
> Ups, you are right. But even in you case the only important branch is
> the first, so the only possible change in behavior is:
>
> git pull --rebase tags v1.6.0
In fact: git pull --rebase remote tags v1.6.0

But this still works because oldremoteref defaults to defaults_merge. So the only behavior change is when a remote branch is rebased/retagged, and you have worst problems then. I think noone used the rebased functionality in this way, so I don't think it is worth to support it. But if someone think it is important I'll do it.

Santi
Junio C Hamano· Jun 9, 2009, 08:28 UTC · re: Santi Béjar · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

Santi Béjar <santi@agolina.net> writes:
Show 9 quoted lines
>> git pull --rebase tags v1.6.0
>
> In fact: git pull --rebase remote tags v1.6.0
>
> But this still works because oldremoteref defaults to defaults_merge.
> So the only behavior change is when a remote branch is
> rebased/retagged, and you have worst problems then. I think noone used
> the rebased functionality in this way, so I don't think it is worth to
> support it. But if someone think it is important I'll do it.

I personally do not think supporting such a form of input is absolutely necessary. Even though technically it might be a regression, if it is so rare a form, we can simply say "this strange form used to work, but now it does not; you can use this form instead to do the same thing", and move on.

However, at least we should describe the change, both in the commit log and documentation. Simply saying "No behaviour change" is not acceptable, when the code clearly is doing something else. It needs to be backed by some explanation, e.g. "Even though this returns different results from the original, the caller behaves the same because of such and such reasons".

What caught my attention was not the difference between the new code and the original codepath, but your "FIXME" comment that said "Currently only works with the default mapping". My initial reaction was "What? The new code that introduces a function for the specific task of figuring out the mapping does not work if the user uses a custom mapping? What kind of improvement is that???".

The reaction was followed by "Even if that were the case, if the original code did not work in the case anyway, then it is not a regression. The proposed commit log message claims that there is no behaviour change, so that FIXME might not be so grave an offense. Is it really the case? Was the original broken?"

While trying to figure it out, I noticed that the new code does quite a different thing (I still haven't figured out the answer to my original question about FIXME, by the way).

In any case, if we were changing behaviour by deprecating support for a rarely-if-ever used syntax, it would be nice if we at least diagnosed it, instead of failing, or worse yet, silently doing something different from the old behaviour.

Santi Béjar· Jun 9, 2009, 08:50 UTC · re: Junio C Hamano · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

2009/6/9 Junio C Hamano <gitster@pobox.com>:
Show 17 quoted lines
> Santi Béjar <santi@agolina.net> writes:
>
>>> git pull --rebase tags v1.6.0
>>
>> In fact: git pull --rebase remote tags v1.6.0
>>
>> But this still works because oldremoteref defaults to defaults_merge.
>> So the only behavior change is when a remote branch is
>> rebased/retagged, and you have worst problems then. I think noone used
>> the rebased functionality in this way, so I don't think it is worth to
>> support it. But if someone think it is important I'll do it.
>
> I personally do not think supporting such a form of input is absolutely
> necessary.  Even though technically it might be a regression, if it is so
> rare a form, we can simply say "this strange form used to work, but now it
> does not; you can use this form instead to do the same thing", and move
> on.
OK.
Show 7 quoted lines
>
> However, at least we should describe the change, both in the commit log
> and documentation.  Simply saying "No behaviour change" is not acceptable,
> when the code clearly is doing something else.  It needs to be backed by
> some explanation, e.g. "Even though this returns different results from
> the original, the caller behaves the same because of such and such
> reasons".
OK.
Show 7 quoted lines
>
> What caught my attention was not the difference between the new code and
> the original codepath, but your "FIXME" comment that said "Currently only
> works with the default mapping".  My initial reaction was "What?  The new
> code that introduces a function for the specific task of figuring out the
> mapping does not work if the user uses a custom mapping?  What kind of
> improvement is that???".

The original code (in git-pull.sh) behaves like this, I only made it more explicit.

Show 6 quoted lines
>
> The reaction was followed by "Even if that were the case, if the original
> code did not work in the case anyway, then it is not a regression.  The
> proposed commit log message claims that there is no behaviour change, so
> that FIXME might not be so grave an offense.  Is it really the case?  Was
> the original broken?"
Yes, the original is broken.
Show 9 quoted lines
>
> While trying to figure it out, I noticed that the new code does quite a
> different thing (I still haven't figured out the answer to my original
> question about FIXME, by the way).
>
> In any case, if we were changing behaviour by deprecating support for a
> rarely-if-ever used syntax, it would be nice if we at least diagnosed it,
> instead of failing, or worse yet, silently doing something different from
> the old behaviour.

I am not changing the behaviour. The old code worked exactly like the new one. But I agree that this has to be documented(/deprecated?) somewhere.

The only change in behavior is when a remote tag is rebased/retagged.
Santi
Santi Béjar· Jun 9, 2009, 12:16 UTC · re: Santi Béjar · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

2009/6/9 Santi Béjar <santi@agolina.net>:
Show 21 quoted lines
> 2009/6/9 Junio C Hamano <gitster@pobox.com>:
>> Santi Béjar <santi@agolina.net> writes:
>>
>>>> git pull --rebase tags v1.6.0
>>>
>>> In fact: git pull --rebase remote tags v1.6.0
>>>
>>> But this still works because oldremoteref defaults to defaults_merge.
>>> So the only behavior change is when a remote branch is
>>> rebased/retagged, and you have worst problems then. I think noone used
>>> the rebased functionality in this way, so I don't think it is worth to
>>> support it. But if someone think it is important I'll do it.
>>
>> I personally do not think supporting such a form of input is absolutely
>> necessary.  Even though technically it might be a regression, if it is so
>> rare a form, we can simply say "this strange form used to work, but now it
>> does not; you can use this form instead to do the same thing", and move
>> on.
>
> OK.
>

At the end it was a little patch to get this corner case working. Here it is the patch to squash (I'll send later a proper patch mail, with a test).

And this additional sentence in the commit log:

No behavior changes. The new function behaves like the old code used in "git pull --rebase".

diff --git i/git-parse-remote.sh w/git-parse-remote.sh
index 8b3ba72..4ac277f 100755
--- i/git-parse-remote.sh
+++ w/git-parse-remote.sh
@@ -238,8 +238,12 @@ get_remote_merge_branch () {
 	    shift
 	    # FIXME: It should return the tracking branch
 	    #        Currently only works with the default mapping
-	    for ref
-	    do
+	    case "$1" in
+	    tag)
+		[ -n "$2" ] && echo "refs/tags/${ref}"
+		;;
+	    *)
+		ref=$1
 		case "$ref" in
 		+*)
 			ref=$(expr "z$ref" : 'z+\(.*\)')
@@ -251,12 +255,11 @@ get_remote_merge_branch () {
 		'' | HEAD ) remote=HEAD ;;
 		heads/*) remote=${remote#heads/} ;;
 		refs/heads/*) remote=${remote#refs/heads/} ;;
-		refs/* | tags/* | remotes/* ) break
+		refs/* | tags/* | remotes/* ) remote=
 		esac

-		echo "refs/remotes/$repo/$remote"
-		break
-	    done
+		[ -n "$remote" ] && echo "refs/remotes/$repo/$remote"
+	    esac
 	    ;;
 	esac
 }

(Sorry, if it gets corrupted)

Santi
Santi Béjar· Jun 11, 2009, 21:30 UTC · re: Santi Béjar · lore

Re: [PATCHv3 1/4] parse-remote: function to get the tracking branch to be merge

2009/6/9 Santi Béjar <santi@agolina.net>:
Show 32 quoted lines
> 2009/6/9 Santi Béjar <santi@agolina.net>:
>> 2009/6/9 Junio C Hamano <gitster@pobox.com>:
>>> Santi Béjar <santi@agolina.net> writes:
>>>
>>>>> git pull --rebase tags v1.6.0
>>>>
>>>> In fact: git pull --rebase remote tags v1.6.0
>>>>
>>>> But this still works because oldremoteref defaults to defaults_merge.
>>>> So the only behavior change is when a remote branch is
>>>> rebased/retagged, and you have worst problems then. I think noone used
>>>> the rebased functionality in this way, so I don't think it is worth to
>>>> support it. But if someone think it is important I'll do it.
>>>
>>> I personally do not think supporting such a form of input is absolutely
>>> necessary.  Even though technically it might be a regression, if it is so
>>> rare a form, we can simply say "this strange form used to work, but now it
>>> does not; you can use this form instead to do the same thing", and move
>>> on.
>>
>> OK.
>>
>
> At the end it was a little patch to get this corner case working. Here
> it is the patch to squash (I'll send later a proper patch mail, with a
> test).
>
> And this additional sentence in the commit log:
>
> No behavior changes. The new function behaves like the old code used in
> "git pull --rebase".
>

At the end the original code does not handle this case, as it asumes that the rebase ref is a remote commit in refs/remotes/$origin/$ref. So the new code behaves exactly like the old one. I'll send all again with an updated commit message explaining all this.

Santi

← back to recent threads