From: Thomas Gummerer <t.gummerer@gmail.com>
To: Joel Teichroeb <joel@teichroeb.net>
Cc: Git Mailing List <git@vger.kernel.org>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 1/4] stash: convert apply to builtin
Date: Sun, 25 Mar 2018 18:23:09 +0100 [thread overview]
Message-ID: <20180325172309.GC10909@hank> (raw)
In-Reply-To: <20180324173707.17699-2-joel@teichroeb.net>
On 03/24, Joel Teichroeb wrote:
> ---
> [...]
> +
> +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.
> + } 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.
> +
> + 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;
> +}
> +
> [...]
next prev parent reply other threads:[~2018-03-25 17:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-24 17:37 [PATCH 0/4] Convert some stash functionality to a builtin Joel Teichroeb
2018-03-24 17:37 ` [PATCH 1/4] stash: convert apply to builtin Joel Teichroeb
2018-03-24 18:19 ` Christian Couder
2018-03-25 6:40 ` Eric Sunshine
2018-03-25 9:27 ` Christian Couder
2018-03-25 8:09 ` Christian Couder
2018-03-25 16:51 ` Joel Teichroeb
2018-03-25 19:58 ` Christian Couder
[not found] ` <20180325204653.1470-1-avarab@gmail.com>
2018-03-25 20:57 ` [PATCH] Remove contrib/examples/* Ævar Arnfjörð Bjarmason
2018-03-26 6:01 ` Jeff King
2018-03-26 20:58 ` Junio C Hamano
2018-03-25 16:43 ` [PATCH 1/4] stash: convert apply to builtin Thomas Gummerer
2018-03-28 3:30 ` Joel Teichroeb
2018-03-25 17:23 ` Thomas Gummerer [this message]
2018-03-24 17:37 ` [PATCH 2/4] stash: convert branch " Joel Teichroeb
2018-03-25 6:44 ` Eric Sunshine
2018-03-25 8:22 ` Christian Couder
2018-03-25 17:02 ` Thomas Gummerer
2018-03-24 17:37 ` [PATCH 3/4] stash: convert drop and clear " Joel Teichroeb
2018-03-24 18:22 ` Christian Couder
2018-03-25 6:49 ` Eric Sunshine
2018-03-24 17:37 ` [PATCH 4/4] stash: convert pop " Joel Teichroeb
2018-03-25 6:51 ` Eric Sunshine
2018-03-25 17:36 ` Thomas Gummerer
2018-03-25 17:39 ` [PATCH 0/4] Convert some stash functionality to a builtin Thomas Gummerer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180325172309.GC10909@hank \
--to=t.gummerer@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=joel@teichroeb.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.