Subject: [PATCH v2 00/11] A minimal builtin rebase

From: "Johannes Schindelin via GitGitGadget" <[email-masked]>
Date: Tue, 04 Sep 2018 14:27:06 -0700 (PDT)

This patch series provides the bare minimum to run more than just the
trivial rebase (i.e. git rebase <upstream>): it implements the most common
options such as --onto.

It is based the latest iteration of pk/rebase-in-c.

This is the second patch series that brings us more closer to a builtin "git
rebase".

Changes since v1:

 * Many commit messages were reworded.
 * An indentation fix was folded into the commit that introduces the
   incorrect indentation.
 * A missing space after a comma was inserted.

Pratik Karki (11):
  builtin rebase: support --onto
  builtin rebase: support `git rebase --onto A...B`
  builtin rebase: handle the pre-rebase hook and --no-verify
  builtin rebase: support --quiet
  builtin rebase: support the `verbose` and `diffstat` options
  builtin rebase: require a clean worktree
  builtin rebase: try to fast forward when possible
  builtin rebase: support --force-rebase
  builtin rebase: start a new rebase only if none is in progress
  builtin rebase: only store fully-qualified refs in `options.head_name`
  builtin rebase: support `git rebase <upstream> <switch-to>`

 builtin/rebase.c | 333 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 320 insertions(+), 13 deletions(-)

base-commit: ac7f467fef8b836084afdce5eded047c79a6858d
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-32%2Fdscho%2Frebase-in-c-2-basic-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-32/dscho/rebase-in-c-2-basic-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/32

