mirror of
https://github.com/git/git
synced 2024-08-27 03:29:21 +00:00
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>
This commit is contained in:
parent
dca3b5f5ce
commit
20d6421cae
|
@ -1154,20 +1154,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
|
||||||
const char *arg = argv[i];
|
const char *arg = argv[i];
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
struct object_context oc;
|
struct object_context oc;
|
||||||
|
struct object *object;
|
||||||
|
|
||||||
if (!strcmp(arg, "--")) {
|
if (!strcmp(arg, "--")) {
|
||||||
i++;
|
i++;
|
||||||
seen_dashdash = 1;
|
seen_dashdash = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Is it a rev? */
|
|
||||||
if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
|
/* Stop at the first non-rev */
|
||||||
struct object *object = parse_object_or_die(sha1, arg);
|
if (get_sha1_with_context(arg, 0, sha1, &oc))
|
||||||
if (!seen_dashdash)
|
break;
|
||||||
verify_non_filename(prefix, arg);
|
|
||||||
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
|
object = parse_object_or_die(sha1, arg);
|
||||||
continue;
|
if (!seen_dashdash)
|
||||||
}
|
verify_non_filename(prefix, arg);
|
||||||
break;
|
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The rest are paths */
|
/* The rest are paths */
|
||||||
|
|
Loading…
Reference in a new issue