git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 00/11] A minimal builtin rebase

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Sep 4, 2018, 21:27 UTC
Message-ID
<pull.32.v2.git.gitgitgadget@gmail.com>
In-Reply-To
<20180808134830.19949-1-predatoramigo@gmail.com>

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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
      
     -    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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      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 <predatoramigo@gmail.com>
     +    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
-- 
gitgitgadget
Previous: Johannes SchindelinNext: Pratik Karki via GitGitGadget
Message 28 of 42 in “A minimal builtin rebase”
  1. Pratik KarkiAug 8, 2018
  2. 01/11 builtin rebase: support --ontoPratik Karki, Aug 8, 2018
  3. Junio C HamanoAug 8, 2018
  4. Johannes SchindelinAug 24, 2018
  5. 02/11 builtin rebase: support `git rebase --onto A...B`Pratik Karki, Aug 8, 2018
  6. Junio C HamanoAug 8, 2018
  7. Johannes SchindelinAug 26, 2018
  8. 03/11 builtin rebase: handle the pre-rebase hook (and add --no-verify)Pratik Karki, Aug 8, 2018
  9. Junio C HamanoAug 8, 2018
  10. Johannes SchindelinAug 27, 2018
  11. 04/11 builtin rebase: support --quietPratik Karki, Aug 8, 2018
  12. Stefan BellerAug 8, 2018
  13. Junio C HamanoAug 8, 2018
  14. Johannes SchindelinAug 27, 2018
  15. 05/11 builtin rebase: support the `verbose` and `diffstat` optionsPratik Karki, Aug 8, 2018
  16. 06/11 builtin rebase: require a clean worktreePratik Karki, Aug 8, 2018
  17. 07/11 builtin rebase: try to fast forward when possiblePratik Karki, Aug 8, 2018
  18. 08/11 builtin rebase: support --force-rebasePratik Karki, Aug 8, 2018
  19. Stefan BellerAug 8, 2018
  20. Johannes SchindelinAug 24, 2018
  21. 09/11 builtin rebase: start a new rebase only if none is in progressPratik Karki, Aug 8, 2018
  22. Stefan BellerAug 8, 2018
  23. Johannes SchindelinAug 24, 2018
  24. 10/11 builtin rebase: only store fully-qualified refs in `options.head_name`Pratik Karki, Aug 8, 2018
  25. 11/11 builtin rebase: support `git rebase <upstream> <switch-to>`Pratik Karki, Aug 8, 2018
  26. Duy NguyenAug 8, 2018
  27. Johannes SchindelinAug 8, 2018
  28. 00/11 A minimal builtin rebaseJohannes Schindelin via GitGitGadget, Sep 4, 2018
  29. 01/11 builtin rebase: support --ontoPratik Karki via GitGitGadget, Sep 4, 2018
  30. 02/11 builtin rebase: support `git rebase --onto A...B`Pratik Karki via GitGitGadget, Sep 4, 2018
  31. 03/11 builtin rebase: handle the pre-rebase hook and --no-verifyPratik Karki via GitGitGadget, Sep 4, 2018
  32. 04/11 builtin rebase: support --quietPratik Karki via GitGitGadget, Sep 4, 2018
  33. 05/11 builtin rebase: support the `verbose` and `diffstat` optionsPratik Karki via GitGitGadget, Sep 4, 2018
  34. 06/11 builtin rebase: require a clean worktreePratik Karki via GitGitGadget, Sep 4, 2018
  35. 07/11 builtin rebase: try to fast forward when possiblePratik Karki via GitGitGadget, Sep 4, 2018
  36. 08/11 builtin rebase: support --force-rebasePratik Karki via GitGitGadget, Sep 4, 2018
  37. 09/11 builtin rebase: start a new rebase only if none is in progressPratik Karki via GitGitGadget, Sep 4, 2018
  38. 10/11 builtin rebase: only store fully-qualified refs in `options.head_name`Pratik Karki via GitGitGadget, Sep 4, 2018
  39. SZEDER GáborSep 8, 2018
  40. Junio C HamanoSep 10, 2018
  41. SZEDER GáborSep 10, 2018
  42. 11/11 builtin rebase: support `git rebase <upstream> <switch-to>`Pratik Karki via GitGitGadget, Sep 4, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.