Message ID | 20210326024005.26962-3-stdedos+git@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | pathspec: warn: long and short forms are incompatible | expand |
On 26/03/21 09.40, Σταύρος Ντέντος wrote: > From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> > > malloc and stuff > --- > pathspec.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) What does this fixup patch try to accomplish? Give more details. > diff --git a/pathspec.c b/pathspec.c > index 374c529569..4ac8bfdc06 100644 > --- a/pathspec.c > +++ b/pathspec.c > @@ -7,6 +7,7 @@ > #include "attr.h" > #include "strvec.h" > #include "quote.h" > +#include "git-compat-util.h" > > /* > * Finds which of the given pathspecs match items in the index. > @@ -745,16 +746,20 @@ int match_pathspec_attrs(const struct index_state *istate, > } > > void check_mishandled_exclude(const char *entry) { > + char *flags, *path; > size_t entry_len = strlen(entry); > - char flags[entry_len]; > - char path[entry_len]; > > - if (sscanf(entry, ":!(%4096[^)])%4096s", &flags, &path) != 2) { > - return; > - } > - if (count_slashes(flags) > 0) { > - return; > + flags = xstrdup(entry); > + memset(flags, '\0', entry_len); > + path = xstrdup(entry); > + memset(path, '\0', entry_len); > + > + if (sscanf(entry, ":!(%4096[^)])%4096s", flags, path) == 2) { > + if (count_slashes(flags) == 0) { > + warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); > + } > } > > - warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); Message looks ok. > + FREE_AND_NULL(flags); > + FREE_AND_NULL(path); > } >
I merely wanted to give visibility on the "resulting" patch https://lore.kernel.org/git/20210326024411.28615-2-stdedos+git@gmail.com/, by giving the two versions of the implementation (as discussed in the https://lore.kernel.org/git/20210326024005.26962-1-stdedos+git@gmail.com/ cover)
diff --git a/pathspec.c b/pathspec.c index 374c529569..4ac8bfdc06 100644 --- a/pathspec.c +++ b/pathspec.c @@ -7,6 +7,7 @@ #include "attr.h" #include "strvec.h" #include "quote.h" +#include "git-compat-util.h" /* * Finds which of the given pathspecs match items in the index. @@ -745,16 +746,20 @@ int match_pathspec_attrs(const struct index_state *istate, } void check_mishandled_exclude(const char *entry) { + char *flags, *path; size_t entry_len = strlen(entry); - char flags[entry_len]; - char path[entry_len]; - if (sscanf(entry, ":!(%4096[^)])%4096s", &flags, &path) != 2) { - return; - } - if (count_slashes(flags) > 0) { - return; + flags = xstrdup(entry); + memset(flags, '\0', entry_len); + path = xstrdup(entry); + memset(path, '\0', entry_len); + + if (sscanf(entry, ":!(%4096[^)])%4096s", flags, path) == 2) { + if (count_slashes(flags) == 0) { + warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); + } } - warning(_("Pathspec provided matches `:!(...)`\n\tDid you mean `:(exclude,...)`?")); + FREE_AND_NULL(flags); + FREE_AND_NULL(path); }
From: Stavros Ntentos <133706+stdedos@users.noreply.github.com> malloc and stuff --- pathspec.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)