pathspec: small readability changes

A few small changes to improve readability. This is done by grouping related assignments, adding blank lines, ensuring lines are <80 characters, and adding additional comments. 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 4f1bf4d2b48cc2dc755e1a61f7e807e3963b33fa
1 file changed +15 -10
pathspec.c
+15 -10
@@ -67,11 +67,11 @@ static struct pathspec_magic {
67 char mnemonic; /* this cannot be ':'! */
68 const char *name;
69 } pathspec_magic[] = {
70 - { PATHSPEC_FROMTOP, '/', "top" },
71 - { PATHSPEC_LITERAL, 0, "literal" },
72 - { PATHSPEC_GLOB, '\0', "glob" },
73 - { PATHSPEC_ICASE, '\0', "icase" },
74 - { PATHSPEC_EXCLUDE, '!', "exclude" },
70 + { PATHSPEC_FROMTOP, '/', "top" },
71 + { PATHSPEC_LITERAL, '\0', "literal" },
72 + { PATHSPEC_GLOB, '\0', "glob" },
73 + { PATHSPEC_ICASE, '\0', "icase" },
74 + { PATHSPEC_EXCLUDE, '!', "exclude" },
75 };
76
77 static void prefix_magic(struct strbuf *sb, int prefixlen, unsigned magic)
@@ -336,6 +336,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
336 if ((magic & PATHSPEC_LITERAL) && (magic & PATHSPEC_GLOB))
337 die(_("%s: 'literal' and 'glob' are incompatible"), elt);
338
339 + /* Create match string which will be used for pathspec matching */
340 if (pathspec_prefix >= 0) {
341 match = xstrdup(copyfrom);
342 prefixlen = pathspec_prefix;
@@ -343,11 +344,16 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
344 match = xstrdup(copyfrom);
345 prefixlen = 0;
346 } else {
346 - match = prefix_path_gently(prefix, prefixlen, &prefixlen, copyfrom);
347 + match = prefix_path_gently(prefix, prefixlen,
348 + &prefixlen, copyfrom);
349 if (!match)
350 die(_("%s: '%s' is outside repository"), elt, copyfrom);
351 }
352 +
353 item->match = match;
354 + item->len = strlen(item->match);
355 + item->prefix = prefixlen;
356 +
357 /*
358 * Prefix the pathspec (keep all magic) and assign to
359 * original. Useful for passing to another command.
@@ -364,8 +370,6 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
370 } else {
371 item->original = xstrdup(elt);
372 }
367 - item->len = strlen(item->match);
368 - item->prefix = prefixlen;
373
374 if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP)
375 strip_submodule_slash_cheap(item);
@@ -373,13 +377,14 @@ static unsigned prefix_pathspec(struct pathspec_item *item, unsigned flags,
377 if (flags & PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE)
378 strip_submodule_slash_expensive(item);
379
376 - if (magic & PATHSPEC_LITERAL)
380 + if (magic & PATHSPEC_LITERAL) {
381 item->nowildcard_len = item->len;
378 - else {
382 + } else {
383 item->nowildcard_len = simple_length(item->match);
384 if (item->nowildcard_len < prefixlen)
385 item->nowildcard_len = prefixlen;
386 }
387 +
388 item->flags = 0;
389 if (magic & PATHSPEC_GLOB) {
390 /*