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

Re: [PATCH v3 2/5] stash: convert apply to builtin

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 27, 2018, 16:02 UTC
Message-ID
<nycvar.QRO.7.76.6.1803271744370.77@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz>
In-Reply-To
<20180327054432.26419-3-joel@teichroeb.net>
Hi Joel,
On Mon, 26 Mar 2018, Joel Teichroeb wrote:
Show 14 quoted lines
> Add a bulitin helper for performing stash commands. Converting
> all at once proved hard to review, so starting with just apply
> let conversion get started without the other command being
> finished.
> 
> The helper is being implemented as a drop in replacement for
> stash so that when it is complete it can simply be renamed and
> the shell script deleted.
> 
> Delete the contents of the apply_stash shell function and replace
> it with a call to stash--helper apply until pop is also
> converted.
> 
> Signed-off-by: Joel Teichroeb <joel@teichroeb.net>
Makes sense.
I need a couple of adjustments before it compiles on Windows:
Show 18 quoted lines
> [...]
> +
> +static int do_apply_stash(const char *prefix, struct stash_info *info, int index)
> +{
> +	struct merge_options o;
> +	struct object_id c_tree;
> +	struct object_id index_tree;
> +	const struct object_id *bases[1];
> +	int bases_count = 1;
> +	struct commit *result;
> +	int ret;
> +	int has_index = index;
> +
> +	read_cache_preload(NULL);
> +	if (refresh_cache(REFRESH_QUIET))
> +		return -1;
> +
> +	if (write_cache_as_tree(&c_tree, 0, NULL) || reset_tree(&c_tree, 0, 0))

When applied on top of current `master`, I need to replace the &c_tree by c_tree.hash.

Likewise...
Show 21 quoted lines
> +		return error(_("Cannot apply a stash in the middle of a merge"));
> +
> +	if (index) {
> +		if (!oidcmp(&info->b_tree, &info->i_tree) || !oidcmp(&c_tree, &info->i_tree)) {
> +			has_index = 0;
> +		} else {
> +			struct strbuf out = STRBUF_INIT;
> +
> +			if (diff_tree_binary(&out, &info->w_commit)) {
> +				strbuf_release(&out);
> +				return -1;
> +			}
> +
> +			ret = apply_cached(&out);
> +			strbuf_release(&out);
> +			if (ret)
> +				return -1;
> +
> +			discard_cache();
> +			read_cache();
> +			if (write_cache_as_tree(&index_tree, 0, NULL))
... &index_tree -> index_tree.hash.
These are probably changed to use object_id's already in `pu`, I guess.
I also need this change:
> [...]
> +
> +	index_file = get_index_file();
> +	xsnprintf(stash_index_path, PATH_MAX, "%s.stash.%d", index_file, pid);

Since `pid_t` is `unsigned long long` on Windows, I changed the %d" to %"PRIuMAX and cast `pid` to `(uintmax_t)`.

With those changes, the entire patch series compiles here.

BTW t3903 runs in 13m30s here with this patch series, 14m30s otherwise. That might not seem like much, until you realize that t3903 *still* performs a metric ton of Unix shell scripting outside of `git stash` (and that is the reason for the slowness).

Ciao, Dscho

Previous: Johannes SchindelinNext: Joel Teichroeb
Message 5 of 10 in “Convert some stash functionality to a builtin”
  1. 0/5 Convert some stash functionality to a builtinJoel Teichroeb, Mar 27, 2018
  2. 1/5 stash: improve option parsing test coverageJoel Teichroeb, Mar 27, 2018
  3. 2/5 stash: convert apply to builtinJoel Teichroeb, Mar 27, 2018
  4. Johannes SchindelinMar 27, 2018
  5. Johannes SchindelinMar 27, 2018
  6. Joel TeichroebMar 27, 2018
  7. 3/5 stash: convert drop and clear to builtinJoel Teichroeb, Mar 27, 2018
  8. 4/5 stash: convert branch to builtinJoel Teichroeb, Mar 27, 2018
  9. 5/5 stash: convert pop to builtinJoel Teichroeb, Mar 27, 2018
  10. Johannes SchindelinMar 27, 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.