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

Re: [PATCH] diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Oct 4, 2010, 10:53 UTC
Message-ID
<4CA9B217.6050600@lsrfire.ath.cx>
In-Reply-To
<1286184071-28457-1-git-send-email-avarab@gmail.com>
Am 04.10.2010 11:21, schrieb Ævar Arnfjörð Bjarmason:
> -	unsigned mode = canon_mode(S_IFREG | 0644);
> +	unsigned mode = canon_mode((S_IFREG | 0644));
That doesn't look pretty.
How about something like the following instead?  It untangles the
?-:-chain in canon_mode and allows passing of an argument with side
effects.  All the S_ISxxx macros get a single variable as parameter.
Does it fix the issue on NetBSD?
---
 cache.h |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/cache.h b/cache.h
index 2ef2fa3..3d5ed51 100644
--- a/cache.h
+++ b/cache.h
@@ -277,9 +277,16 @@ static inline int ce_to_dtype(const struct cache_entry *ce)
 	else
 		return DT_UNKNOWN;
 }
-#define canon_mode(mode) \
-	(S_ISREG(mode) ? (S_IFREG | ce_permissions(mode)) : \
-	S_ISLNK(mode) ? S_IFLNK : S_ISDIR(mode) ? S_IFDIR : S_IFGITLINK)
+static inline unsigned int canon_mode(unsigned int mode)
+{
+	if (S_ISREG(mode))
+		return S_IFREG | ce_permissions(mode);
+	if (S_ISLNK(mode))
+		return S_IFLNK;
+	if (S_ISDIR(mode))
+		return S_IFDIR;
+	return S_IFGITLINK;
+}
 
 #define flexible_size(STRUCT,len) ((offsetof(struct STRUCT,name) + (len) + 8) & ~7)
 #define cache_entry_size(len) flexible_size(cache_entry,len)
-- 
1.7.3
Previous: Jonathan NiederNext: Matthieu Moy
Message 9 of 13 in “diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning”
  1. diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warningÆvar Arnfjörð Bjarmason, Oct 4, 2010
  2. Jonathan NiederOct 4, 2010
  3. Ævar Arnfjörð BjarmasonOct 4, 2010
  4. Junio C HamanoOct 4, 2010
  5. cache.h: work around broken NetBSD system headersÆvar Arnfjörð Bjarmason, Oct 4, 2010
  6. Ævar Arnfjörð BjarmasonOct 4, 2010
  7. Jonathan NiederOct 4, 2010
  8. Jonathan NiederOct 4, 2010
  9. René ScharfeOct 4, 2010
  10. Matthieu MoyOct 4, 2010
  11. Junio C HamanoOct 4, 2010
  12. René ScharfeOct 4, 2010
  13. yj2133011Oct 4, 2010

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.