Re: [PATCHv4 2/2] pull --rebase: Avoid spurious conflicts and reapplying unnecessary patches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 12, 2010 at 7:56 AM, Elijah Newren <newren@xxxxxxxxx> wrote:
> Prior to c85c79279df2c8a583d95449d1029baba41f8660, pull --rebase would run
>  git rebase $merge_head
> which resulted in a call to
>  git format-patch ... --ignore-if-in-upstream $merge_head..$cur_branch
>
> This resulted in patches from $merge_head..$cur_branch being applied, as
> long as they did not already exist in $cur_branch..$merge_head.
> Unfortunately, when upstream is rebased, $merge_head..$cur_branch also
> refers to "old" commits that have already been rebased upstream, meaning
> that many patches that were already fixed upstream would be reapplied.
> This could result in many spurious conflicts, as well as reintroduce
> patches that were intentionally dropped upstream.
>
> So the algorithm was changed in c85c79279df2c8a583d95449d1029baba41f8660
> and d44e71261f91d3cc81293e0976bb40daa8abb583.  Defining $old_remote_ref to
> be the most recent entry in the reflog for @{upstream} that is an ancestor
> of $cur_branch, pull --rebase was changed to run
>  git rebase --onto $merge_head $old_remote_ref
> which results in a call to
>  git format-patch ... --ignore-if-in-upstream $old_remote_ref..$cur_branch
>
> The whole point of this change was to reduce the number of commits being
> reapplied, by avoiding commits that upstream already has or had.
>
> In the rebased upstream case, this change achieved that purpose.  It is
> worth noting, though, that since $old_remote_ref is always an ancestor of
> $cur_branch (by its definition), format-patch will not know what upstream
> is and thus will not be able to determine if any patches are already
> upstream; they will all be reapplied.
>
> In the non-rebased upstream case, this new form is usually the same as the
> original code but in some cases $old_remote_ref can be an ancestor of
>   $(git merge-base $merge_head $cur_branch)
> meaning that instead of avoiding reapplying commits that upstream already
> has, it actually includes more such commits.  Combined with the fact that
> format-patch can no longer detect commits that are already upstream (since
> it is no longer told what upstream is), results in lots of confusion for
> users (e.g. "git is giving me lots of conflicts in stuff I didn't even
> change since my last push.")
>
> Fix the non-rebased upstream case by ignoring $old_remote_ref whenever it
> is contained in $(git merge-base $merge_head $cur_branch).  This should
> have no affect on the rebased upstream case.

All this makes sense.

But can you explain when it happens? One possibility is when you don't
fork from the tracking branch as in:

Subject: Difference between pull --rebase and fetch+rebase 						
Message-ID: <27059158.post@xxxxxxxxxxxxxxx>
From: martinvz <martin.von.zweigbergk@xxxxxxxxx>

and this patch should also fix martinvz's issue (I've CC martinvz, can
you test this patch? Thanks).

Can you refer to commits with something like this?

c85c792 (pull --rebase: be cleverer with rebased upstream branches, 2008-01-26)

alias.one !git --no-pager show -s --pretty='tformat:%h (%s, %ad)' --date=short

>
> Signed-off-by: Elijah Newren <newren@xxxxxxxxx>
> ---
>  git-pull.sh     |   34 ++++++++++++++++++++++------------
>  t/t5520-pull.sh |    4 ++--
>  2 files changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/git-pull.sh b/git-pull.sh
> index a09a44e..54da07b 100755
> --- a/git-pull.sh
> +++ b/git-pull.sh
> @@ -206,18 +206,6 @@ test true = "$rebase" && {
>                git diff-index --ignore-submodules --cached --quiet HEAD -- ||
>                die "refusing to pull with rebase: your working tree is not up-to-date"
>        fi
> -       oldremoteref= &&
> -       . git-parse-remote &&
> -       remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
> -       oldremoteref="$(git rev-parse -q --verify "$remoteref")" &&
> -       for reflog in $(git rev-list -g $remoteref 2>/dev/null)
> -       do
> -               if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
> -               then
> -                       oldremoteref="$reflog"
> -                       break
> -               fi
> -       done
>  }
>  orig_head=$(git rev-parse -q --verify HEAD)
>  git fetch $verbosity $progress $dry_run --update-head-ok "$@" || exit 1
> @@ -273,6 +261,28 @@ then
>        exit
>  fi
>
> +if test true = "$rebase"
> +then
> +       oldremoteref= &&
> +       . git-parse-remote &&
> +       remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" &&
> +       oldremoteref="$(git rev-parse -q --verify "$remoteref")" &&
> +       for reflog in $(git rev-list -g $remoteref 2>/dev/null)
> +       do
> +               if test "$reflog" = "$(git merge-base $reflog $curr_branch)"
> +               then
> +                       oldremoteref="$reflog"
> +                       break
> +               fi
> +       done
> +
> +       o=$(git show-branch --merge-base $curr_branch $merge_head $oldremoteref)
> +       if test "$oldremoteref" = "$o"
> +       then
> +               unset oldremoteref
> +       fi
> +fi
> +

You've moved all the lines after the call to "git fetch". It changes
the behavior when the reflog is not enabled, as the old value of
remoteref is lost.

Thanks
Santi
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]