Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9749925ybi; Wed, 10 Jul 2019 16:20:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJjox2CPDzadO3SYsmcVmTB4czDJPYd8Pugw5Dff8wzPdlYrzYjrvGenw63o9uKrgvs81J X-Received: by 2002:a17:90a:fa07:: with SMTP id cm7mr1008481pjb.115.1562800807976; Wed, 10 Jul 2019 16:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562800807; cv=none; d=google.com; s=arc-20160816; b=DGPwl4px6hqF33WWCUDIMksmC7+5+L1fvRMMSccNEami9sfsHI3dUvJ/nVEi2OgzmV LMXsJlYiB+BIii4uNa6YZzZYBJ43hbEKnT5UzyTl6Exn3R6lwdRq/DpCdgELxwXtXgIP VK+HxGU8qHAsTn1sPa9l0jUQd0TE74T0VTOEbf8eKKTmwhmWd44fJ4b01B8W6WUCd3KH B9XBkGqC692HJpO0pCe2BlR8vMz3sPbIXP0Ur9l9F2+x0Ssx2MHVJBaXumMueJ8rM9Fo a7fagIb0hZEWr4HccphL2R6QYxCHN2TsWjVGnf8ADo8Ci7itLxLq9Yx5pf2JMpJ8PMWo EudQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Pfkm16ESPrwdyy5eXbeiSaul1UHucvhtw70mTCVOEgk=; b=RWZHnPqD0kx5bsDe+jqbCi4zBeksa1nkE8olTKf/ShxmbpQyuJMhsCxn+D6IosxYMq LoUz9/4W3QWJZ53SVo4hsv5UMcyQ/05LnxnftVygH5Kp2XCjRLMJwqLSF/ubZDvi+CuQ Lab1097+MQX7l6lOYBpQi+uSzKox1KH3tvmgdUNjp/cynggjAJeSuxalfJwxjeGlQ+xv MHKfla1z01T0w06c30D6gH9lbFCZq69dcU6TqCP4D+5A1sYU2qLUyyn/ta99ALLlHzA8 t+3mEg7LNU1QSgDnh/Pr//AcNYkZTpzJkamZMtB2pCMxsFCED3DRcQgY9mfwVdUvy/QA jXeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s19si3463911pgm.291.2019.07.10.16.19.52; Wed, 10 Jul 2019 16:20:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727619AbfGJXT1 (ORCPT + 99 others); Wed, 10 Jul 2019 19:19:27 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43344 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726708AbfGJXT1 (ORCPT ); Wed, 10 Jul 2019 19:19:27 -0400 Received: by mail-wr1-f67.google.com with SMTP id p13so4150422wru.10 for ; Wed, 10 Jul 2019 16:19:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pfkm16ESPrwdyy5eXbeiSaul1UHucvhtw70mTCVOEgk=; b=kVImacjCrtS1G9sF5N/BeWyb7M30NxM4UaMg4cWMQWXr+jnbbLPt5b1ehm8Bwf6K/W 3YSG8tVOUUKglr6ALJOOKS+vyOO4XlC1ZmfRimXCB4cRCcgwjNMUAJJEZwFnGEBu47rS qwXEsVoEV7pjWlRqj3Fe0LdsgmiThZ+W38Oi80dZg9Nb4b3DKuGiO9nL0VTC8/+1jUiQ qVJLDDWwSi0Vou7giHH2XlOvdL8OYPRGwt/FG3YWrCXzD1fOqjAmDGULw+ngDAIJWsaN JIVGWEGLmjorN4zpRPnMHRnl25r/Y0rNBk9F/0ly///Q1y0ugTPKagtPHBxgw2+wK/ap xKQQ== X-Gm-Message-State: APjAAAVPQi0+9CHAUsKBwM7ndr12Bgy9ipZJ9uGGzoHT4vo/gL/W1nPD 0+md2xe+NeBG3Tx7d53VkRDNLZepJvs= X-Received: by 2002:adf:e6c5:: with SMTP id y5mr146662wrm.235.1562800765131; Wed, 10 Jul 2019 16:19:25 -0700 (PDT) Received: from raver.teknoraver.net (net-47-53-105-184.cust.vodafonedsl.it. [47.53.105.184]) by smtp.gmail.com with ESMTPSA id c9sm2586667wml.41.2019.07.10.16.19.24 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 16:19:24 -0700 (PDT) From: Matteo Croce To: LKML Cc: Andy Whitcroft , Joe Perches Subject: [PATCH] checkpatch.pl: warn on invalid commit hash Date: Thu, 11 Jul 2019 01:19:19 +0200 Message-Id: <20190710231919.9631-1-mcroce@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It can happen that a commit message refers to an invalid hash, because the referenced hash changed following a rebase, or simply by mistake. Add a check in checkpatch.pl which checks that an hash referenced by a Fixes tag or just cited in the commit message is a valid commit hash. $ scripts/checkpatch.pl <<'EOF' Subject: [PATCH] test commit Sample test commit to test checkpatch.pl Commit 1da177e4c3f4 ("Linux-2.6.12-rc2") really exists, commit 0bba044c4ce7 ("tree") is valid but not a commit, while commit b4cc0b1c0cca ("unknown") is invalid. Fixes: f0cacc14cade ("unknown") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") EOF WARNING: Invalid hash 0bba044c4ce7 WARNING: Invalid hash b4cc0b1c0cca WARNING: Invalid hash f0cacc14cade total: 0 errors, 3 warnings, 4 lines checked Signed-off-by: Matteo Croce --- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index a6d436809bf5..6fe15fbe876f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2898,6 +2898,13 @@ sub process { } } +# check for invalid hashes + if ($in_commit_log && $line =~ /(^fixes:|commit)\s+([0-9a-f]{6,40})\b/i) { + if (`git cat-file -t $2 2>/dev/null` ne "commit\n") { + WARN('INVALID_COMMIT_HASH', "Invalid commit hash $2"); + } + } + # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =~ /^-/); -- 2.21.0