git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Thomas Rast <trast@student.ethz.ch>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 1/3] rebase: learn to rebase root commit
Date: Thu, 01 Jan 2009 13:00:46 -0800	[thread overview]
Message-ID: <7v4p0iivwh.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 7b2902d36a4790670f20f786d4ea2e26052a6e71.1230639970.git.trast@student.ethz.ch

Thomas Rast <trast@student.ethz.ch> writes:

> Teach git-rebase a new option --root, which instructs it to rebase the
> entire history leading up to <branch>.
>
> The main use-case is with git-svn: suppose you start hacking (perhaps
> offline) on a new project, but later notice you want to commit this
> work to SVN.  You will have to rebase the entire history, including
> the root commit, on a (possibly empty) commit coming from git-svn, to
> establish a history connection.  This previously had to be done by
> cherry-picking the root commit manually.

I like what this series tries to do.  Using the --root option is probably
a more natural way to do what people often do with the "add graft and
filter-branch the whole history once" procedure.

But it somewhat feels sad if the "main" use-case for this is to start your
project in git and then migrate away by feeding your history to subversion
;-).

> @@ -344,17 +348,23 @@ case "$diff" in
>  	;;
>  esac
>  
> +if test -z "$rebase_root"; then
>  # The upstream head must be given.  Make sure it is valid.
> -upstream_name="$1"
> -upstream=`git rev-parse --verify "${upstream_name}^0"` ||
> -    die "invalid upstream $upstream_name"
> +	upstream_name="$1"
> +	shift
> +	upstream=`git rev-parse --verify "${upstream_name}^0"` ||
> +	die "invalid upstream $upstream_name"
> +fi
> +
> +test ! -z "$rebase_root" -a -z "$newbase" &&
> +	die "--root must be used with --onto"

This is much easier to read if it were:

	if test -z "$rebase_root"
        then
        	... do the upstream_name/upstream thing, such as
                upstream_name="$1"
                ...
	else
        	... do the rebase_root thing, including
                unset upstream
                unset upstream_name
                test -z "$newbase" && die "--root without --onto"
                ...
	fi

(Mental note.  You shifted positional parameters and the remainders need
to be adjusted, which you seem to have done).

>  # Make sure the branch to rebase onto is valid.
>  onto_name=${newbase-"$upstream_name"}
>  onto=$(git rev-parse --verify "${onto_name}^0") || exit
>  
>  # If a hook exists, give it a chance to interrupt
> -run_pre_rebase_hook ${1+"$@"}
> +run_pre_rebase_hook ${upstream_name+"$upstream_name"} "$@"

I do not think ${upstream_name+"$upstream_name"} is a good check to begin
with, because presense of it does not necessarily mean the command was
invoked without --root; it could have come from the environment of the
invoker (hence the suggestion to unset the variable explicitly).

And I do not think this is a good way to extend the calling convention of
the hook, either.  pre-rebase-hook used to always take upstream and
optionally the explicit branch name.  When --root is given, your code will
give the hook a single parameter which is the explicit branch name
(i.e. "we will switch to this branch and rebase it, are you Ok with it?"),
but the hook will mistakenly think you are feeding the fork-point commit.

Because an old pre-rebase-hook cannot verify --root case correctly anyway
and needs to be updated, how about doing 'run_pre_rebase_hook --root "$@"'
when --root was given?

> @@ -393,7 +403,8 @@ case "$#" in
>  esac
>  orig_head=$branch
>  
> -# Now we are rebasing commits $upstream..$branch on top of $onto
> +# Now we are rebasing commits $upstream..$branch (or simply $branch
> +# with --root) on top of $onto

"or simply everything leading to $branch if --root is given"?

>  # Check if we are already based on $onto with linear history,
>  # but this should be done only when upstream and onto are the same.
> @@ -429,10 +440,18 @@ then
>  	exit 0
>  fi
>  
> +if test ! -z "$rebase_root"; then
> +	revisions="$orig_head"
> +	fp_flag="--root"
> +else
> +	revisions="$upstream..$orig_head"
> +	fp_flag="--ignore-if-in-upstream"
> +fi

Hmph, the reason why --ignore-if-in-upstream is irrelevant when --root is
given is because...?

> diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh
> new file mode 100755
> index 0000000..63ec5e6
> --- /dev/null
> +++ b/t/t3412-rebase-root.sh
> @@ -0,0 +1,52 @@
> +#!/bin/sh
> +
> +test_description='git rebase --root
> ...
> +test_done

Including tests for the pre-rebase-hook would be nice.

  parent reply	other threads:[~2009-01-01 21:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-29 16:45 [PATCH 0/3] rebase --root Thomas Rast
     [not found] ` <cover.1230569041.git.trast@student.ethz.ch>
2008-12-29 16:45   ` rebase: learn to rebase root commit Thomas Rast
2008-12-29 16:45   ` rebase -i: " Thomas Rast
2008-12-29 21:49     ` Thomas Rast
2008-12-29 22:21       ` Boyd Stephen Smith Jr.
2008-12-30 12:23         ` Thomas Rast
2008-12-30 12:29           ` [PATCH v2 1/3] rebase: " Thomas Rast
2008-12-30 12:29             ` [PATCH v2 2/3] rebase -i: " Thomas Rast
2008-12-30 12:29               ` [PATCH v2 3/3] rebase: update documentation for --root Thomas Rast
2009-01-01 21:00             ` Junio C Hamano [this message]
2009-01-02 18:58               ` [PATCH v2 1/3] rebase: learn to rebase root commit Johannes Schindelin
2009-01-02 22:20               ` Thomas Rast
2009-01-02 22:28                 ` [PATCH v3 1/4] rebase -i: execute hook only after argument checking Thomas Rast
2009-01-02 22:28                   ` [PATCH v3 2/4] rebase: learn to rebase root commit Thomas Rast
2009-01-02 22:28                     ` [PATCH v3 3/4] rebase -i: " Thomas Rast
2009-01-02 22:28                       ` [PATCH v3 4/4] rebase: update documentation for --root Thomas Rast
2009-01-02 22:41                       ` [INTERDIFF v3 3/4] rebase -i: learn to rebase root commit Thomas Rast
2009-01-02 22:41                     ` [INTERDIFF v3 2/4] rebase: " Thomas Rast
2009-01-02 23:06                     ` [PATCH " Junio C Hamano
2009-01-02 23:45                       ` [PATCH v3.1] " Thomas Rast
2009-01-05 17:35                         ` [PATCH v3.2] " Thomas Rast
2009-01-06  8:19                           ` Junio C Hamano
2009-01-02 22:49                 ` [PATCH v2 1/3] " Junio C Hamano
2009-01-02 22:54                   ` Thomas Rast
2009-01-02 23:07                     ` Junio C Hamano
2008-12-30  8:22       ` rebase -i: " Junio C Hamano
2008-12-29 16:45   ` rebase: update documentation for --root Thomas Rast

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=7v4p0iivwh.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=trast@student.ethz.ch \
    /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).