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

Re: [PATCH 2/5] rebase: start implementing it as a builtin

From
Stefan Beller <sbeller@google.com>
Date
Jun 28, 2018, 18:49 UTC
Message-ID
<CAGZ79kZe46nkNd9yRZfwDG_-D-oBV5221qvB5zaj4Vw909U7fw@mail.gmail.com>
In-Reply-To
<20180628074655.5756-3-predatoramigo@gmail.com>
On Thu, Jun 28, 2018 at 12:48 AM Pratik Karki <predatoramigo@gmail.com> wrote:
Show 6 quoted lines
>
> This commit imitates the strategy that was used to convert the
> difftool to a builtin, see be8a90e (difftool: add a skeleton for the
> upcoming builtin, 2017-01-17) for details: This commit renames the
> shell script `git-rebase.sh` to `git-legacy-rebase.sh` and hands off to
> it by default.

That is a good way to start, imitating Johannes approach on rewriting the difftool. Thanks for pointing this out.

Show 10 quoted lines
> The current version of the builtin rebase does not, however, make full
> use of the internals but instead chooses to spawn a couple of Git
> processes to find out if we run the builtin or legacy rebase as that
> keeps the directory that we are in correct. There remains a lot
> of room for improvement, left for a later date. The following commits
> will recreate the functionality of the shell script, in pure C.
>
> We intentionally avoid reading the config directly to avoid
> messing up the GIT_* environment variables when we need to fall back to
> exec()ing the shell script.
Thanks for calling this out!
The test of builtin rebase can be done by
Show 85 quoted lines
> `git -c rebase.useBuiltin=true rebase ...`
>
> Signed-off-by: Pratik Karki <predatoramigo@gmail.com>
> ---
>  .gitignore                            |  1 +
>  Makefile                              |  3 +-
>  builtin.h                             |  1 +
>  builtin/rebase.c                      | 55 +++++++++++++++++++++++++++
>  git-rebase.sh => git-legacy-rebase.sh |  0
>  git.c                                 |  6 +++
>  6 files changed, 65 insertions(+), 1 deletion(-)
>  create mode 100644 builtin/rebase.c
>  rename git-rebase.sh => git-legacy-rebase.sh (100%)
>
> diff --git a/.gitignore b/.gitignore
> index 3284a1e9b..ec2395901 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -78,6 +78,7 @@
>  /git-init-db
>  /git-interpret-trailers
>  /git-instaweb
> +/git-legacy-rebase
>  /git-log
>  /git-ls-files
>  /git-ls-remote
> diff --git a/Makefile b/Makefile
> index 0cb6590f2..e88fe2e5f 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -609,7 +609,7 @@ SCRIPT_SH += git-merge-one-file.sh
>  SCRIPT_SH += git-merge-resolve.sh
>  SCRIPT_SH += git-mergetool.sh
>  SCRIPT_SH += git-quiltimport.sh
> -SCRIPT_SH += git-rebase.sh
> +SCRIPT_SH += git-legacy-rebase.sh
>  SCRIPT_SH += git-remote-testgit.sh
>  SCRIPT_SH += git-request-pull.sh
>  SCRIPT_SH += git-stash.sh
> @@ -1059,6 +1059,7 @@ BUILTIN_OBJS += builtin/prune.o
>  BUILTIN_OBJS += builtin/pull.o
>  BUILTIN_OBJS += builtin/push.o
>  BUILTIN_OBJS += builtin/read-tree.o
> +BUILTIN_OBJS += builtin/rebase.o
>  BUILTIN_OBJS += builtin/rebase--helper.o
>  BUILTIN_OBJS += builtin/receive-pack.o
>  BUILTIN_OBJS += builtin/reflog.o
> diff --git a/builtin.h b/builtin.h
> index 0362f1ce2..44651a447 100644
> --- a/builtin.h
> +++ b/builtin.h
> @@ -202,6 +202,7 @@ extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
>  extern int cmd_pull(int argc, const char **argv, const char *prefix);
>  extern int cmd_push(int argc, const char **argv, const char *prefix);
>  extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
> +extern int cmd_rebase(int argc, const char **argv, const char *prefix);
>  extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix);
>  extern int cmd_receive_pack(int argc, const char **argv, const char *prefix);
>  extern int cmd_reflog(int argc, const char **argv, const char *prefix);
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> new file mode 100644
> index 000000000..1152b7229
> --- /dev/null
> +++ b/builtin/rebase.c
> @@ -0,0 +1,55 @@
> +/*
> + * "git rebase" builtin command
> + *
> + * Copyright (c) 2018 Pratik Karki
> + */
> +
> +#include "builtin.h"
> +#include "run-command.h"
> +#include "exec-cmd.h"
> +#include "argv-array.h"
> +#include "dir.h"
> +
> +static int use_builtin_rebase(void)
> +{
> +       struct child_process cp = CHILD_PROCESS_INIT;
> +       struct strbuf out = STRBUF_INIT;
> +       int ret;
> +
> +       argv_array_pushl(&cp.args,
> +                        "config", "--bool", "rebase.usebuiltin", NULL);

--bool is documented as "Historical options for selecting a type specifier. Prefer instead --type, (see: above)." in the man page of git-config. But as this code will go away once the conversion is done, this is not kept around for long. So we should be fine using the --bool option.

Show 6 quoted lines
> +       cp.git_cmd = 1;
> +       if (capture_command(&cp, &out, 6))
> +               return 0;
> +
> +       strbuf_trim(&out);
> +       ret = !strcmp("true", out.buf);

As --bool will make sure that the config command prints "true" or "false", even when the user configured 0 or 1 instead, this is fine.

Show 7 quoted lines
> +       if (argc != 2)
> +               die("Usage: %s <base>", argv[0]);
> +       prefix = setup_git_directory();
> +       trace_repo_setup(prefix);
> +       setup_work_tree();
> +
> +       die("TODO");

When reading the last sentence in the commit message ("This can be tested ...") I shortly wondered how we adapt the tests but as this is really just the skeleton, there is no need to adapt any tests.

This patch looks fine to me except for the nit that Christian points out.

Thanks! Stefan

Previous: Christian CouderNext: Pratik Karki
Message 6 of 61 in “rebase: rewrite rebase in C”
  1. Pratik KarkiJun 28, 2018
  2. 1/5 Start TODO-rebase.shPratik Karki, Jun 28, 2018
  3. Pratik KarkiJun 28, 2018
  4. 2/5 rebase: start implementing it as a builtinPratik Karki, Jun 28, 2018
  5. Christian CouderJun 28, 2018
  6. Stefan BellerJun 28, 2018
  7. 3/5 rebase: refactor common shell functions into their own filePratik Karki, Jun 28, 2018
  8. Christian CouderJun 28, 2018
  9. Stefan BellerJun 28, 2018
  10. 4/5 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jun 28, 2018
  11. Christian CouderJun 28, 2018
  12. Stefan BellerJun 28, 2018
  13. 5/5 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jun 28, 2018
  14. Stefan BellerJun 28, 2018
  15. [GSoC] [PATCH v2 0/4] rebase: rewrite rebase in CPratik Karki, Jul 2, 2018
  16. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 2, 2018
  17. Junio C HamanoJul 3, 2018
  18. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 2, 2018
  19. Junio C HamanoJul 3, 2018
  20. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 2, 2018
  21. Junio C HamanoJul 3, 2018
  22. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 2, 2018
  23. Junio C HamanoJul 3, 2018
  24. [GSoC] [PATCH v3 0/4] rebase: rewrite rebase in CPratik Karki, Jul 6, 2018
  25. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 6, 2018
  26. Junio C HamanoJul 6, 2018
  27. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 6, 2018
  28. Johannes SchindelinJul 6, 2018
  29. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 6, 2018
  30. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 6, 2018
  31. Junio C HamanoJul 6, 2018
  32. Christian CouderJul 7, 2018
  33. Johannes SchindelinJul 7, 2018
  34. Junio C HamanoJul 7, 2018
  35. Beat BolliJul 17, 2018
  36. Beat BolliJul 17, 2018
  37. [GSoC] [PATCH v4 0/4] rebase: rewrite rebase in CPratik Karki, Jul 8, 2018
  38. 1/4 rebase: start implementing it as a builtinPratik Karki, Jul 8, 2018
  39. Andrei RybakJul 9, 2018
  40. Eric SunshineJul 9, 2018
  41. Pratik KarkiJul 9, 2018
  42. Duy NguyenJul 22, 2018
  43. 2/4 rebase: refactor common shell functions into their own filePratik Karki, Jul 8, 2018
  44. 3/4 sequencer: refactor the code to detach HEAD to checkout.cPratik Karki, Jul 8, 2018
  45. Johannes SchindelinJul 8, 2018
  46. Pratik KarkiJul 9, 2018
  47. Junio C HamanoJul 9, 2018
  48. Pratik KarkiJul 9, 2018
  49. 4/4 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 8, 2018
  50. Johannes SchindelinJul 8, 2018
  51. Johannes SchindelinJul 8, 2018
  52. [GSoC] [PATCH v5 0/3] rebase: rewrite rebase in CPratik Karki, Jul 30, 2018
  53. 1/3 rebase: start implementing it as a builtinPratik Karki, Jul 30, 2018
  54. 2/3 rebase: refactor common shell functions into their own filePratik Karki, Jul 30, 2018
  55. 3/3 builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Jul 30, 2018
  56. Pratik KarkiAug 1, 2018
  57. [GSoC] [PATCH v6 0/3] rebase: rewrite rebase in CPratik Karki, Aug 6, 2018
  58. [GSoC] [PATCH v6 3/3] builtin/rebase: support running "git rebase <upstream>"Pratik Karki, Aug 6, 2018
  59. Junio C HamanoAug 16, 2018
  60. [GSoC] [PATCH v6 2/3] rebase: refactor common shell functions into their own filePratik Karki, Aug 6, 2018
  61. [GSoC] [PATCH v6 1/3] rebase: start implementing it as a builtinPratik Karki, Aug 6, 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.