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

Re: [PATCH 1/4] stash: convert apply to builtin

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Mar 25, 2018, 17:23 UTC
Message-ID
<20180325172309.GC10909@hank>
In-Reply-To
<20180324173707.17699-2-joel@teichroeb.net>
On 03/24, Joel Teichroeb wrote:
Show 43 quoted lines
> ---
> [...]
> +
> +static const char *ref_stash = "refs/stash";
> +static int quiet;
> +static char stash_index_path[PATH_MAX];
> +
> +struct stash_info {
> +	struct object_id w_commit;
> +	struct object_id b_commit;
> +	struct object_id i_commit;
> +	struct object_id u_commit;
> +	struct object_id w_tree;
> +	struct object_id b_tree;
> +	struct object_id i_tree;
> +	struct object_id u_tree;
> +	const char *message;
> +	const char *revision;
> +	int is_stash_ref;
> +	int has_u;
> +	const char *patch;
> +};
> +
> +static int get_stash_info(struct stash_info *info, const char *commit)
> +{
> +	struct strbuf w_commit_rev = STRBUF_INIT;
> +	struct strbuf b_commit_rev = STRBUF_INIT;
> +	struct strbuf w_tree_rev = STRBUF_INIT;
> +	struct strbuf b_tree_rev = STRBUF_INIT;
> +	struct strbuf i_tree_rev = STRBUF_INIT;
> +	struct strbuf u_tree_rev = STRBUF_INIT;
> +	struct strbuf commit_buf = STRBUF_INIT;
> +	struct strbuf symbolic = STRBUF_INIT;
> +	struct strbuf out = STRBUF_INIT;
> +	int ret;
> +	const char *revision = commit;
> +	char *end_of_rev;
> +	struct child_process cp = CHILD_PROCESS_INIT;
> +	info->is_stash_ref = 0;
> +
> +	if (commit == NULL) {
> +		strbuf_addf(&commit_buf, "%s@{0}", ref_stash);
> +		revision = commit_buf.buf;

Before setting up the revisions here, as is done below, we used to check if a stash even exists, if no commit was given. So in a repository with no stashes we would die with "No stash entries found", while now we die with "error: refs/stash@{0} is not a valid reference". I think the error message we had previously was slightly nicer, and we should try to keep it.

Show 26 quoted lines
> +	} else if (strspn(commit, "0123456789") == strlen(commit)) {
> +		strbuf_addf(&commit_buf, "%s@{%s}", ref_stash, commit);
> +		revision = commit_buf.buf;
> +	}
> +	info->revision = revision;
> +
> +	strbuf_addf(&w_commit_rev, "%s", revision);
> +	strbuf_addf(&b_commit_rev, "%s^1", revision);
> +	strbuf_addf(&w_tree_rev, "%s:", revision);
> +	strbuf_addf(&b_tree_rev, "%s^1:", revision);
> +	strbuf_addf(&i_tree_rev, "%s^2:", revision);
> +
> +	ret = !get_oid(w_commit_rev.buf, &info->w_commit) &&
> +		!get_oid(b_commit_rev.buf, &info->b_commit) &&
> +		!get_oid(w_tree_rev.buf, &info->w_tree) &&
> +		!get_oid(b_tree_rev.buf, &info->b_tree) &&
> +		!get_oid(i_tree_rev.buf, &info->i_tree);
> +
> +	strbuf_release(&w_commit_rev);
> +	strbuf_release(&b_commit_rev);
> +	strbuf_release(&w_tree_rev);
> +	strbuf_release(&b_tree_rev);
> +	strbuf_release(&i_tree_rev);
> +
> +	if (!ret)
> +		return error(_("%s is not a valid reference"), revision);

We used to distinguish between "not a valid reference" and "not a stash-like commit" here. I think just doing the first 'get_oid' before the others, and returning the error if that fails, and then doing the rest and returning the "not a stash-like commit" if one of the other 'get_oid' calls fails would work, although I did not test it.

Show 23 quoted lines
> +
> +	strbuf_addf(&u_tree_rev, "%s^3:", revision);
> +
> +	info->has_u = !get_oid(u_tree_rev.buf, &info->u_tree);
> +
> +	strbuf_release(&u_tree_rev);
> +
> +	end_of_rev = strchrnul(revision, '@');
> +	strbuf_add(&symbolic, revision, end_of_rev - revision);
> +	cp.git_cmd = 1;
> +	argv_array_pushl(&cp.args, "rev-parse", "--symbolic-full-name", NULL);
> +	argv_array_pushf(&cp.args, "%s", symbolic.buf);
> +	strbuf_release(&symbolic);
> +	pipe_command(&cp, NULL, 0, &out, 0, NULL, 0);
> +
> +	if (out.len - 1 == strlen(ref_stash))
> +		info->is_stash_ref = !strncmp(out.buf, ref_stash, out.len - 1);
> +	strbuf_release(&out);
> +
> +	return 0;
> +}
> +
> [...]
Previous: Joel TeichroebNext: Joel Teichroeb
Message 11 of 25 in “Convert some stash functionality to a builtin”
  1. 0/4 Convert some stash functionality to a builtinJoel Teichroeb, Mar 24, 2018
  2. 1/4 stash: convert apply to builtinJoel Teichroeb, Mar 24, 2018
  3. Christian CouderMar 24, 2018
  4. Eric SunshineMar 25, 2018
  5. Christian CouderMar 25, 2018
  6. Christian CouderMar 25, 2018
  7. Joel TeichroebMar 25, 2018
  8. Christian CouderMar 25, 2018
  9. Thomas GummererMar 25, 2018
  10. Joel TeichroebMar 28, 2018
  11. Thomas GummererMar 25, 2018
  12. 2/4 stash: convert branch to builtinJoel Teichroeb, Mar 24, 2018
  13. Eric SunshineMar 25, 2018
  14. Christian CouderMar 25, 2018
  15. Thomas GummererMar 25, 2018
  16. 3/4 stash: convert drop and clear to builtinJoel Teichroeb, Mar 24, 2018
  17. Christian CouderMar 24, 2018
  18. Eric SunshineMar 25, 2018
  19. 4/4 stash: convert pop to builtinJoel Teichroeb, Mar 24, 2018
  20. Eric SunshineMar 25, 2018
  21. Thomas GummererMar 25, 2018
  22. Thomas GummererMar 25, 2018
  23. Remove contrib/examples/*Ævar Arnfjörð Bjarmason, Mar 25, 2018
  24. Jeff KingMar 26, 2018
  25. Junio C HamanoMar 26, 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.