From patchwork Thu Jul 18 08:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736164 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8D9B110A for ; Thu, 18 Jul 2024 08:16:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290572; cv=none; b=VR3HAk4wFDWvq30nfI9zQx8wB7DK865Q7S+Mxe6buzQtMBCaeafPtjHlsj6lMuxXVUgtLo4nQaltW0zGGSKwXzpUFIxd4M2DTL/7iQiwek6bgE5Jg3hRFTftHDftbXPITWXYtJUcjVYn+vtiWhXEnGmlotxZMoRyLhsoN8EVb9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290572; c=relaxed/simple; bh=fXYkwyyNJCLwx/1+LXMILAXgVK2bnFuuMMrPjySB8G8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LWoARwvKmTVvbR6B3hksvj7gPTKmGTo7qzukCEnV6MYcQ2u4WRp8tuHsWHc6ZldvqTxGsjJ6cUxhJik+8UHiFVrYzxBCnV7jPC3QAeBDdp1r2VpwOjM6hCZVLqmg3CexyKDf0fbzY9CAS2x8xrnK92HrL1xt5HRiJV28XhFN9zM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EmRNVTNF; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EmRNVTNF" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-42795086628so215755e9.3 for ; Thu, 18 Jul 2024 01:16:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290569; x=1721895369; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IXE3MYu8CxgvrX1p6ggHUE0kt8dF7SAUpXUFx2O4fgw=; b=EmRNVTNFmGOvWYjgngvIdW+E+D2Fk0hKUJC6cpRXTLGrvOLoIfDvV2lbibCICAZEpt 0Yf1onVRGLq5O7vdRJi5yCwwn93oRkYTBRKgNmcxDH48IVPmKwMpQSe30hECFxFdaUy7 oquXUYAwIwt/l8HHjDVQztVNsM69qinqdFHbULE3sjY8QEsHix+uK+01sECNXgGJ+EfP skM9KwvKWIqWN4iPqbnj39oHi856tx+kWRwoY7ph/UtevwONAfpBj35MKnuOFLGOZn0p 5iI44hq7GgiepluwiOWAnZtHo6Yf/JfHaVsZEQo72riZIZjB2PVqWOO1HhsXOEzN3bDV //Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290569; x=1721895369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IXE3MYu8CxgvrX1p6ggHUE0kt8dF7SAUpXUFx2O4fgw=; b=t2A2xOs3hI1SmhNU5yo0+d9klFvFP9PjXN0XJaC5PVFT5Zueh0AcAigfdWHeh6qMgN NWGCsY+HLddLOIIPk8kTNH32Vp7Fp0u4KKk9KJ1P+9FNlnPFajXBgZHihwIgF/RICWBC NCwXkc1I3hH2dF/f9QEg4Xme49ocJCFQe1+Cw5ovpSQhi4xSSvFtkBUZfGCwjnIHL3Vr tRGBT+fiy+5bUVWEl7/dg+Zd6pM5DuIxbN6Nm1vH+QJ0Aeh6MMrEs5FSVvLTbvbw2KK8 +ipZL0V4gxFZ/q5O/aATnhMGuJ0/NfErIS84nQo6Ge2mXeqXU+j5gzQbCQNEZ541hwDj RZuA== X-Forwarded-Encrypted: i=1; AJvYcCVuMYfAj93t08/EZF8LHhiD7eOzQRzxqsIp8pY/N/+kDnv2bnpZpTuSFDcSuOa2o7COqlZ11Jmq0vlsjEmXFmpTUwBX X-Gm-Message-State: AOJu0Yy4FS3wucCEu2EhKANJmsVy+4ij2C7bjWrHenqktc2lt6rYyI9t z2shAVVn39fuZbNOnWpvGkWLnxtHlXnSw4sMQy4asqMm9tm+ckVk X-Google-Smtp-Source: AGHT+IEJ8pRvb0rHyikUuD9q60lmFBA6ioXoEGqtRIM23eNPdjCbb8nex+8xZ/+Y6W4FPXsACUIAmQ== X-Received: by 2002:a05:600c:5249:b0:426:63b8:2cce with SMTP id 5b1f17b1804b1-427c2ca7a3amr26562595e9.7.1721290569024; Thu, 18 Jul 2024 01:16:09 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:08 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 1/6] clang-format: indent preprocessor directives after hash Date: Thu, 18 Jul 2024 10:16:00 +0200 Message-ID: <20240718081605.452366-2-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We do not have a rule around the indentation of preprocessor directives. This was also discussed on the list [1], noting how there is often inconsistency in the styling. While there was discussion, there was no conclusion around what is the preferred style here. One style being indenting after the hash: #if FOO # if BAR # include # endif #endif The other being before the hash: #if FOO #if BAR #include #endif #endif Let's pick the former and add 'IndentPPDirectives: AfterHash' value to our '.clang-format'. There is no clear reason to pick one over the other, but it would definitely be nicer to be consistent. [1]: https://lore.kernel.org/r/xmqqwmmm1bw6.fsf@gitster.g Signed-off-by: Karthik Nayak --- .clang-format | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.clang-format b/.clang-format index 3ed4fac753..5e128519bf 100644 --- a/.clang-format +++ b/.clang-format @@ -96,6 +96,12 @@ BreakStringLiterals: false # Switch statement body is always indented one level more than case labels. IndentCaseLabels: false +# Indents directives before the hash. +# #if FOO +# # include +# #endif +IndentPPDirectives: AfterHash + # Don't indent a function definition or declaration if it is wrapped after the # type IndentWrappedFunctionNames: false From patchwork Thu Jul 18 08:16:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736166 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1244455886 for ; Thu, 18 Jul 2024 08:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290573; cv=none; b=aTM3DpGcYJAUY3xaDY2SwW1mwntfdw0ZJG0QXIkkJ8ryOZEXocavsiaA7QE/a1qYuju2ouJbvXlNZws9NdTq7jiwnvSgAVIRvUKPr7A6LvYZ/a0f5UKy0pMo3yqr4j38fJPvW57zVFgqszbb5GaZaNFLQPwd6UxjCJXlqITb0ZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290573; c=relaxed/simple; bh=c57a5FZo8oc1XwZXmAykTqE3C++vUFM1nNGdVk7APJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PS8q6IjKmDC8estF8/8QsrD6t96dGRKTVeyOqXOAojn/YzjpjAiOuc4oN3utxi2EYu4K1IKSz/FAngPqsEKgSdBCm/lYsxRXj7dmD0sfMgHvnty/WzxTxVSyRMhTEajuF3s5a4clH5+cAwiZjPFUP+gzHThOQRA4xff5VewqArI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TdNMjT26; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TdNMjT26" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-368440b073bso245635f8f.0 for ; Thu, 18 Jul 2024 01:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290570; x=1721895370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dGFI5dxykS0Ye5JgwzTOfeSKS/2TqbyMZWuGeO3hO3Y=; b=TdNMjT26TIZm6LnyIDrXxutiyLMFg9G7+weDNGyV47BMtwh6WA4//8CIYQu7iNB+e7 BjuXZoajyIA02+iHKT0FsvLe3XYB4ZYc7ujXJXw+1LfQe+cH8idZoTaW7IBYscIdxl7D 4xDtW/H3m9YI6F0AcJ285uovOkYl8kP09pXyqhWg8926+Ubl5mKcxPwCIXI+DNnsxwgg qbPgAQV+1F4Sz3Ss2xkAeZBWaeEzAh15upvYcWXN/+fgC5ytcmbeE/g4fKJXxhOztWsr ltBBVLdZN+fBRpfLtFfUIe6AQ5ZuIJu6JrhctReVt6LZ8i09kQbDi4W2T/nCTZIe8n5r deDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290570; x=1721895370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dGFI5dxykS0Ye5JgwzTOfeSKS/2TqbyMZWuGeO3hO3Y=; b=K1h9MYuLH6VvzO/NZpSfskinSABZ3HGzPiPAXJMJeF/EXS6/TfzJ9nMBGZ2RMtn5Mw AHIkmp6JXAg0KnRdaIRueTKfZjDKbPFeWLDUZVwLmgE63Cx4tbHjg/w0YQeupaTwcFli CEv9+DY/kADfFVXmR8hOQd4JcW2v0Ravrinmth+EjV/PpZFtPhFGHft7WcLQNwPvAl6B 7dkdBakVksPKONT9n1WHeU1DGLXMsGIjd3iz3vi6sJ8HcJwvvLR3JRdL2v0kdkjZhUcQ vkk4oe/iIEsW4PKd11evXfmlogBnCahmIizHPDGHewBqCFIJuUDf2RJEkjP6l0tRi+KR UPNA== X-Forwarded-Encrypted: i=1; AJvYcCVpzD8Ai9mFZCrQokf77ralWt7gyvrHJ3F5jz4IUCD85q5E0V3k3XQ+UFQMAMN/LD7coXQz0aMYxvrLNy9O5fgmXUUm X-Gm-Message-State: AOJu0Yw7eBw8cXGOkIHlD9jDk+SpNwkd6//83vxG4GZ355a8dDjU4BBC 8oA07dcoBGOxiWF0M27TOYxgrHaxDRg4AwG5N3RdI4mgxUhkQ3SN X-Google-Smtp-Source: AGHT+IEZVfkzM/OPQrp+gws3Pd8voF01Gl4YOZj1Z5CoYTgVlL1WBbtiAJxF68hI/zPwnIvAVSQKvA== X-Received: by 2002:adf:f583:0:b0:366:ee84:6a77 with SMTP id ffacd0b85a97d-3684b378973mr1125401f8f.3.1721290569949; Thu, 18 Jul 2024 01:16:09 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:09 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 2/6] clang-format: avoid spacing around bitfield colon Date: Thu, 18 Jul 2024 10:16:01 +0200 Message-ID: <20240718081605.452366-3-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The spacing around colons is currently not standardized and as such we have the following practices in our code base: - Spacing around the colon `int bf : 1`: 146 instances - No spacing around the colon `int bf:1`: 148 instances - Spacing before the colon `int bf :1`: 6 instances - Spacing after the colon `int bf: 1`: 12 instances Let's formalize this by picking the most followed pattern and add the corresponding style to '.clang-format'. Signed-off-by: Karthik Nayak --- .clang-format | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.clang-format b/.clang-format index 5e128519bf..803b274dd5 100644 --- a/.clang-format +++ b/.clang-format @@ -72,6 +72,10 @@ AlwaysBreakAfterReturnType: None BinPackArguments: true BinPackParameters: true +# Add no space around the bit field +# unsigned bf:2; +BitFieldColonSpacing: None + # Attach braces to surrounding context except break before braces on function # definitions. # void foo() From patchwork Thu Jul 18 08:16:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736167 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E72B278297 for ; Thu, 18 Jul 2024 08:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290574; cv=none; b=t+HS1pvPZOZJKga5Cj497Eezvk2kJxrhnfkK3MJ2GBFNjm2fhzF4VyqpIKyiBfcCYj0UNf8i8r+SDqV8HSypVosfOhggNjbMXUW9ZMY4kkxwBjZzwC8fj2b2Oow2q56kAdAKV4osjYexY6nRtzv/3aLj7jclCKePLZWUM5HhUpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290574; c=relaxed/simple; bh=f+9t1NpkVoe+I5qn36ZdOhXw0efovMxsbbnwFmTI/jE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mHBXhCvhQnsFItjbsP7WBgmj/7Gv6PDrZajLgQJTEhvXGKiFwNTg6/4eKeRfguZisqK0zQdFCdSi/So558YqMwj7DkXmIIfwUIKakUxMDEqyrgW0S4ipaUp17Vf/r0G5PpBac/1jmPgynPKENhlRgBPuWxk4XE+Ea7hhGXRgASg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PCoXuuT3; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PCoXuuT3" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4266b1f1b21so299005e9.1 for ; Thu, 18 Jul 2024 01:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290571; x=1721895371; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kW/pu3ynQau+YcaNh9IHKcFwebEUBcLLIFlf5rzAZnM=; b=PCoXuuT3COoH2/wr1gCw/4PKNcox8hXyGkpfCjPkKcIw7JE/XqePCrDfGlgB+WT03X dNVPxYGB2QBWJC/KMar4Rg1hSeTvRkXC6MJb4YXAIcs3z++EqpFvRIcvj3OEJsM1mFRY 8L+yYDSYBGXqqVn+8CT1nD1hiagpYiiAtqARWFkXA9mNAkhYqQ/3T22cwE9z/9B30mHL 5iOsYq8TFJdu0u6Lx+c+jXYuBn5YGWumANMpp22daROH1PJycJsi+Iu5GPf7QAGZpZ+O NqHk0k07eqg9r+RhnJutOQyYU3F1v2k6Qsfmwc0JejCQpO7hSJpvgBZqk4gZL4C6PtHW aDXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290571; x=1721895371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kW/pu3ynQau+YcaNh9IHKcFwebEUBcLLIFlf5rzAZnM=; b=Mneepe92jzc8uyn0rEkh4YqjPy98iwOLjqoDnzgDceWsEpoK2JGSiFJEdAmhAxj5Gc 8G1Gvqu5bMXDftErQv6DvPp418Q6ERITgLwoIsiO1DNdsfCtFk9x5urS4ccTKXWIpaNd 4QSKkf/EZfMhWpReL3hrdUZHSTb0qiuTV+qIzLLy7qqxhVpNugr/1rIPDKweB7d+6V1j VqQU7k085pn/xfXpVaO/vABxL2qMXg2LceBk/c+fA05POnzmO3GtVjUp9MRJRq7Qz12y rmBqjl4kj4DFYh5hkD18/q0aESPABgExkr+fsP1rMXYG7Gw4O4If7tguTeldkEwbYVvm wH7A== X-Forwarded-Encrypted: i=1; AJvYcCUbrZNc20c1Uws3AG0qw942d6m41TKcOfjOSsrLby/LERdiEa2KyFML1U9Gp/YP2l5glYMa8tIj3472rrfDCSIEp4m7 X-Gm-Message-State: AOJu0Yy0hchWYy1LFnO1ETl8TFSTk5SWTxpJVECGpEGhovUfRQ58vB0m o7XvEAfXpHlhvsjdadyl/PkGZl6rWBW+w3G01tUsPbuef1bDqHiT X-Google-Smtp-Source: AGHT+IGXW74rq+If94GdfoGeQQgRyrGCxzjDu5ioyd18xJauLkPzcInNdbysHmDWyThNn1ovyOiwYw== X-Received: by 2002:a05:600c:1f82:b0:426:5f0b:a49b with SMTP id 5b1f17b1804b1-427c2cd1533mr28663015e9.23.1721290571222; Thu, 18 Jul 2024 01:16:11 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:10 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 3/6] clang-format: formalize some of the spacing rules Date: Thu, 18 Jul 2024 10:16:02 +0200 Message-ID: <20240718081605.452366-4-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are some spacing rules that we follow in the project and it makes sense to formalize them: * Ensure there is no space inserted after the logical not '!' operator. * Ensure there is no space before the case statement's colon. * Ensure there is no space before the first bracket '[' of an array. * Ensure there is no space in empty blocks. Signed-off-by: Karthik Nayak --- .clang-format | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.clang-format b/.clang-format index 803b274dd5..3c8018a1dd 100644 --- a/.clang-format +++ b/.clang-format @@ -118,11 +118,18 @@ PointerAlignment: Right # x = (int32)y; not x = (int32) y; SpaceAfterCStyleCast: false +# No space is inserted after the logical not operator +SpaceAfterLogicalNot: false + # Insert spaces before and after assignment operators # int a = 5; not int a=5; # a += 42; a+=42; SpaceBeforeAssignmentOperators: true +# Spaces will be removed before case colon. +# case 1: break; not case 1 : break; +SpaceBeforeCaseColon: false + # Put a space before opening parentheses only after control statement keywords. # void f() { # if (true) { @@ -134,6 +141,14 @@ SpaceBeforeParens: ControlStatements # Don't insert spaces inside empty '()' SpaceInEmptyParentheses: false +# No space before first '[' in arrays +# int a[5][5]; not int a [5][5]; +SpaceBeforeSquareBrackets: false + +# No space will be inserted into {} +# while (true) {} not while (true) { } +SpaceInEmptyBlock: false + # The number of spaces before trailing line comments (// - comments). # This does not affect trailing block comments (/* - comments). SpacesBeforeTrailingComments: 1 From patchwork Thu Jul 18 08:16:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736168 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 111EE7A715 for ; Thu, 18 Jul 2024 08:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290575; cv=none; b=CkIAwQJS/TM6P2q2+x4/9x1E7d9FGGvajkbUXhcCNUjBvQ6Hp3oVvEbNMg8h275tJf5FOYeXUPEsnYtVFMIP/C56mW3pk4WsLResYJzCu5Cxsci8hoJmWSuLfxBVjlb4cE2Zrv86WxvBdqNlP15QoF47i7E0FyO305r0gB42Cx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290575; c=relaxed/simple; bh=rwLRnsKYvUFoDTFgof5PRJgbWZQ/MQGM9ZzsJ3UvzeE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KUlmCCkXJQbI/eg1uQzvkpfM4t7Zl7UbPQ4pT5HV+L4Ggawn25Tbxzfmg0GpvMFNHA2pRNVTpy9PRiG56R9P2sWww47T9lcfphcCUeDKQJP2A2kpuqqj7sznqio/Y872Ih4DUDLBSeoEBrivOmdMqAPSNYSJCEHBd7YJXc8S3fY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QqfBd0l2; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QqfBd0l2" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4266f535e82so293455e9.1 for ; Thu, 18 Jul 2024 01:16:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290572; x=1721895372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=scaJXtQ683x4rg7PUZYMvNACcRxGHUThDZRqfOQfi3M=; b=QqfBd0l2XRMxC0ah3v8+/Vs64HT1I/AGkA1OJyLHfkDqulCl/g5o6ZKsX+pmBoh66t RjuI06PTw2iI8QzZzmj3N3CEADyuLqoebt/2IBXADZe8w2iaBwIWYQnI9/d5vyIEw/ZT TFBPFy2pGFlHCcEHR/UiKuVVAZBAetedTpZpFq+FcQHCRoDqpUBwKETe5uiDmJKXwwbF uMxiGiV0pa/5s+497Khu6YSxCX3h0GNTNGmHPcZgef/KMGN1JmfovPf3Z8JGr8T88lUD GfAftzGkH8qjRjTO59U/jlSVIogUXrfUKDxs0GiUc+TBkk4XezcTd/SY2qTiumvxZ8ak p/Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290572; x=1721895372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=scaJXtQ683x4rg7PUZYMvNACcRxGHUThDZRqfOQfi3M=; b=t9Y0FiEWuDZtwZVnhyFHPsjUwrqI4Dcf/+7Z+j1p93qNRMI34gOZuWSmMhnwaFsqsy SgvR4say4n+uGxpYQu7afSGF/UnzWJv+iJJuwwd4FXkWkVynRAMyNrhRHWyb2N9AJrrC uBDaOg0ojlO128O0FiKffWt0S4waKVYtQ0pO5xUPeOWpIk6P9Xxcv90S1eXVLnRr2fjd N7lRYcg+VuNpZaCsq3IMGfFA9cAuY2bus6Lu5five504MQu62sdzqOuwLpiOWMdVJLpX atNO5vjtlASyzkZqLalcntkVGHSUv2tY+MFoUmye/++WEF820Kpa7lK3cIcQbSeUuwjA 0M9Q== X-Forwarded-Encrypted: i=1; AJvYcCUtsJTJd86kD1Yg0wpdmWogGLSP4O8EFMTc+5dPxDCVjx2Rkf9bUVf2WdHmDocc2tv8nJ6MyWdlGoboaXLwzVp6NtFW X-Gm-Message-State: AOJu0Yw0f+19h3Ek8VLNTB1PerHwurbgMBVMVErg/CeeYnFjibYwNwfk oGm1zT6MXrvdIhX9WFjDFT0++wyQMHUcAcf9aBOqZwXeGcB7LOal9V9pJUTD X-Google-Smtp-Source: AGHT+IEbm35FauD+N09JiCRnEv+vPlzk5g9Rm5x4yX7bGV/q5tyiAAF65LPWArXkMhbtznXbPeiOnQ== X-Received: by 2002:a05:600c:4e4f:b0:426:6773:17 with SMTP id 5b1f17b1804b1-427c2cf27d5mr32939525e9.30.1721290572235; Thu, 18 Jul 2024 01:16:12 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:11 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 4/6] ci: run style check on GitHub and GitLab Date: Thu, 18 Jul 2024 10:16:03 +0200 Message-ID: <20240718081605.452366-5-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We don't run style checks on our CI, even though we have a '.clang-format' setup in the repository. Let's add one, the job will validate only against the new commits added and will only run on merge requests. Since we're introducing it for the first time, let's allow this job to fail, so we can validate if this is useful and eventually enforce it. For GitHub, we allow the job to pass by adding 'continue-on-error: true' to the workflow. This means the job would show as passed, even if the style check failed. To know the status of the job, users have to manually check the logs. For GitLab, we allow the job to pass by adding 'allow_failure: true', to the job. Unlike GitHub, here the job will show as failed with a yellow warning symbol, but the pipeline would still show as passed. Also for GitLab, we use the 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA' variable by default to obtain the base SHA of the merged pipeline (which is only available for merged pipelines [1]). Otherwise we use the 'CI_MERGE_REQUEST_DIFF_BASE_SHA' variable. [1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines Helped-by: Junio C Hamano Signed-off-by: Karthik Nayak --- .github/workflows/check-style.yml | 34 +++++++++++++++++++++++++++++++ .gitlab-ci.yml | 24 ++++++++++++++++++++++ ci/install-dependencies.sh | 4 ++++ ci/run-style-check.sh | 8 ++++++++ 4 files changed, 70 insertions(+) create mode 100644 .github/workflows/check-style.yml create mode 100755 ci/run-style-check.sh diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml new file mode 100644 index 0000000000..c052a5df23 --- /dev/null +++ b/.github/workflows/check-style.yml @@ -0,0 +1,34 @@ +name: check-style + +# Get the repository with all commits to ensure that we can analyze +# all of the commits contributed via the Pull Request. + +on: + pull_request: + types: [opened, synchronize] + +# Avoid unnecessary builds. Unlike the main CI jobs, these are not +# ci-configurable (but could be). +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-style: + env: + CC: clang + jobname: ClangFormat + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - run: ci/install-dependencies.sh + + - name: git clang-format + continue-on-error: true + id: check_out + run: | + ./ci/run-style-check.sh \ + "${{github.event.pull_request.base.sha}}" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 37b991e080..817266226e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -123,6 +123,30 @@ check-whitespace: rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' +check-style: + image: ubuntu:latest + allow_failure: true + variables: + CC: clang + jobname: ClangFormat + before_script: + - ./ci/install-dependencies.sh + # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged + # pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should + # be defined in all pipelines. + script: + - | + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}} + + if test -z "$R" + then + echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!" + exit 1 + fi + ./ci/run-style-check.sh "$R" + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + documentation: image: ubuntu:latest variables: diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh index 6ec0f85972..fb34ced8f0 100755 --- a/ci/install-dependencies.sh +++ b/ci/install-dependencies.sh @@ -87,6 +87,10 @@ macos-*) esac case "$jobname" in +ClangFormat) + sudo apt-get -q update + sudo apt-get -q -y install clang-format + ;; StaticAnalysis) sudo apt-get -q update sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \ diff --git a/ci/run-style-check.sh b/ci/run-style-check.sh new file mode 100755 index 0000000000..76dd37d22b --- /dev/null +++ b/ci/run-style-check.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# Perform style check +# + +baseCommit=$1 + +git clang-format --style file --diff --extensions c,h "$baseCommit" From patchwork Thu Jul 18 08:16:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736169 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E20C7CF30 for ; Thu, 18 Jul 2024 08:16:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290576; cv=none; b=EK5Ln6jcr2yN9Q8mhE83zXihLl6Av47vy99eXBkr5FWH6CDFMn9lTmJ6rUFNOwZ+T8dZo1NRoB7i+uIF0ackk9b2cbulWnGLhJVit0LUaqWJLnPI7flhl0J1iwZL4ohy8BU12Jmqm1LL9z4s6dNtg7APZ5Mjj51O98JKn0dZOzc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290576; c=relaxed/simple; bh=Y31aADat4fA3Usr4h81u60I1xgTliDuxKQfJoOyOVoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=shQRZQGzRWkr1N5yOqv2xl0gv8Vapz/MRlo5adi/p3zo/JUPj94PkSF0VgMqC+E/p/nh3+R1I44On8RqPv42fdBUDiD7zNnuC02CgdyAsE3U5gPyeXkg3OZRMvLrW8/iCn0FefLueqlaadT7FEV7dgE3qVka95Weeh+gOYclA+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=I5mw6+OZ; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I5mw6+OZ" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4266ed6c691so215465e9.3 for ; Thu, 18 Jul 2024 01:16:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290574; x=1721895374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GV4c1RtqvwQl2FhVDHHsZzR1lqJqJuoxbPpvwuiA6DI=; b=I5mw6+OZ24JR4+FP1f4xZi4dwcFH8pjrSGdIWLtB7rjCiCcq/gjX+lRyk9Y4CPFj5X 0S5be4de3tny4nFofzwFMXn+4OnneS+eUJ2zPPQbNAkB3vb6oKGRBl7DH6xEu2fWpX9l CiJEmDfXIYB69vL8iYrHOhQn0UxzEyZmp9NfHvBV9iGSklU3wi6Xs+HyboB5Z+ZdE8/S KlwI6ovMCJVrp9L3HPLhI5cxsCj0zpfE2xcEdxT5fofwxxCD+haPzj0olytIQAz1Pyi3 6Y7wpYip5hbLkHLeOX0KR9v/hBgSyapQbipQZLm9pkBsZWtZFzkrElQ/zjAMTM1FSlCA Hzcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290574; x=1721895374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GV4c1RtqvwQl2FhVDHHsZzR1lqJqJuoxbPpvwuiA6DI=; b=cK1N9tDGZLZHXgGz8SJBqq4R+x/ctPADmkK1YydMYmDFCK8zgdgU0sqPakCfDRIcsx nyEJ3JBLtV+A++OT994VagM7s6HxKBxlbufAdNkiSp6+lfkf8WpXLww2k0gNAk201G/S qTDvKU2ngmQSBWamD0tzFLSNDjf3ueAo8neyNWBSTUCoy8GBrTwqsahB9OWpXK4Z1ayN LlWXrmsrivzQgy/y3oO1J2c+8TeuBK7deHwMgFldhWWeNPy2MvCkFPraoUyg+/gMV1s1 iE1Dz8ie/WoIeNPU65efw2N0ZwEM8TphDIrWMp72NLHI3PIVmlIYJVvV5wferJD+uJoY 4hKw== X-Forwarded-Encrypted: i=1; AJvYcCW0W7XnnWswjUX93aybrPFheG9wRZM1qEPvsfZBt+wlHOG+KUzc3MWGPayTDDHM23HveYXsBF/rFKYziNoGo+mFA2nn X-Gm-Message-State: AOJu0YzCgt9ycXWH2N5WfNL5y2jysSGI4Kqg6K+7Nolt1h3qvkPQqPSg yRflbJkfpoaNvv/ZPuAeqqGAtANbnhyazc4gB1OoB9XV+WDlGp0W X-Google-Smtp-Source: AGHT+IEMmfosQL42qpFIDBUyurFRhMlsZKk77piB54ybVzfONsoNt8K36RqLBDC0oIP1yY+oTa8MAw== X-Received: by 2002:a05:600c:c12:b0:426:6ea0:d5b8 with SMTP id 5b1f17b1804b1-427c2cefebemr29487175e9.29.1721290573463; Thu, 18 Jul 2024 01:16:13 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:12 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 5/6] check-whitespace: detect if no base_commit is provided Date: Thu, 18 Jul 2024 10:16:04 +0200 Message-ID: <20240718081605.452366-6-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The 'check-whitespace' CI script exits gracefully if no base commit is provided or if an invalid revision is provided. This is not good because if a particular CI provides an incorrect base_commit, it would fail successfully. This is exactly the case with the GitLab CI. The CI is using the "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" variable to get the base commit SHA, but variable is only defined for _merged_ pipelines. So it is empty for regular pipelines [1]. This should've failed the check-whitespace job. Let's fallback to 'CI_MERGE_REQUEST_DIFF_BASE_SHA' if "CI_MERGE_REQUEST_TARGET_BRANCH_SHA" isn't available in GitLab CI, similar to the previous commit. Let's also add a check for incorrect base_commit in the 'check-whitespace.sh' script. While here, fix a small typo too. [1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines Helped-by: Junio C Hamano Signed-off-by: Karthik Nayak --- .gitlab-ci.yml | 13 ++++++++++++- ci/check-whitespace.sh | 10 ++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 817266226e..320b78b9ae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -118,8 +118,19 @@ check-whitespace: image: ubuntu:latest before_script: - ./ci/install-dependencies.sh + # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged + # pipelines, we fallback to $CI_MERGE_REQUEST_DIFF_BASE_SHA, which should + # be defined in all pipelines. script: - - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" + - | + R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}} + + if test -z "$R" + then + echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!" + exit 1 + fi + ./ci/check-whitespace.sh "$R" rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh index db399097a5..c40804394c 100755 --- a/ci/check-whitespace.sh +++ b/ci/check-whitespace.sh @@ -9,7 +9,7 @@ baseCommit=$1 outputFile=$2 url=$3 -if test "$#" -ne 1 && test "$#" -ne 3 +if test "$#" -ne 1 && test "$#" -ne 3 || test -z "$1" then echo "USAGE: $0 [ ]" exit 1 @@ -21,6 +21,12 @@ commitText= commitTextmd= goodParent= +if ! git rev-parse --quiet --verify "${baseCommit}" +then + echo "Invalid '${baseCommit}'" + exit 1 +fi + while read dash sha etc do case "${dash}" in @@ -67,7 +73,7 @@ then goodParent=${baseCommit: 0:7} fi - echo "A whitespace issue was found in onen of more of the commits." + echo "A whitespace issue was found in one or more of the commits." echo "Run the following command to resolve whitespace issues:" echo "git rebase --whitespace=fix ${goodParent}" From patchwork Thu Jul 18 08:16:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: karthik nayak X-Patchwork-Id: 13736170 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FE217D09D for ; Thu, 18 Jul 2024 08:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290578; cv=none; b=SWnluDOkAeaVWNv378+foxBFYIRGTf9AHw+hhBk4Qe0+e6zfHlncxthJCByeWHK3BsA32u/KkAJSCmAozBhGC4v0b+BFd8AHkw9crV5vv3I5/wVOcx37mpqzWvtFehFRQt5Kx0bnpgAXrj+UEb9/xteW2XmnEb4RgbLJgYjXlOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721290578; c=relaxed/simple; bh=GihmzoGpXQcJWWVBnIdVZUVKWLXaKUcn40FtEz0KU9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ULR/t3kaybanZILDHQTiYP35i8y29nYZXS8tDNJ2BFptOsTQBVy3SwHjDa8QWV1nGyNur/KzJIq13hzKIiQjfjE1kowEbf6ksYUVUa27jNoTYoRp/5W37uhaiA7ErpSnEuUIz7LvwfhPndBEvoJPyJ8fr3iiGy9Xe6hexOfPUO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WVqm8dVY; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WVqm8dVY" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4266edee10cso223855e9.2 for ; Thu, 18 Jul 2024 01:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721290575; x=1721895375; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QdJVQPxnX2ejLWnSEXYE14wHZC6ZGRrq/+9puE7yOEs=; b=WVqm8dVY0lpz9KzBJN4/Wt4qmSdiR1uZ4UACtrCKnjHd8nX3lC65c6REdpsOPfYM6m 9dv8V8mdAyW2QPQSzcr1TIV4aBU2qLAY8Tr7lWVA8Zo+kOtKGP9octBsztXKkVu6kk4k 5WIpxovtdQQ6ycydP3u2RqZ82lordEFlKT5sR7kyiSwP8MzeEI53XXJs+a6Gaua2wsFG eUXnXj3BYzYQFoI3lIEDRheLe4SWE4XlSq01XK50TxObCpI2TXTQFCEKTX/fE6hPEN8z v7ZrsRPyMYpmoEXbmmmAQpWqgr6TERpLjrCOVPXTalcCXtYsjT957o4Ga9pJgjss3RrC 3ovg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721290575; x=1721895375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QdJVQPxnX2ejLWnSEXYE14wHZC6ZGRrq/+9puE7yOEs=; b=l3BWZk/UD1X4LFMGIJE5g6jCQFMnbA3GXJOesSQsVBJi5QmAF8yIidseMRZ0tfyTEa XOnvGqQaoCkpH8SnSxQQWGpgAbogfLaoIax6hF2vuUkNZzWfPTK+py0Qgh9x1zBY9R7m yL7EtHA9xn4i4Toz8rcZe7l/gsnVPjeb7cAxsHJvsvTvMH5mPpFALQbX9gHZuxzhmpwB KoRwcwWcvyi5CSYg0fSxMIT1ZgoVc2D6jeSd1oc7UjqZhKJyQs52C/lt0m863UZhrRTR T1V/CNsE5ZYiBJGgWydRlbrvSzPafLCYyFzHRGmBk7ERYFfihz757aYPInVuswaMaiAK HciA== X-Forwarded-Encrypted: i=1; AJvYcCUJDlKXTXrenij2WbtXW/u5IxLmOlwnPg4WTB10ObtpJilgxHSX9L9Uhg/priHhTlJ2LdNyI1toZxHxx1K3lPKfHFjg X-Gm-Message-State: AOJu0YzfqB2hbrLdxbU2h4H2/XkBQVGtZY8x4dM/J/nZ++Zcxipqqnw+ d/0GitbXnd3fqwkSwyHKHtwFXrq1o8ULu/CckL0VnWEhMROGtCxO X-Google-Smtp-Source: AGHT+IFZBuayHQyEhbWldUA5UH7AEsqhPZlehG68DBICXAsjC4PvzloFvbJ2HM16+zxovkqCU7+wHA== X-Received: by 2002:a05:600c:1c28:b0:426:6220:cb57 with SMTP id 5b1f17b1804b1-427c2cefe49mr29566205e9.25.1721290574672; Thu, 18 Jul 2024 01:16:14 -0700 (PDT) Received: from laptop.fritz.box ([2a02:2455:826e:4900:e75c:3a24:6dbb:5d7e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427d2a43598sm1714375e9.1.2024.07.18.01.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jul 2024 01:16:14 -0700 (PDT) From: Karthik Nayak To: karthik.188@gmail.com Cc: chriscool@tuxfamily.org, git@vger.kernel.org, gitster@pobox.com, jltobler@gmail.com, phillip.wood123@gmail.com Subject: [PATCH v5 6/6] ci/style-check: add `RemoveBracesLLVM` in CI job Date: Thu, 18 Jul 2024 10:16:05 +0200 Message-ID: <20240718081605.452366-7-karthik.188@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718081605.452366-1-karthik.188@gmail.com> References: <20240715093047.49321-1-karthik.188@gmail.com> <20240718081605.452366-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For 'clang-format', setting 'RemoveBracesLLVM' to 'true', adds a check to ensure we avoid curly braces for single-statement bodies in conditional blocks. However, the option does come with two warnings [1]: This option will be renamed and expanded to support other styles. and Setting this option to true could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option. The latter seems to be of concern. While we want to experiment with the rule, adding it to the in-tree '.clang-format' could affect end-users. Let's only add it to the CI jobs for now. With time, we can evaluate its efficacy and decide if we want to add it to '.clang-format' or retract it entirely. We do so, by adding the existing rules in '.clang-format' and this rule to a temp file outside the working tree, which is then used by 'git clang-format'. This ensures we don't murk with files in-tree. [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm Signed-off-by: Karthik Nayak --- ci/run-style-check.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ci/run-style-check.sh b/ci/run-style-check.sh index 76dd37d22b..6cd4b1d934 100755 --- a/ci/run-style-check.sh +++ b/ci/run-style-check.sh @@ -5,4 +5,21 @@ baseCommit=$1 -git clang-format --style file --diff --extensions c,h "$baseCommit" +# Remove optional braces of control statements (if, else, for, and while) +# according to the LLVM coding style. This avoids braces on simple +# single-statement bodies of statements but keeps braces if one side of +# if/else if/.../else cascade has multi-statement body. +# +# As this rule comes with a warning [1], we want to experiment with it +# before adding it in-tree. since the CI job for the style check is allowed +# to fail, appending the rule here allows us to validate its efficacy. +# While also ensuring that end-users are not affected directly. +# +# [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm +{ + cat .clang-format + echo "RemoveBracesLLVM: true" +} >/tmp/clang-format-rules + +git clang-format --style=file:/tmp/clang-format-rules \ + --diff --extensions c,h "$baseCommit"