From: Patrick Steinhardt <ps@pks.im>
To: Thalia Archibald <thalia@archibald.dev>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 2/8] fast-import: directly use strbufs for paths
Date: Wed, 10 Apr 2024 08:27:11 +0200 [thread overview]
Message-ID: <ZhYxP42Br2h1mq5r@tanuki> (raw)
In-Reply-To: <82a6f53c1326a420348eb70461f5929340a930d3.1711960552.git.thalia@archibald.dev>
[-- Attachment #1: Type: text/plain, Size: 6430 bytes --]
On Mon, Apr 01, 2024 at 09:03:06AM +0000, Thalia Archibald wrote:
> Previously, one case would not write the path to the strbuf: when the
> path is unquoted and at the end of the string. It was essentially
> copy-on-write. However, with the logic simplification of the previous
> commit, this case was eliminated and the strbuf is always populated.
>
> Directly use the strbufs now instead of an alias.
>
> Since this already changes all the lines that use the strbufs, rename
> them from `uq` to be more descriptive. That they are unquoted is not
> their most important property, so name them after what they carry.
>
> Additionally, `file_change_m` no longer needs to copy the path before
> reading inline data.
>
> Signed-off-by: Thalia Archibald <thalia@archibald.dev>
> ---
> builtin/fast-import.c | 64 ++++++++++++++++++-------------------------
> 1 file changed, 27 insertions(+), 37 deletions(-)
>
> diff --git a/builtin/fast-import.c b/builtin/fast-import.c
> index 6f9048a037..fad9324e59 100644
> --- a/builtin/fast-import.c
> +++ b/builtin/fast-import.c
> @@ -2305,7 +2305,
> 7 @@ static void parse_path_space(struct strbuf *sb, const char *p, const char **endp
>
> static void file_change_m(const char *p, struct branch *b)
> {
> - static struct strbuf uq = STRBUF_INIT;
> + static struct strbuf path = STRBUF_INIT;
> struct object_entry *oe;
> struct object_id oid;
> uint16_t mode, inline_data = 0;
> @@ -2342,13 +2342,12 @@ static void file_change_m(const char *p, struct branch *b)
> die("Missing space after SHA1: %s", command_buf.buf);
> }
>
> - strbuf_reset(&uq);
> - parse_path_eol(&uq, p, "path");
> - p = uq.buf;
> + strbuf_reset(&path);
> + parse_path_eol(&path, p, "path");
>
> /* Git does not track empty, non-toplevel directories. */
> - if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *p) {
> - tree_content_remove(&b->branch_tree, p, NULL, 0);
> + if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
> + tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
> return;
> }
>
> @@ -2369,10 +2368,6 @@ static void file_change_m(const char *p, str
> uct branch *b)
> if (S_ISDIR(mode))
> die("Directories cannot be specified 'inline': %s",
> command_buf.buf);
> - if (p != uq.buf) {
> - strbuf_addstr(&uq, p);
> - p = uq.buf;
> - }
> while (read_next_command() != EOF) {
> const char *v;
> if (skip_prefix(command_buf.buf, "cat-blob ", &v))
> @@ -2398,55 +2393,51 @@ static void file_change_m(const char *p, struct branch *b)
> command_buf.buf);
> }
>
> - if (!*p) {
> + if (!*path.buf) {
> tree_content_replace(&b->branch_tree, &oid, mode, NULL);
> return;
> }
> - tree_content_set(&b->branch_tree, p, &oid, mode, NULL);
> + tree_content_set(&b->branch_tree, path.buf, &oid, mode, NULL);
> }
>
> static void file_change_d(const char *p, struct branch *b)
> {
> - static struct strbuf uq = STRBUF_INIT;
> + static struct strbuf path = STRBUF_INIT;
>
> - strbuf_reset(&uq);
> - parse_path_eol(&uq, p, "path");
> - p = uq.buf;
> - tree_content_remove(&b->branch_tree, p, NULL, 1);
> + strbuf_reset(&path);
> + parse_path_eol(&path, p
> , "path");
This looks weird. Did you manually edit the patch or is there some weird
character in here that breaks diff generation?
> + tree_content_remove(&b->branch_tree, path.buf, NULL, 1);
> }
>
> static void file_change_cr(const char *p, struct branch *b, int rename)
> {
> - const char *s, *d;
> - static struct strbuf s_uq = STRBUF_INIT;
> - static struct strbuf d_uq = STRBUF_INIT;
> + static struct strbuf source = STRBUF_INIT;
> + static struct strbuf dest = STRBUF_INIT;
> struct tree_entry leaf;
>
> - strbuf_reset(&s_uq);
> - parse_path_space(&s_uq, p, &p, "source");
> - s = s_uq.buf;
> + strbuf_reset(&source);
> + parse_path_space(&source, p, &p, "source");
>
> if (!p)
> die("Missing dest: %s", command_buf.buf);
> - strbuf_reset(&d_uq);
> - parse_path_eol(&d_uq, p, "dest");
> - d = d_uq.buf;
> + strbuf_reset(&dest);
> + parse_path_eol(&dest, p, "dest");
>
> memset(&leaf, 0, sizeof(leaf));
> if (rename)
> - tree_content_remove(&b->branch_tree, s, &leaf, 1);
> + tree_content_remove(&b->branch_tree, source.buf, &leaf, 1);
> else
> - tree_content_get(&b->branch_tree, s, &leaf, 1);
> + tree_content_get(&b-
> >branch_tree, source.buf, &leaf, 1);
Same here. Is your mail agent maybe wrapping lines?
> if (!leaf.versions[1].mode)
> - die("Path %s not in branch", s);
> - if (!*d) { /* C "path/to/subdir" "" */
> + die("Path %s not in branch", source.buf);
> + if (!*dest.buf) { /* C "path/to/subdir" "" */
> tree_content_replace(&b->branch_tree,
> &leaf.versions[1].oid,
> leaf.versions[1].mode,
> leaf.tree);
> return;
> }
> - tree_content_set(&b->branch_tree, d,
> + tree_content_set(&b->branch_tree, dest.buf,
> &leaf.versions[1].oid,
> leaf.versions[1].mode,
> leaf.tree);
> @@ -3174,7 +3165,7 @@ static void print_ls(int mode, const unsigned char *hash, const char *path)
>
> static void parse_ls(const char *p, struct branch *b)
> {
> - static struct strbuf uq = STRBUF_INIT;
> + static struct strbuf path = STRBUF_INIT;
> struct tree_entry *root = NULL;
> struct tree_entry leaf = {NULL};
>
> @@ -3191,10 +3182,9 @@ static void parse_ls(const char *p, struct branch *b)
> root->versions[1].mode = S_IFDIR;
> load_tree(root);
> }
> - s
> trbuf_reset(&uq);
And here.
Other than those formatting issues this patch looks fine to me.
Patrick
> - parse_path_eol(&uq, p, "path");
> - p = uq.buf;
> - tree_content_get(root, p, &leaf, 1);
> + strbuf_reset(&path);
> + parse_path_eol(&path, p, "path");
> + tree_content_get(root, path.buf, &leaf, 1);
> /*
> * A directory in preparation would have a sha1 of zero
> * until it is saved. Save, for simplicity.
> @@ -3202,7 +3192,7 @@ static void parse_ls(const char *p, struct branch *b)
> if (S_ISDIR(leaf.versions[1].mode))
> store_tree(&leaf);
>
> - print_ls(leaf.versions[1].mode, leaf.versions[1].oid.hash, p);
> + print_ls(leaf.versions[1].mode, leaf.versions[1].oid.hash, path.buf);
> if (leaf.tree)
> release_tree_content_recursive(leaf.tree);
> if (!b || root != &b->branch_tree)
> --
> 2.44.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-04-10 6:27 UTC|newest]
Thread overview: 84+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 0:03 [PATCH 0/6] fast-import: tighten parsing of paths Thalia Archibald
2024-03-22 0:03 ` [PATCH 1/6] " Thalia Archibald
2024-03-22 0:11 ` Thalia Archibald
2024-03-28 8:21 ` Patrick Steinhardt
[not found] ` <E01C617F-3720-42C0-83EE-04BB01643C86@archibald.dev>
2024-04-01 9:05 ` Thalia Archibald
2024-03-22 0:03 ` [PATCH 2/6] fast-import: directly use strbufs for paths Thalia Archibald
2024-03-28 8:21 ` Patrick Steinhardt
2024-03-22 0:03 ` [PATCH 3/6] fast-import: release unfreed strbufs Thalia Archibald
2024-03-28 8:21 ` Patrick Steinhardt
2024-04-01 9:06 ` Thalia Archibald
2024-03-22 0:03 ` [PATCH 4/6] fast-import: remove dead strbuf Thalia Archibald
2024-03-28 8:21 ` Patrick Steinhardt
2024-03-22 0:03 ` [PATCH 5/6] fast-import: document C-style escapes for paths Thalia Archibald
2024-03-28 8:21 ` Patrick Steinhardt
2024-04-01 9:06 ` Thalia Archibald
2024-03-22 0:03 ` [PATCH 6/6] fast-import: forbid escaped NUL in paths Thalia Archibald
2024-04-01 9:02 ` [PATCH v2 0/8] fast-import: tighten parsing of paths Thalia Archibald
2024-04-01 9:02 ` [PATCH v2 1/8] fast-import: tighten path unquoting Thalia Archibald
2024-04-10 6:27 ` Patrick Steinhardt
2024-04-10 8:18 ` Chris Torek
2024-04-10 8:44 ` Thalia Archibald
2024-04-10 8:51 ` Chris Torek
2024-04-10 9:14 ` Thalia Archibald
2024-04-10 9:42 ` Patrick Steinhardt
2024-04-10 9:16 ` Thalia Archibald
2024-04-10 9:12 ` Thalia Archibald
2024-04-01 9:03 ` [PATCH v2 2/8] fast-import: directly use strbufs for paths Thalia Archibald
2024-04-10 6:27 ` Patrick Steinhardt [this message]
2024-04-10 10:07 ` Thalia Archibald
2024-04-10 10:18 ` Patrick Steinhardt
2024-04-01 9:03 ` [PATCH v2 3/8] fast-import: allow unquoted empty path for root Thalia Archibald
2024-04-10 6:27 ` Patrick Steinhardt
2024-04-01 9:03 ` [PATCH v2 4/8] fast-import: remove dead strbuf Thalia Archibald
2024-04-01 9:03 ` [PATCH v2 5/8] fast-import: improve documentation for unquoted paths Thalia Archibald
2024-04-01 9:03 ` [PATCH v2 6/8] fast-import: document C-style escapes for paths Thalia Archibald
2024-04-01 9:03 ` [PATCH v2 7/8] fast-import: forbid escaped NUL in paths Thalia Archibald
2024-04-01 9:03 ` [PATCH v2 8/8] fast-import: make comments more precise Thalia Archibald
2024-04-07 21:19 ` [PATCH v2 0/8] fast-import: tighten parsing of paths Thalia Archibald
2024-04-07 23:46 ` Eric Sunshine
2024-04-08 6:25 ` Patrick Steinhardt
2024-04-08 7:15 ` Thalia Archibald
2024-04-08 9:07 ` Patrick Steinhardt
2024-04-08 14:52 ` Junio C Hamano
2024-04-10 9:54 ` [PATCH v3 " Thalia Archibald
2024-04-10 9:55 ` [PATCH v3 1/8] fast-import: tighten path unquoting Thalia Archibald
2024-04-10 9:55 ` [PATCH v3 2/8] fast-import: directly use strbufs for paths Thalia Archibald
2024-04-10 9:55 ` [PATCH v3 3/8] fast-import: allow unquoted empty path for root Thalia Archibald
2024-04-11 19:59 ` Junio C Hamano
2024-04-10 9:55 ` [PATCH v3 4/8] fast-import: remove dead strbuf Thalia Archibald
2024-04-11 19:53 ` Junio C Hamano
2024-04-10 9:55 ` [PATCH v3 5/8] fast-import: improve documentation for unquoted paths Thalia Archibald
2024-04-11 19:51 ` Junio C Hamano
2024-04-10 9:56 ` [PATCH v3 6/8] fast-import: document C-style escapes for paths Thalia Archibald
2024-04-10 18:28 ` Junio C Hamano
2024-04-10 22:50 ` Thalia Archibald
2024-04-11 5:32 ` Junio C Hamano
2024-04-11 9:14 ` Patrick Steinhardt
2024-04-10 9:56 ` [PATCH v3 7/8] fast-import: forbid escaped NUL in paths Thalia Archibald
2024-04-10 18:51 ` Junio C Hamano
2024-04-10 9:56 ` [PATCH v3 8/8] fast-import: make comments more precise Thalia Archibald
2024-04-10 19:21 ` Junio C Hamano
2024-04-12 8:01 ` [PATCH v4 0/8] fast-import: tighten parsing of paths Thalia Archibald
2024-04-12 8:02 ` [PATCH v4 1/8] fast-import: tighten path unquoting Thalia Archibald
2024-04-12 16:34 ` Junio C Hamano
2024-04-13 0:07 ` Thalia Archibald
2024-04-13 18:33 ` Junio C Hamano
2024-04-12 8:03 ` [PATCH v4 2/8] fast-import: directly use strbufs for paths Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 3/8] fast-import: allow unquoted empty path for root Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 4/8] fast-import: remove dead strbuf Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 5/8] fast-import: improve documentation for path quoting Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 6/8] fast-import: document C-style escapes for paths Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 7/8] fast-import: forbid escaped NUL in paths Thalia Archibald
2024-04-12 8:03 ` [PATCH v4 8/8] fast-import: make comments more precise Thalia Archibald
2024-04-14 1:11 ` [PATCH v5 0/8] fast-import: tighten parsing of paths Thalia Archibald
2024-04-14 1:11 ` [PATCH v5 1/8] fast-import: tighten path unquoting Thalia Archibald
2024-04-14 1:11 ` [PATCH v5 2/8] fast-import: directly use strbufs for paths Thalia Archibald
2024-04-14 1:11 ` [PATCH v5 3/8] fast-import: allow unquoted empty path for root Thalia Archibald
2024-04-14 1:11 ` [PATCH v5 4/8] fast-import: remove dead strbuf Thalia Archibald
2024-04-14 1:12 ` [PATCH v5 5/8] fast-import: improve documentation for path quoting Thalia Archibald
2024-04-14 1:12 ` [PATCH v5 6/8] fast-import: document C-style escapes for paths Thalia Archibald
2024-04-14 1:12 ` [PATCH v5 7/8] fast-import: forbid escaped NUL in paths Thalia Archibald
2024-04-14 1:12 ` [PATCH v5 8/8] fast-import: make comments more precise Thalia Archibald
2024-04-15 7:06 ` [PATCH v5 0/8] fast-import: tighten parsing of paths Patrick Steinhardt
2024-04-15 17:07 ` Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZhYxP42Br2h1mq5r@tanuki \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
--cc=thalia@archibald.dev \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).