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>,
ZheNing Hu <adlternative@gmail.com>
Subject: Re: [PATCH 2/6] [GSOC] ref-filter: add %(raw) atom
Date: Tue, 08 Jun 2021 14:07:28 +0900 [thread overview]
Message-ID: <xmqqa6o1q6zz.fsf@gitster.g> (raw)
In-Reply-To: <0efed9435b59098f3ad928acd46c3c7e9f13677d.1622884415.git.gitgitgadget@gmail.com> (ZheNing Hu via GitGitGadget's message of "Sat, 05 Jun 2021 09:13:30 +0000")
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
> static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struct ref_array_item *b)
> {
> struct atom_value *va, *vb;
> @@ -2389,10 +2452,30 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
> } else if (s->sort_flags & REF_SORTING_VERSION) {
> cmp = versioncmp(va->s, vb->s);
> } else if (cmp_type == FIELD_STR) {
> - int (*cmp_fn)(const char *, const char *);
> - cmp_fn = s->sort_flags & REF_SORTING_ICASE
> - ? strcasecmp : strcmp;
> - cmp = cmp_fn(va->s, vb->s);
> + if (va->s_size == ATOM_VALUE_S_SIZE_INIT &&
> + vb->s_size == ATOM_VALUE_S_SIZE_INIT) {
> + int (*cmp_fn)(const char *, const char *);
> + cmp_fn = s->sort_flags & REF_SORTING_ICASE
> + ? strcasecmp : strcmp;
> + cmp = cmp_fn(va->s, vb->s);
> + } else {
> + int (*cmp_fn)(const void *, const void *, size_t);
> + cmp_fn = s->sort_flags & REF_SORTING_ICASE
> + ? memcasecmp : memcmp;
> + size_t a_size = va->s_size == ATOM_VALUE_S_SIZE_INIT ?
> + strlen(va->s) : va->s_size;
> + size_t b_size = vb->s_size == ATOM_VALUE_S_SIZE_INIT ?
> + strlen(vb->s) : vb->s_size;
This breaks -Wdecl-after-stmt. A possible fix below.
diff --git a/ref-filter.c b/ref-filter.c
index 46aec291de..648f9cabff 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2459,13 +2459,13 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
? strcasecmp : strcmp;
cmp = cmp_fn(va->s, vb->s);
} else {
- int (*cmp_fn)(const void *, const void *, size_t);
- cmp_fn = s->sort_flags & REF_SORTING_ICASE
+ size_t a_size = va->s_size == ATOM_VALUE_S_SIZE_INIT
+ ? strlen(va->s) : va->s_size;
+ size_t b_size = vb->s_size == ATOM_VALUE_S_SIZE_INIT
+ ? strlen(vb->s) : vb->s_size;
+ int (*cmp_fn)(const void *, const void *, size_t) =
+ s->sort_flags & REF_SORTING_ICASE
? memcasecmp : memcmp;
- size_t a_size = va->s_size == ATOM_VALUE_S_SIZE_INIT ?
- strlen(va->s) : va->s_size;
- size_t b_size = vb->s_size == ATOM_VALUE_S_SIZE_INIT ?
- strlen(vb->s) : vb->s_size;
cmp = cmp_fn(va->s, vb->s, b_size > a_size ?
a_size : b_size);
next prev parent reply other threads:[~2021-06-08 5:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-05 9:13 [PATCH 0/6] [GSOC][RFC] ref-filter: add %(raw:textconv) and %(raw:filters) ZheNing Hu via GitGitGadget
2021-06-05 9:13 ` [PATCH 1/6] [GSOC] ref-filter: add obj-type check in grab contents ZheNing Hu via GitGitGadget
2021-06-05 9:13 ` [PATCH 2/6] [GSOC] ref-filter: add %(raw) atom ZheNing Hu via GitGitGadget
2021-06-08 5:07 ` Junio C Hamano [this message]
2021-06-08 6:10 ` ZheNing Hu
2021-06-05 9:13 ` [PATCH 3/6] [GSOC] ref-filter: use non-const ref_format in *_atom_parser() ZheNing Hu via GitGitGadget
2021-06-05 9:13 ` [PATCH 4/6] [GSOC] ref-filter: add %(rest) atom and --rest option ZheNing Hu via GitGitGadget
2021-06-05 15:20 ` Hariom verma
2021-06-06 4:58 ` ZheNing Hu
2021-06-07 5:52 ` Junio C Hamano
2021-06-07 13:02 ` ZheNing Hu
2021-06-07 13:18 ` ZheNing Hu
2021-06-08 6:16 ` ZheNing Hu
2021-06-08 6:59 ` Junio C Hamano
2021-06-08 12:39 ` ZheNing Hu
2021-06-09 7:00 ` Junio C Hamano
2021-06-09 12:47 ` ZheNing Hu
2021-06-08 6:50 ` Junio C Hamano
2021-06-08 12:32 ` ZheNing Hu
2021-06-05 9:13 ` [PATCH 5/6] [GSOC] ref-filter: teach grab_sub_body_contents() return value and err ZheNing Hu via GitGitGadget
2021-06-05 9:13 ` [PATCH 6/6] [GSOC] ref-filter: add %(raw:textconv) and %(raw:filters) ZheNing Hu via GitGitGadget
2021-06-05 10:29 ` [PATCH 0/6] [GSOC][RFC] " Bagas Sanjaya
2021-06-05 13:19 ` ZheNing Hu
2021-06-07 5:55 ` Junio C Hamano
2021-06-07 13:06 ` ZheNing Hu
2021-06-08 6:42 ` Junio C Hamano
2021-06-08 12:52 ` 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqa6o1q6zz.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=adlternative@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=hariom18599@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).