summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-02-14 06:04:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-14 19:26:37 (GMT)
commit20d6421cae23d33fa153a9251360298ff7f1ce0a (patch)
tree3224c79d889ecaec395df449eaa5fde30ef8867d /builtin/grep.c
parentdca3b5f5cef8138e695f87e6cb37fb2063a10ea4 (diff)
downloadgit-20d6421cae23d33fa153a9251360298ff7f1ce0a.zip
git-20d6421cae23d33fa153a9251360298ff7f1ce0a.tar.gz
git-20d6421cae23d33fa153a9251360298ff7f1ce0a.tar.bz2
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>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 081e1b5..461347a 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1154,20 +1154,22 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
const char *arg = argv[i];
unsigned char sha1[20];
struct object_context oc;
+ struct object *object;
+
if (!strcmp(arg, "--")) {
i++;
seen_dashdash = 1;
break;
}
- /* Is it a rev? */
- if (!get_sha1_with_context(arg, 0, sha1, &oc)) {
- struct object *object = parse_object_or_die(sha1, arg);
- if (!seen_dashdash)
- verify_non_filename(prefix, arg);
- add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
- continue;
- }
- break;
+
+ /* Stop at the first non-rev */
+ if (get_sha1_with_context(arg, 0, sha1, &oc))
+ break;
+
+ object = parse_object_or_die(sha1, arg);
+ if (!seen_dashdash)
+ verify_non_filename(prefix, arg);
+ add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
}
/* The rest are paths */