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

Re: [PATCH v2 4/4] builtin/rebase: support running "git rebase <upstream>"

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 3, 2018, 21:42 UTC
Message-ID
<xmqqfu10nghi.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180702091509.15950-5-predatoramigo@gmail.com>
Pratik Karki <predatoramigo@gmail.com> writes:
> +static struct commit *peel_committish(const char *name)
> +{
> +	struct object *obj;
> +	struct object_id oid;

It by itself is not a big enough deal to warrant a reroll, but please make it a habit to leave a blank line between the declarations and the first statement (i.e. here), to help readers.

Show 6 quoted lines
> +	if (get_oid(name, &oid))
> +		return NULL;
> +	obj = parse_object(&oid);
> +	return (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
> +}
> +
Show 37 quoted lines
> +{
> +	const char *argv[] = { NULL, NULL };
> +	struct strbuf script_snippet = STRBUF_INIT;
> +	struct argv_array env = ARGV_ARRAY_INIT;
> +	int status;
> +	const char *backend, *backend_func;
> +
> +	argv_array_pushf(&env, "upstream_name=%s", opts->upstream_name);
> +	argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(get_git_dir()));
> +	argv_array_pushf(&env, "upstream=%s",
> +				oid_to_hex(&opts->upstream->object.oid));
> +	argv_array_pushf(&env, "orig_head=%s", oid_to_hex(&opts->orig_head));
> +	argv_array_pushf(&env, "onto=%s",
> +				oid_to_hex(&opts->onto->object.oid));
> +	argv_array_pushf(&env, "onto_name=%s", opts->onto_name);
> +	argv_array_pushf(&env, "revisions=%s", opts->revisions);
> +
> +	switch (opts->type) {
> +		case REBASE_AM:
> +			backend = "git-rebase--am";
> +			backend_func = "git_rebase__am";
> +			break;
> +		case REBASE_INTERACTIVE:
> +			backend = "git-rebase--interactive";
> +			backend_func = "git_rebase__interactive";
> +			break;
> +		case REBASE_MERGE:
> +			backend = "git-rebase--merge";
> +			backend_func = "git_rebase__merge";
> +			break;
> +		case REBASE_PRESERVE_MERGES:
> +			backend = "git-rebase--preserve-merges";
> +			backend_func = "git_rebase__preserve_merges";
> +			break;
> +		default:
> +			BUG("Unhandled rebase type %d", opts->type);
> +			break;

De-dent these lines so that case/default and switch all sit on the same column, and the body of each case arm is indented one level deeper than the case labels.

Show 9 quoted lines
> +	}
> +
> +	strbuf_addf(&script_snippet,
> +		    ". git-rebase--common && . %s && %s",
> +		    backend, backend_func);
> +	argv[0] = script_snippet.buf;
> +
> +	status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, NULL,
> +					  env.argv);

Hmph. These shell variables that tell rebase backend scriptlets what rebase frontend figured out about the request and current state used to be just plain shell variables that are not exported. Now they are exported and visible even to subprocesses these scriptlets spawn. That does not sound safe at all, especially GIT_DIR being among these variables (git-sh-setup sets GIT_DIR but does not export it and that has been very much deliberate).

You should actually be able to avoid exporthing them by building these variable assignment into script_snippet (you need to quote the values properly, using quote.c::sq_quote_buf() etc.), I think, and that would be a more faithful-to-the-original safe covnersion.

Thanks for a pleasant read. This step smells more like WIP, but I can see it is already moving in the right direction. The previous ones (except for the issues I noticed and sent responses separately) looked more-or-less good, too.

Previous: Pratik KarkiNext: Pratik Karki
Message 23 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.