use logical OR (||) instead of binary OR (|) in logical context

The compiler can short-circuit the evaluation of conditions strung together with logical OR operators instead of computing the resulting bitmask with binary ORs. More importantly, this patch makes the intent of the changed code clearer, because the logical context (as opposed to binary context) becomes immediately obvious. While we're at it, simplify the check for patch->is_rename in builtin/apply.c a bit; it can only be 0 or 1, so we don't need a comparison operator. Signed-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jun 13, 2013 at 20:19 UTC 0b437a18bdd188794cec8855e2a413921d08b6e8
3 files changed +6 -6
builtin/apply.c
+1 -1
@@ -3525,7 +3525,7 @@ static int check_patch(struct patch *patch)
3525 ok_if_exists = 0;
3526
3527 if (new_name &&
3528 - ((0 < patch->is_new) | (0 < patch->is_rename) | patch->is_copy)) {
3528 + ((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {
3529 int err = check_to_create(new_name, ok_if_exists);
3530
3531 if (err && threeway) {
builtin/ls-files.c
+4 -4
@@ -219,7 +219,7 @@ static void show_files(struct dir_struct *dir)
219 if (show_killed)
220 show_killed_files(dir);
221 }
222 - if (show_cached | show_stage) {
222 + if (show_cached || show_stage) {
223 for (i = 0; i < active_nr; i++) {
224 struct cache_entry *ce = active_cache[i];
225 if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -233,7 +233,7 @@ static void show_files(struct dir_struct *dir)
233 (ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
234 }
235 }
236 - if (show_deleted | show_modified) {
236 + if (show_deleted || show_modified) {
237 for (i = 0; i < active_nr; i++) {
238 struct cache_entry *ce = active_cache[i];
239 struct stat st;
@@ -571,8 +571,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
571 die("ls-files --ignored needs some exclude pattern");
572
573 /* With no flags, we default to showing the cached files */
574 - if (!(show_stage | show_deleted | show_others | show_unmerged |
575 - show_killed | show_modified | show_resolve_undo))
574 + if (!(show_stage || show_deleted || show_others || show_unmerged ||
575 + show_killed || show_modified || show_resolve_undo))
576 show_cached = 1;
577
578 if (max_prefix)
builtin/merge-base.c
+1 -1
@@ -107,7 +107,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
107 argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
108 if (!octopus && !reduce && argc < 2)
109 usage_with_options(merge_base_usage, options);
110 - if (is_ancestor && (show_all | octopus | reduce))
110 + if (is_ancestor && (show_all || octopus || reduce))
111 die("--is-ancestor cannot be used with other options");
112 if (is_ancestor)
113 return handle_is_ancestor(argc, argv);