git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Santi Béjar" <santi@agolina.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCHv3 2/2] pull: support rebased upstream + fetch + pull  --rebase
Date: Sun, 19 Jul 2009 09:27:43 +0200	[thread overview]
Message-ID: <adf1fd3d0907190027s2bf5380er8e59a60d1a3637ad@mail.gmail.com> (raw)
In-Reply-To: <7vk5253mg8.fsf@alter.siamese.dyndns.org>

2009/7/18 Junio C Hamano <gitster@pobox.com>:
> Santi Béjar <santi@agolina.net> writes:
>
>> Changes since v2:
>>   - Hopefully enhance the commit log
>>   - Use a 'for' loop for the reflog entries
>>   - provide a default value in case there is no reflog
>> diff --git a/git-pull.sh b/git-pull.sh
>> index 4b78a0c..c8f1674 100755
>> --- a/git-pull.sh
>> +++ b/git-pull.sh
>> @@ -125,9 +125,16 @@ test true = "$rebase" && {
>>       die "refusing to pull with rebase: your working tree is not up-to-date"
>>
>>       . git-parse-remote &&
>> -     reflist="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
>> +     remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
>> +     oldremoteref= &&
>> +     for reflog in $(git rev-list -g $remoteref 2>/dev/null)
>> +     do
>> +             test $reflog = $(git merge-base $reflog $curr_branch) &&
>> +             oldremoteref=$reflog && break
>> +     done
>> +     [ -z "$oldremoteref" ] &&
>>       oldremoteref="$(git rev-parse -q --verify \
>> -             "$reflist")"
>> +             "$remoteref")"
>>  }
>
> If get_remote_merge_branch fails, oldremoteref is not initialized to empty
> string, the for loop is skipped and then the last step (by the way, please
> write that as 'test -z "$oldremoteref"') may not kick in, using whatever
> random value the variable originally had in the environment.

Not a justification but it also happens with the original code.

>
> It probably makes more sense to do it in a slightly different order:
>
>        . git-parse-remote &&
>        oldremoteref="$(get_remote_merge...)" &&

oldremotref must be a sha1, because it changes during the fetch. But
I'll use more o less this order.

>        remoteref=$oldremoteref &&
>        for old in $(git rev-list -g "$remoteref" 2>/dev/null)
>        do
>                if test "$old" = "$(git merge-base "$old" "$current_branch")
>                then
>                        oldremoteref="$old"
>                        break
>                fi
>        done
>        # and you do not need 'if test -z "$oldremoteref"' anymore...
>
> But other than that, I agree that this is the most straightforward
> algorithm to express what you wanted to do.  I guess another possibility
> is to instead look in the reflog of the _current_ branch to check how the
> previous rebase was done, iow, find out onto which commit the recent part
> of the current branch was rebased to, and rebase onto the current remote
> tip using that as the base.

It supposes that it was rebased already, and you have to interpret the
reflog history. And there are situations where you don't get the same
answer, i.e you create a new local branch using another local branch
as the starting point but with the same upstream.

Santi

  reply	other threads:[~2009-07-19  7:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-16  0:09 [PATCH 1/2] t5520-pull: Test for rebased upstream + fetch + pull --rebase Santi Béjar
2009-07-16  0:09 ` [PATCH 2/2] pull: support " Santi Béjar
2009-07-16  0:26   ` Junio C Hamano
2009-07-16  6:29     ` Santi Béjar
2009-07-16  8:12       ` [PATCHv2 " Santi Béjar
2009-07-16  8:12         ` Santi Béjar
2009-07-16  8:15         ` Santi Béjar
2009-07-16  8:51         ` Johannes Schindelin
2009-07-16 16:32           ` Santi Béjar
2009-07-17 10:13             ` Johannes Schindelin
2009-07-16 20:41           ` Junio C Hamano
2009-07-16 23:18             ` Santi Béjar
2009-07-17  7:51               ` Santi Béjar
2009-07-17  8:25                 ` Junio C Hamano
2009-07-17 13:24                   ` Santi Béjar
2009-07-18 13:46                     ` [PATCHv3 " Santi Béjar
2009-07-18 17:55                       ` Junio C Hamano
2009-07-19  7:27                         ` Santi Béjar [this message]
2009-07-19  7:45                           ` [PATCHv4 " Santi Béjar

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=adf1fd3d0907190027s2bf5380er8e59a60d1a3637ad@mail.gmail.com \
    --to=santi@agolina.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).