git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Phillip Wood <phillip.wood123@gmail.com>
Subject: Re: [PATCH v5 4/4] builtin/stash: provide a way to import stashes from a ref
Date: Sun, 11 May 2025 23:44:10 +0000	[thread overview]
Message-ID: <aCE2SjpCu5qlwyoK@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <xmqqzfflzhjv.fsf@gitster.g>

[-- Attachment #1: Type: text/plain, Size: 3169 bytes --]

On 2025-05-09 at 19:54:12, Junio C Hamano wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
> 
> > +static int do_import_stash(struct repository *r, const char *rev)
> > +{
> > +	struct object_id chain;
> > +	struct oid_array items = OID_ARRAY_INIT;
> > +	int res = 0;
> > +	int i;
> > +	const char *buffer = NULL;
> > +	struct commit *this = NULL;
> > +	char *msg = NULL;
> > +
> > +	if (repo_get_oid(r, rev, &chain))
> > +		return error(_("not a valid revision: %s"), rev);
> > +
> > +	/*
> > +	 * Walk the commit history, finding each stash entry, and load data into
> > +	 * the array.
> > +	 */
> > +	for (i = 0;; i++) {
> > +		struct object_id tree, oid;
> > +		char revision[GIT_MAX_HEXSZ + 1];
> > +
> > +		oid_to_hex_r(revision, &chain);
> > +
> > +		if (get_oidf(&tree, "%s:", revision) ||
> > +		    !oideq(&tree, r->hash_algo->empty_tree)) {
> > +			res = error(_("%s is not a valid exported stash commit"), revision);
> > +			goto out;
> > +		}
> > +		if (get_oidf(&chain, "%s^1", revision) ||
> > +		    get_oidf(&oid, "%s^2", revision))
> > +			break;
> 
> This is to stop at the sentinel commit at the end.  Don't we want to
> make sure that it actually has the expected shape of the sentinel?
> 
> IOW, how robust do we try to be against being fed a random mergy
> commit history (e.g., our 'master') and mistakenly adding nonsense
> stash entries as refs/stash@{<n>}?

I'll try to make this more robust.  The advantage of the current
approach is that we don't have to parse the buffer, but once we need to
do that, we might as well do the entire thing.

> > +	/*
> > +	 * Now, walk each entry, adding it to the stash as a normal stash
> > +	 * commit.
> > +	 */
> > +	for (i = items.nr - 1; i >= 0; i--) {
> > +		unsigned long bufsize;
> > +		const char *p;
> > +		const struct object_id *oid = items.oid + i;
> > +
> > +		this = lookup_commit_reference(r, oid);
> > +		buffer = repo_get_commit_buffer(r, this, &bufsize);
> > +		if (!buffer) {
> > +			res = error(_("cannot read commit buffer for %s"), oid_to_hex(oid));
> > +			goto out;
> > +		}
> > +
> > +		p = strstr(buffer, "\n\n");
> > +		if (!p) {
> > +			res = error(_("cannot parse commit %s"), oid_to_hex(oid));
> > +			goto out;
> > +		}
> > +
> > +		p += 2;
> > +		msg = xmemdupz(p, bufsize - (p - buffer));
> 
> Here, we could check "git stash: " string to make sure that it is as
> expected in an exported stash we previously made, and abort, just
> like the above "cannot parse" case.

This part doesn't have the prefix.  That's the part above, but I'll add
the check there.  This part instead is the actual stash commit and we're
extracting the message to put into the reflog.

> Should we be making sure that the object named by "oid" does look
> like a stash, like what is done in builtin/stash.c:get_stash_info(),
> or is assert_stash_like() called from do_store_stash() sufficient?

I think `assert_stash_like` should be fine.  I don't have any better
checking to do than that, since we don't have any more checks to do.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]

  reply	other threads:[~2025-05-11 23:49 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-08 23:44 [PATCH v5 0/4] Importing and exporting stashes to refs brian m. carlson
2025-05-08 23:44 ` [PATCH v5 1/4] object-name: make get_oid quietly return an error brian m. carlson
2025-05-09  1:55   ` Junio C Hamano
2025-05-09 19:50     ` brian m. carlson
2025-05-08 23:44 ` [PATCH v5 2/4] builtin/stash: factor out revision parsing into a function brian m. carlson
2025-05-09 15:27   ` Junio C Hamano
2025-05-08 23:44 ` [PATCH v5 3/4] builtin/stash: provide a way to export stashes to a ref brian m. carlson
2025-05-09 16:38   ` Junio C Hamano
2025-05-09 19:31   ` Junio C Hamano
2025-05-10 21:24   ` Jeff King
2025-05-12  9:10   ` Phillip Wood
2025-05-12 15:53     ` Junio C Hamano
2025-05-08 23:44 ` [PATCH v5 4/4] builtin/stash: provide a way to import stashes from " brian m. carlson
2025-05-09 19:54   ` Junio C Hamano
2025-05-11 23:44     ` brian m. carlson [this message]
2025-05-10 17:21   ` Jeff King
2025-05-12 12:42     ` Junio C Hamano
2025-05-12 12:58       ` Jeff King
2025-05-12 16:05         ` Junio C Hamano
2025-05-12 21:19     ` brian m. carlson
2025-05-10 21:33   ` Jeff King
2025-05-12  9:10   ` Phillip Wood
2025-05-09  1:10 ` [PATCH v5 0/4] Importing and exporting stashes to refs Junio C Hamano
2025-05-09 20:16   ` brian m. carlson
2025-05-09 16:53 ` D. Ben Knoble
2025-05-09 20:15   ` brian m. carlson
2025-05-10 19:13     ` D. Ben Knoble
2025-05-22 18:55 ` [PATCH] Makefile: avoid constant rebuilds with compilation database brian m. carlson
2025-05-22 18:55   ` [PATCH v6 0/5] Importing and exporting stashes to refs brian m. carlson
2025-06-01 22:32     ` [PATCH v7 0/4] " brian m. carlson
2025-06-01 22:32       ` [PATCH v7 1/4] object-name: make get_oid quietly return an error brian m. carlson
2025-06-01 22:32       ` [PATCH v7 2/4] builtin/stash: factor out revision parsing into a function brian m. carlson
2025-06-01 22:32       ` [PATCH v7 3/4] builtin/stash: provide a way to export stashes to a ref brian m. carlson
2025-06-05  9:25         ` Phillip Wood
2025-06-11 11:31         ` Kristoffer Haugsbakk
2025-06-11 23:35           ` brian m. carlson
2025-06-01 22:32       ` [PATCH v7 4/4] builtin/stash: provide a way to import stashes from " brian m. carlson
2025-06-05  9:38       ` [PATCH v7 0/4] Importing and exporting stashes to refs Phillip Wood
2025-06-12  1:12       ` [PATCH v8 " brian m. carlson
2025-06-12  1:12         ` [PATCH v8 1/4] object-name: make get_oid quietly return an error brian m. carlson
2025-06-12  1:12         ` [PATCH v8 2/4] builtin/stash: factor out revision parsing into a function brian m. carlson
2025-06-12  1:12         ` [PATCH v8 3/4] builtin/stash: provide a way to export stashes to a ref brian m. carlson
2025-06-12  1:12         ` [PATCH v8 4/4] builtin/stash: provide a way to import stashes from " brian m. carlson
2025-06-25  8:40         ` [PATCH v8 0/4] Importing and exporting stashes to refs Phillip Wood
2025-06-25 16:30           ` Junio C Hamano
2025-05-22 18:55   ` [PATCH v6 1/5] object-name: make get_oid quietly return an error brian m. carlson
2025-05-22 19:27     ` Junio C Hamano
2025-05-22 18:55   ` [PATCH v6 2/5] reflog-walk: expose read_complete_reflog brian m. carlson
2025-05-22 21:53     ` Ramsay Jones
2025-05-23 23:22       ` brian m. carlson
2025-05-24  1:09         ` Ramsay Jones
2025-05-26 19:55           ` brian m. carlson
2025-05-29 16:01     ` Phillip Wood
2025-05-29 21:59       ` Junio C Hamano
2025-05-22 18:55   ` [PATCH v6 3/5] builtin/stash: factor out revision parsing into a function brian m. carlson
2025-05-22 20:34     ` Junio C Hamano
2025-05-23 23:25       ` brian m. carlson
2025-05-24  0:23         ` Junio C Hamano
2025-05-26 19:36           ` brian m. carlson
2025-05-22 18:55   ` [PATCH v6 4/5] builtin/stash: provide a way to export stashes to a ref brian m. carlson
2025-05-22 20:51     ` Junio C Hamano
2025-05-26 19:42       ` brian m. carlson
2025-05-29 16:01     ` Phillip Wood
2025-05-22 18:55   ` [PATCH v6 5/5] builtin/stash: provide a way to import stashes from " brian m. carlson
2025-05-22 21:09     ` Junio C Hamano
2025-05-26 20:03       ` brian m. carlson
2025-05-22 21:15     ` Junio C Hamano
2025-05-23 13:17       ` Phillip Wood
2025-05-22 19:00   ` [PATCH] Makefile: avoid constant rebuilds with compilation database brian m. carlson
2025-05-22 19:08     ` Junio C Hamano
2025-06-11 11:35 ` [PATCH v5 0/4] Importing and exporting stashes to refs Kristoffer Haugsbakk
2025-06-12  0:45   ` brian m. carlson

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=aCE2SjpCu5qlwyoK@tapette.crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).