grep: re-order rev-parsing loop

We loop over the arguments, but every branch of the loop hits either a "continue" or a "break". Surely we can make this simpler. The final conditional is: if (arg is a rev) { ... handle rev ... continue; } break; We can rewrite this as: if (arg is not a rev) break; ... handle rev ... That makes the flow a little bit simpler, and will make things much easier to follow when we add more logic in future patches. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 14, 2017 at 01:04 UTC 20d6421cae23d33fa153a9251360298ff7f1ce0a
1 file changed +11 -9
builtin/grep.c
+11 -9
@@ -1154,20 +1154,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1154 const char *arg = argv[i];
1155 unsigned char sha1[20];
1156 struct object_context oc;
1157 + struct object *object;
1158 +
1159 if (!strcmp(arg, "--")) {
1160 i++;
1161 seen_dashdash = 1;
1162 break;
1163 }
1162 - /* Is it a rev? */
1163 - if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
1164 - struct object *object = parse_object_or_die(sha1, arg);
1165 - if (!seen_dashdash)
1166 - verify_non_filename(prefix, arg);
1167 - add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
1168 - continue;
1169 - }
1170 - break;
1164 +
1165 + /* Stop at the first non-rev */
1166 + if (get_sha1_with_context(arg, 0, sha1, &oc))
1167 + break;
1168 +
1169 + object = parse_object_or_die(sha1, arg);
1170 + if (!seen_dashdash)
1171 + verify_non_filename(prefix, arg);
1172 + add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
1173 }
1174
1175 /* The rest are paths */