git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3][GSOC] fsck: use bitwise-or assignment operator to set flag

From
Hiroyuki Sano <sh19910711@gmail.com>
Date
Mar 19, 2014, 23:02 UTC
Message-ID
<1395270124-2242-1-git-send-email-sh19910711@gmail.com>

fsck_tree() has two different ways to set a flag, which are the followings:

  1. Using a if-statement that guards assignment.
  2. Using a bitwise-or assignment operator.

Currently, many with the former way, and one with the latter way.

In this patch, unify them to the latter way, because it makes the code shorter and easier to read, and it is brief and to the point.

Signed-off-by: Hiroyuki Sano <sh19910711@gmail.com>
---
 fsck.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/fsck.c b/fsck.c
index b3022ad..abed62b 100644
--- a/fsck.c
+++ b/fsck.c
@@ -165,18 +165,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 |= !strcmp(name, ".");
+		has_dotdot |= !strcmp(name, "..");
+		has_dotgit |= !strcmp(name, ".git");
 		has_zero_pad |= *(char *)desc.buffer == '0';
 		update_tree_entry(&desc);
 
-- 
1.9.0
Next: Junio C Hamano
Message 1 of 4 in “[GSOC] fsck: use bitwise-or assignment operator to set flag”
  1. [GSOC] fsck: use bitwise-or assignment operator to set flagHiroyuki Sano, Mar 19, 2014
  2. Junio C HamanoMar 20, 2014
  3. Junio C HamanoMar 20, 2014
  4. HiroyukiMar 20, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.