pathspec: always show mnemonic and name in unsupported_magic

For better clarity, always show the mnemonic and name of the unsupported magic being used. This lets users have a more clear understanding of what magic feature isn't supported. And if they supplied a mnemonic, the user will be told what its corresponding name is which will allow them to more easily search the man pages for that magic type. This also avoids passing an extra parameter around the pathspec initialization code. Signed-off-by: Brandon Williams <bmwill@google.com> Reviewed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jan 4, 2017 at 10:04 UTC 2aee5849c9b3698b65d74bc354f3cee7213add35
1 file changed +9 -15
pathspec.c
+9 -15
@@ -101,9 +101,7 @@ static void prefix_short_magic(struct strbuf *sb, int prefixlen,
101 * the prefix part must always match literally, and a single stupid
102 * string cannot express such a case.
103 */
104 -static unsigned prefix_pathspec(struct pathspec_item *item,
105 - unsigned *p_short_magic,
106 - unsigned flags,
104 +static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
105 const char *prefix, int prefixlen,
106 const char *elt)
107 {
@@ -210,7 +208,6 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
208 }
209
210 magic |= short_magic;
213 - *p_short_magic = short_magic;
211
212 /* --noglob-pathspec adds :(literal) _unless_ :(glob) is specified */
213 if (noglob_global && !(magic & PATHSPEC_GLOB))
@@ -329,8 +326,7 @@ static int pathspec_item_cmp(const void *a_, const void *b_)
326 }
327
328 static void NORETURN unsupported_magic(const char *pattern,
332 - unsigned magic,
333 - unsigned short_magic)
329 + unsigned magic)
330 {
331 struct strbuf sb = STRBUF_INIT;
332 int i;
@@ -339,9 +335,11 @@ static void NORETURN unsupported_magic(const char *pattern,
335 if (!(magic & m->bit))
336 continue;
337 if (sb.len)
342 - strbuf_addch(&sb, ' ');
343 - if (short_magic & m->bit)
344 - strbuf_addf(&sb, "'%c'", m->mnemonic);
338 + strbuf_addstr(&sb, ", ");
339 +
340 + if (m->mnemonic)
341 + strbuf_addf(&sb, _("'%s' (mnemonic: '%c')"),
342 + m->name, m->mnemonic);
343 else
344 strbuf_addf(&sb, "'%s'", m->name);
345 }
@@ -413,11 +411,9 @@ void parse_pathspec(struct pathspec *pathspec,
411 prefixlen = prefix ? strlen(prefix) : 0;
412
413 for (i = 0; i < n; i++) {
416 - unsigned short_magic;
414 entry = argv[i];
415
419 - item[i].magic = prefix_pathspec(item + i, &short_magic,
420 - flags,
416 + item[i].magic = prefix_pathspec(item + i, flags,
417 prefix, prefixlen, entry);
418 if ((flags & PATHSPEC_LITERAL_PATH) &&
419 !(magic_mask & PATHSPEC_LITERAL))
@@ -425,9 +421,7 @@ void parse_pathspec(struct pathspec *pathspec,
421 if (item[i].magic & PATHSPEC_EXCLUDE)
422 nr_exclude++;
423 if (item[i].magic & magic_mask)
428 - unsupported_magic(entry,
429 - item[i].magic & magic_mask,
430 - short_magic);
424 + unsupported_magic(entry, item[i].magic & magic_mask);
425
426 if ((flags & PATHSPEC_SYMLINK_LEADING_PATH) &&
427 has_symlink_leading_path(item[i].match, item[i].len)) {