git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Dan McMahill <dmcmahill@NetBSD.org>
Subject: Re: [PATCH] diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning
Date: Mon, 04 Oct 2010 12:53:11 +0200	[thread overview]
Message-ID: <4CA9B217.6050600@lsrfire.ath.cx> (raw)
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

  parent reply	other threads:[~2010-10-04 10:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-04  9:21 [PATCH] diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning Ævar Arnfjörð Bjarmason
2010-10-04  9:35 ` Jonathan Nieder
2010-10-04  9:47   ` Ævar Arnfjörð Bjarmason
2010-10-04 17:54     ` Junio C Hamano
2010-10-04 18:10       ` [PATCH v2] cache.h: work around broken NetBSD system headers Ævar Arnfjörð Bjarmason
2010-10-04  9:42 ` [PATCH] diff: "S_IFREG | 0644" to "(S_IFREG | 0644)" to avoid warning Ævar Arnfjörð Bjarmason
2010-10-04 10:35   ` Jonathan Nieder
2010-10-04 10:50     ` Jonathan Nieder
2010-10-04 10:53 ` René Scharfe [this message]
2010-10-04 11:45   ` Matthieu Moy
2010-10-04 19:23   ` Junio C Hamano
2010-10-04 21:11     ` René Scharfe
2010-10-04 12:28 ` yj2133011

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=4CA9B217.6050600@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=avarab@gmail.com \
    --cc=dmcmahill@NetBSD.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).