From: Junio C Hamano <gitster@pobox.com>
To: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
Christian Couder <christian.couder@gmail.com>,
Hariom Verma <hariom18599@gmail.com>,
Karthik Nayak <karthik.188@gmail.com>,
Felipe Contreras <felipe.contreras@gmail.com>,
Bagas Sanjaya <bagasdotme@gmail.com>, Jeff King <peff@peff.net>,
Phillip Wood <phillip.wood123@gmail.com>,
ZheNing Hu <adlternative@gmail.com>
Subject: Re: [PATCH 2/2] [GSOC] ref-filter: add %(raw) atom
Date: Thu, 03 Jun 2021 11:38:19 +0900 [thread overview]
Message-ID: <xmqqsg1z65b8.fsf@gitster.g> (raw)
In-Reply-To: <5a94705cdbc101169488919e35613d723e6ec581.1622558243.git.gitgitgadget@gmail.com> (ZheNing Hu via GitGitGadget's message of "Tue, 01 Jun 2021 14:37:23 +0000")
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
> @@ -644,13 +664,6 @@ static int parse_ref_filter_atom(const struct ref_format *format,
> return strbuf_addf_ret(err, -1, _("malformed field name: %.*s"),
> (int)(ep-atom), atom);
>
> - /* Do we have the atom already used elsewhere? */
> - for (i = 0; i < used_atom_cnt; i++) {
> - int len = strlen(used_atom[i].name);
> - if (len == ep - atom && !memcmp(used_atom[i].name, atom, len))
> - return i;
> - }
> -
> /*
> * If the atom name has a colon, strip it and everything after
> * it off - it specifies the format for this entry, and
> @@ -660,6 +673,17 @@ static int parse_ref_filter_atom(const struct ref_format *format,
> arg = memchr(sp, ':', ep - sp);
> atom_len = (arg ? arg : ep) - sp;
>
> + if (format->quote_style && !strncmp(sp, "raw", 3) && !arg)
> + return strbuf_addf_ret(err, -1, _("--format=%.*s cannot be used with"
> + "--python, --shell, --tcl, --perl"), (int)(ep-atom), atom);
> +
> + /* Do we have the atom already used elsewhere? */
> + for (i = 0; i < used_atom_cnt; i++) {
> + int len = strlen(used_atom[i].name);
> + if (len == ep - atom && !memcmp(used_atom[i].name, atom, len))
> + return i;
> + }
> +
These two hunks
- hoists up the code that sets 'arg' to optional string after
"<atom>:" and counts how long the "<atom>" is in 'atom_len'; the
change causes the counting done even when the same placeholder is
already used elsewhere (in which case we do not have to do such
counting);
- inserts the early return to reject use of "raw" atom when
language specific quoting is used.
It probably makes it easier to understand if the former is split
into a separate commit, but at the same time a series with too many
small steps is harder to manage, so let's keep them in a single
change.
But I do not think we want to add the new change at this location,
at least for two reasons:
* The posted patch checks '!arg' to avoid rejecting "raw:size",
which would not scale at all. What if you wanted to later add
"raw:upcase", which you must reject?
* We do have enumerated constants for each atom types, but this
early check and return does string comparison.
Where it belongs is either after "Is the atom a valid one?" loop
where 'atom_len' is used to locate the placeholder's atom in the
table of valid atoms [*], or inside raw_atom_parser().
Side note: If you read the original code, you would notice that
there already is a similar "this is a valid atom that appear in
the valid_atom[] table, but unallowed in this situation" check
done with .source != SOURCE_NONE conditional. One downside is
that until calling raw_atom_parser(), you do not know if
RAW_BARE or RAW_LENGTH is requested.
If we do inside raw_atom_parser(), it would probably look like this:
+static int raw_atom_parser(const struct ref_format *format, struct used_atom *atom,
+ const char *arg, struct strbuf *err)
+{
+ if (!arg)
+ atom->u.raw_data.option = RAW_BARE;
+ else if (!strcmp(arg, "size"))
+ atom->u.raw_data.option = RAW_LENGTH;
+ else
+ return strbuf_addf_ret(err, -1, _("unrecognized %%(raw) argument: %s"), arg);
+
+ if (atom->u.raw_data.option == RAW_BARE && format->quote_style)
+ return strbuf_addf_ret(err, -1,
+ _("--format=%%(raw) cannot be used with ...")...);
+
+ return 0;
+}
next prev parent reply other threads:[~2021-06-03 2:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-01 14:37 [PATCH 0/2] [GSOC] ref-filter: add %(raw) atom ZheNing Hu via GitGitGadget
2021-06-01 14:37 ` [PATCH 1/2] [GSOC] ref-filter: add obj-type check in grab contents ZheNing Hu via GitGitGadget
2021-06-03 2:10 ` Junio C Hamano
2021-06-03 4:52 ` ZheNing Hu
2021-06-01 14:37 ` [PATCH 2/2] [GSOC] ref-filter: add %(raw) atom ZheNing Hu via GitGitGadget
2021-06-03 2:38 ` Junio C Hamano [this message]
2021-06-03 5:36 ` ZheNing Hu
2021-06-03 14:06 ` ZheNing Hu
2021-06-03 21:36 ` Junio C Hamano
2021-06-03 21:35 ` Junio C Hamano
2021-06-04 10:59 ` ZheNing Hu
2021-06-03 5:11 ` [PATCH 0/2] " Bagas Sanjaya
2021-06-03 5:37 ` ZheNing Hu
2021-06-04 12:12 ` [PATCH v2 " ZheNing Hu via GitGitGadget
2021-06-04 12:12 ` [PATCH v2 1/2] [GSOC] ref-filter: add obj-type check in grab contents ZheNing Hu via GitGitGadget
2021-06-04 12:12 ` [PATCH v2 2/2] [GSOC] ref-filter: add %(raw) atom ZheNing Hu via GitGitGadget
2021-06-04 13:23 ` Christian Couder
2021-06-04 12:53 ` [PATCH v2 0/2] " Christian Couder
2021-06-05 4:34 ` ZheNing Hu
2021-06-05 4:49 ` Christian Couder
2021-06-05 5:42 ` ZheNing Hu
2021-06-05 6:45 ` Christian Couder
2021-06-05 8:05 ` ZheNing Hu
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=xmqqsg1z65b8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=adlternative@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=christian.couder@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=hariom18599@gmail.com \
--cc=karthik.188@gmail.com \
--cc=peff@peff.net \
--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.
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).