Range-diff vs v1:

  1:  c5f67c35ea !  1:  fba1b3e2a9 builtin rebase: support --onto
     @@ -15,6 +15,7 @@
          command name, but to the first (non-option) command-line parameter.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  2:  35d141c32a !  2:  f9826ab58f builtin rebase: support `git rebase --onto A...B`
     @@ -7,12 +7,18 @@
      
          The equivalent shell script version of the code offers two different
          error messages for the cases where there is no merge base vs more than
     -    one merge base. Though following the similar approach would be nice,
     -    this would create more complexity than it is of current. Currently, for
     -    simple convenience, the `get_oid_mb()` function is used whose return
     -    value does not discern between those two error conditions.
     +    one merge base.
     +
     +    Though it would be nice to retain this distinction, dropping it makes it
     +    possible to simply use the `get_oid_mb()` function. Besides, it happens
     +    rarely in real-world scenarios.
     +
     +    Therefore, in the interest of keeping the code less complex, let's just
     +    use that function, and live with an error message that does not
     +    distinguish between those two error conditions.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  3:  e223f2209d !  3:  7100820def builtin rebase: handle the pre-rebase hook (and add --no-verify)
     @@ -1,12 +1,13 @@
      Author: Pratik Karki <[email-masked]>
      
     -    builtin rebase: handle the pre-rebase hook (and add --no-verify)
     +    builtin rebase: handle the pre-rebase hook and --no-verify
      
          This commit converts the equivalent part of the shell script
          `git-legacy-rebase.sh` to run the pre-rebase hook (unless disabled), and
          to interrupt the rebase with error if the hook fails.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  4:  19919e7e24 !  4:  5034f53024 builtin rebase: support --quiet
     @@ -7,19 +7,23 @@
          the rebase command: both `--quiet` and `--verbose` default to `false` if
          neither `--quiet` nor `--verbose` is present.
      
     -    This commit goes further and introduces `--no-quiet` which is the
     -    contrary of `--quiet` and it's introduction doesn't modify any
     -    behaviour.
     +    Despite the default being `false` for both verbose and quiet mode,
     +    passing the `--quiet` option will turn off verbose mode, and `--verbose`
     +    will turn off quiet mode.
      
     -    Note: The `flags` field in `rebase_options` will accumulate more bits in
     -    subsequent commits, in particular a verbose and a diffstat flag. And as
     -    --quoet inthe shell scripted version of the rebase command switches off
     -    --verbose and --stat, and as --verbose switches off --quiet, we use the
     -    (negated) REBASE_NO_QUIET instead of REBASE_QUIET: this allows us to
     -    turn off the quiet mode and turn on the verbose and diffstat mode in a
     -    single OPT_BIT(), and the opposite in a single OPT_NEGBIT().
     +    This patch introduces the `flags` bit field, with `REBASE_NO_QUIET`
     +    as first user (with many more to come).
     +
     +    We do *not* use `REBASE_QUIET` here for an important reason: To keep the
     +    implementation simple, this commit introduces `--no-quiet` instead of
     +    `--quiet`, so that a single `OPT_NEGBIT()` can turn on quiet mode and
     +    turn off verbose and diffstat mode at the same time. Likewise, the
     +    companion commit which will introduce support for `--verbose` will have
     +    a single `OPT_BIT()` that turns off quiet mode and turns on verbose and
     +    diffstat mode at the same time.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  5:  cbf318d0de !  5:  ce1e1f266a builtin rebase: support the `verbose` and `diffstat` options
     @@ -11,6 +11,7 @@
          calling) git_default_config().
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  6:  b440bf9884 !  6:  f11f21d5c6 builtin rebase: require a clean worktree
     @@ -6,6 +6,7 @@
          whether the repository is ready for rebase.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
  7:  0efe9b41f0 !  7:  2ec0b744bf builtin rebase: try to fast forward when possible
     @@ -11,6 +11,7 @@
          rebase).
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
     @@ -105,7 +106,7 @@
      +		if (!(options.flags & REBASE_NO_QUIET))
      +			; /* be quiet */
      +		else if (!strcmp(branch_name, "HEAD") &&
     -+			resolve_ref_unsafe("HEAD", 0, NULL, &flag))
     ++			 resolve_ref_unsafe("HEAD", 0, NULL, &flag))
      +			puts(_("HEAD is up to date, rebase forced."));
      +		else
      +			printf(_("Current branch %s is up to date, rebase "
  8:  ae019dec3f !  8:  78d90e67de builtin rebase: support --force-rebase
     @@ -10,6 +10,7 @@
          fast-forward even if it could.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
     @@ -63,8 +64,4 @@
      +		} else if (!(options.flags & REBASE_NO_QUIET))
       			; /* be quiet */
       		else if (!strcmp(branch_name, "HEAD") &&
     --			resolve_ref_unsafe("HEAD", 0, NULL, &flag))
     -+			 resolve_ref_unsafe("HEAD", 0, NULL, &flag))
     - 			puts(_("HEAD is up to date, rebase forced."));
     - 		else
     - 			printf(_("Current branch %s is up to date, rebase "
     + 			 resolve_ref_unsafe("HEAD", 0, NULL, &flag))
  9:  d58d504c03 !  9:  b639bfa5a8 builtin rebase: start a new rebase only if none is in progress
     @@ -7,6 +7,7 @@
          ongoing rebase operation completes or is terminated.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
     @@ -84,7 +85,7 @@
      +		      "and run me again.  I am stopping in case you still "
      +		      "have something\n"
      +		      "valuable there.\n"),
     -+		    state_dir_base, cmd_live_rebase,buf.buf);
     ++		    state_dir_base, cmd_live_rebase, buf.buf);
      +	}
      +
       	if (!(options.flags & REBASE_NO_QUIET))
 10:  ef468bf3d7 ! 10:  aab01f0b8e builtin rebase: only store fully-qualified refs in `options.head_name`
     @@ -12,6 +12,7 @@
          "detached HEAD" for display only. Make it so.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
 11:  9a26fc3fac ! 11:  e64190d8ed builtin rebase: support `git rebase <upstream> <switch-to>`
     @@ -7,6 +7,7 @@
          `git-legacy-rebase.sh` is converted to builtin `rebase.c`.
      
          Signed-off-by: Pratik Karki <[email-masked]>
     +    Signed-off-by: Johannes Schindelin <[email-masked]>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c

-- 
gitgitgadget