From: Hiroyuki Sano <sh19910711@gmail.com>
To: git@vger.kernel.org
Cc: Hiroyuki Sano <sh19910711@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v2 3/3][GSOC] fsck: replace if-statements to logical expressions
Date: Wed, 19 Mar 2014 20:23:50 +0900 [thread overview]
Message-ID: <1395228230-10189-3-git-send-email-sh19910711@gmail.com> (raw)
In-Reply-To: <1395228230-10189-1-git-send-email-sh19910711@gmail.com>
There were two different ways to check flag values,
one way is using if-statement, and the other way is
using logical expression.
To make sensible, replace if-statements to logical expressions
in fsck_tree().
When checking "has_dot" and "has_dotdot", use is_dot_or_dotdot()
instead of strcmp() to avoid hard coding.
The is_dot_or_dotdot() is used to check if the string is
either "." or "..".
Include the "dir.h" header file to use is_dot_or_dotdot().
Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
---
fsck.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/fsck.c b/fsck.c
index b3022ad..08f613d 100644
--- a/fsck.c
+++ b/fsck.c
@@ -6,6 +6,7 @@
#include "commit.h"
#include "tag.h"
#include "fsck.h"
+#include "dir.h"
static int fsck_walk_tree(struct tree *tree, fsck_walk_func walk, void *data)
{
@@ -165,18 +166,12 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
sha1 = tree_entry_extract(&desc, &name, &mode);
- if (is_null_sha1(sha1))
- has_null_sha1 = 1;
- if (strchr(name, '/'))
- has_full_path = 1;
- if (!*name)
- has_empty_name = 1;
- if (!strcmp(name, "."))
- has_dot = 1;
- if (!strcmp(name, ".."))
- has_dotdot = 1;
- if (!strcmp(name, ".git"))
- has_dotgit = 1;
+ has_null_sha1 |= is_null_sha1(sha1);
+ has_full_path |= !!strchr(name, '/');
+ has_empty_name |= !*name;
+ has_dot |= is_dot_or_dotdot(name) && !name[1];
+ has_dotdot |= is_dot_or_dotdot(name) && name[1];
+ has_dotgit |= !strcmp(name, ".git");
has_zero_pad |= *(char *)desc.buffer == '0';
update_tree_entry(&desc);
--
1.9.0
next prev parent reply other threads:[~2014-03-19 11:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 11:23 [PATCH v2 1/3][GSOC] diff: rename read_directory() to get_path_list() Hiroyuki Sano
2014-03-19 11:23 ` [PATCH v2 2/3][GSOC] diff: use is_dot_or_dotdot() instead of strcmp() Hiroyuki Sano
2014-03-19 21:15 ` Eric Sunshine
2014-03-19 11:23 ` Hiroyuki Sano [this message]
2014-03-19 18:29 ` [PATCH v2 3/3][GSOC] fsck: replace if-statements to logical expressions Junio C Hamano
2014-03-19 21:15 ` [PATCH v2 1/3][GSOC] diff: rename read_directory() to get_path_list() Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395228230-10189-3-git-send-email-sh19910711@gmail.com \
--to=sh19910711@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).