public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha•warpmail.net>
To: Junio C Hamano <gitster@pobox•com>
Cc: git@vger•kernel.org, Daniel Barkalow <barkalow@iabervon•org>,
	Johannes Schindelin <Johannes.Schindelin@gmx•de>
Subject: Re: [PATCH 2/2] Make local branches behave like remote branches when --tracked
Date: Fri, 27 Mar 2009 09:47:01 +0100	[thread overview]
Message-ID: <49CC9285.407@drmicha.warpmail.net> (raw)
In-Reply-To: <7vprg3fkw8.fsf@gitster.siamese.dyndns.org>

Junio C Hamano venit, vidit, dixit 27.03.2009 09:08:
> Michael J Gruber <git@drmicha•warpmail.net> writes:
> 
>> This makes sure that local branches, when followed using --track, behave
>> the same as remote ones (e.g. differences being reported by git status
>> and git checkout). This fixes 1 known failure.
>>
>> Signed-off-by: Michael J Gruber <git@drmicha•warpmail.net>
>> ---
>>  remote.c                 |    9 +++++----
>>  t/t6040-tracking-info.sh |    2 +-
>>  2 files changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/remote.c b/remote.c
>> index 2b037f1..5d2d7a1 100644
>> --- a/remote.c
>> +++ b/remote.c
>> @@ -1170,8 +1170,9 @@ struct branch *branch_get(const char *name)
>>  			for (i = 0; i < ret->merge_nr; i++) {
>>  				ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
>>  				ret->merge[i]->src = xstrdup(ret->merge_name[i]);
>> -				remote_find_tracking(ret->remote,
>> -						     ret->merge[i]);
>> +				if(remote_find_tracking(ret->remote,
>> +						     ret->merge[i]) && !strcmp(ret->remote_name, "."))
>> +					ret->merge[i]->dst = xstrdup(ret->merge_name[i]);
>>  			}
>>  		}
>>  	}
> 
> Yuck; please have a SP betweeen "if" and "(", and also have a decency to
> break a long line at a more sensible place, like:
> 
> 			if (remote_find_tracking(ret->remote, ret->merge[i])
> 			    && !strcmp(...))
>                             	then do this;
> 

Sorry about the space. Regarding the break, you can see that the break
was like that before already, and I just followed suite, which I think
makes the diff more readable. But no problem changing that,

> A naïve question from me to this change is why this "fix-up" is done here.

It was the easiest and least intrusive way for me...

> 
> The remote_find_tracking() function is given a half-filled refspec (this
> caller fills the src side, and asks to find the dst side to the function).
> After it fails to find a fetch refspec that copies remote refs to tracking
> refs in the local repository that match the criteria, it returns -1 to
> signal an error, otherwise it returns 0 after updating the other half of
> the refspec.
> 
> After calling r-f-t, because this new code assumes that for the "." remote
> (aka "local repository"), r-f-t lies and does not give back what it
> expects, fixes what it got back from r-f-t.  Shouldn't we be fixing this
> inside r-f-t?

The technical reason is that there is no local remote, i.e. no remote
struct for '.', and I don't think we want it, because it would show up
in all places where the list of remotes is searched/displayed/...

With ret being the branch we talk about, r-f-t is passed ret->remote and
ret->merge[i] only. In the local case, r-f-t cannot use the remote
struct for '.' (there is none) to find what it needs, and it has no easy
access to ret->merge_names[i] which is that info.

branch_get(), on the other hand, has all needed info in place. So,
having r-f-t do it would require changing the parameters or adding a
remote struct for '.' and adjusting all callers correspondingly. Doing
it the way I did it is "minimally invasive" in that respect, with the
(small) downside that we may call r-f-t unnecessarily in the local case
- but we don't know before: If someone set up a remote config for '.'
then we have to go through r-f-t anayways.

> 
>> @@ -1449,8 +1450,8 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
>>  		return 0;
>>  
>>  	base = branch->merge[0]->dst;
>> -	if (!prefixcmp(base, "refs/remotes/")) {
>> -		base += strlen("refs/remotes/");
>> +	if (!prefixcmp(base, "refs/")) {
>> +		base += strlen("refs/");
> 
> I am not sure if this is a good change.  The majority of the case would
> be remotes/ and we would be better off not repeating them.  Can't you
> limit the use of longer refs only when disambiguation is necessary?
> 

The majority will be remotes, yes, but will the majority be unique? In
my case not.  Even when we knew that format_tracking_info() would have
to deal with remote branches only (before this series) there was a
(high) chance of outputting non-unique refs, even worse: if foo is
ambiguous because refs/heads/foo and refs/remotes/foo exist then
refs/heads/foo would win, i.e. we used to output the *wrong* ref. The
above disambiguates. But I'll see if I can simplify the output based on
the necessity of disambiguation.

Michael

  reply	other threads:[~2009-03-27  8:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-20 14:22 Tracking of local branches Michael J Gruber
2009-03-20 16:13 ` Michael J Gruber
2009-03-20 16:46 ` Junio C Hamano
2009-03-20 18:10   ` Daniel Barkalow
2009-03-26 20:53     ` [PATCH 0/2] Make local branches behave like remote branches when --tracked Michael J Gruber
2009-03-26 20:53       ` [PATCH 1/2] Test for local branches being followed with --track Michael J Gruber
2009-03-26 20:53         ` [PATCH 2/2] Make local branches behave like remote branches when --tracked Michael J Gruber
2009-03-27  8:08           ` Junio C Hamano
2009-03-27  8:47             ` Michael J Gruber [this message]
2009-03-27 16:20               ` Junio C Hamano
2009-03-27 16:52                 ` Michael J Gruber
2009-04-01 21:42                   ` [PATCHv2 0/2] " Michael J Gruber
2009-04-01 21:42                     ` [PATCHv2 1/2] Test for local branches being followed with --track Michael J Gruber
2009-04-01 21:42                       ` [PATCHv2 2/2] Make local branches behave like remote branches when --tracked Michael J Gruber
2009-03-26 20:57       ` [PATCH 0/2] " Michael J Gruber

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=49CC9285.407@drmicha.warpmail.net \
    --to=git@drmicha$(echo .)warpmail.net \
    --cc=Johannes.Schindelin@gmx$(echo .)de \
    --cc=barkalow@iabervon$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox