From patchwork Sun Oct 22 02:27:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael McClimon X-Patchwork-Id: 13431619 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA12380A for ; Sun, 22 Oct 2023 02:28:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mcclimon.org header.i=@mcclimon.org header.b="KI1gv46d" Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 942CCC2 for ; Sat, 21 Oct 2023 19:28:14 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id 6a1803df08f44-66cfef11a25so12028946d6.3 for ; Sat, 21 Oct 2023 19:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mcclimon.org; s=gw; t=1697941693; x=1698546493; 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=4oZKot/+W1qWeS7lTaIzLgEwIQH/09EIdvW2mEE2xL4=; b=KI1gv46d/c8RwUKWJO4YZVKFI55ulF5pixI4vqUWmO26c9wOiRWV2K9ZAseljAlsmw Qpzr7wXAvyG2u5/SyOl2J1TFedXzGzWBxVJJxMFm7t/bsgXoCtq2mlxCl/BJUTAEWYRY lP+V9I+VtlYFjr1fSXS9BehZHUGdR88SyRqV4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697941693; x=1698546493; 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=4oZKot/+W1qWeS7lTaIzLgEwIQH/09EIdvW2mEE2xL4=; b=HdDVj+vcFaS4kFQ0NshBWwSa1rXnz4RbG2Wp6iUDhOd1e+kJTw/opCXJF9Xx3uubaU uGf0h2Tg93hyrXH+6TTZrso58YQdsH84l2VDPHliau9E0IC5GxLWwDO5kngXl4qRfkmS qhjZa1rYC0Zxmot1JsVxiLtfzaDrdD3Q3SS7IXP1Rcf1CDYAsgMJGSvPjEXvl5mT7M1Z f0VWuGVjOSNFEeVRR7GBkCXW6bME6Gnv+ewLigpo4UsllU9thaYm4+op2DgmBwHrMBzo 8WIaYUnHeNf8IXSxtm7qKZRMaRev+UawnMWOTyq3BvAhC+Y2Fwv5rYkKtlHK8wpHCjGV rD7g== X-Gm-Message-State: AOJu0Yz5qTmUelnUbC9aQfiYK/9zTCLq62DzdSdEWUmJZQU7y/vgpZhC ETXbNtP+LVkJGzJtWNgXeQfrVy88KoQEVrnctzL5FyTu X-Google-Smtp-Source: AGHT+IHh4cWPDgCnQfQsY5caEO5BHAiHbvS9EMGAjIOE0fODvJEjyg4eYNCXf/n8lFirmmanssTp1A== X-Received: by 2002:a05:6214:2465:b0:66d:5ee5:815b with SMTP id im5-20020a056214246500b0066d5ee5815bmr5462044qvb.64.1697941693706; Sat, 21 Oct 2023 19:28:13 -0700 (PDT) Received: from localhost ([2600:4040:7ee9:4100:1908:ac84:cbae:dea2]) by smtp.gmail.com with ESMTPSA id d12-20020a056214184c00b0065d03eae7a0sm1866659qvy.82.2023.10.21.19.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 19:28:13 -0700 (PDT) From: Michael McClimon To: git@vger.kernel.org Cc: Michael McClimon Subject: [RFC PATCH 1/2] patch-ids: add const modifier to commit Date: Sat, 21 Oct 2023 22:27:59 -0400 Message-ID: <20231022022800.69219-2-michael@mcclimon.org> X-Mailer: git-send-email 2.42.0.424.gceadf0f3 In-Reply-To: <20231022022800.69219-1-michael@mcclimon.org> References: <20231022022800.69219-1-michael@mcclimon.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These aren't modified by these functions, and I want to use them somewhere where the commit is in fact a const. Signed-off-by: Michael McClimon --- patch-ids.c | 4 ++-- patch-ids.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/patch-ids.c b/patch-ids.c index c3e1a0dd..ecfd7ba0 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -6,13 +6,13 @@ #include "hex.h" #include "patch-ids.h" -static int patch_id_defined(struct commit *commit) +static int patch_id_defined(const struct commit *commit) { /* must be 0 or 1 parents */ return !commit->parents || !commit->parents->next; } -int commit_patch_id(struct commit *commit, struct diff_options *options, +int commit_patch_id(const struct commit *commit, struct diff_options *options, struct object_id *oid, int diff_header_only) { if (!patch_id_defined(commit)) diff --git a/patch-ids.h b/patch-ids.h index 490d7393..3f61d88a 100644 --- a/patch-ids.h +++ b/patch-ids.h @@ -19,7 +19,7 @@ struct patch_ids { struct diff_options diffopts; }; -int commit_patch_id(struct commit *commit, struct diff_options *options, +int commit_patch_id(const struct commit *commit, struct diff_options *options, struct object_id *oid, int); int init_patch_ids(struct repository *, struct patch_ids *); int free_patch_ids(struct patch_ids *); From patchwork Sun Oct 22 02:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael McClimon X-Patchwork-Id: 13431620 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92717A4D for ; Sun, 22 Oct 2023 02:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mcclimon.org header.i=@mcclimon.org header.b="Nd8L3qTT" Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54575DA for ; Sat, 21 Oct 2023 19:28:16 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id 6a1803df08f44-66d4453ba38so14010106d6.0 for ; Sat, 21 Oct 2023 19:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mcclimon.org; s=gw; t=1697941695; x=1698546495; 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=NZxzU+Y2RGRpa17om0vDhiHo3cLzipx0my2boZJmrIE=; b=Nd8L3qTTPE5rkxx51i/TikaT6g8+QJpXtS9Xl6j2StmeFQb73rBg8WuzMnkppt+Mwp I6JOy+AfL8NkoBmCVmZcaKdcAseImwl/wEwRNj44iBCmMnWpdnekOdOVAjCDmBoisszd n77EK4o1uZROwNzJQLzWGM6MnkqUnYqYdbLgo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697941695; x=1698546495; 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=NZxzU+Y2RGRpa17om0vDhiHo3cLzipx0my2boZJmrIE=; b=JtWBwBFsSBiZuNtrMDhdVp6R+9HYNE4FHX1wEcZ+ViyqOBRsezem8/twY9sn4ASUTr rvnHuJfGPTVv60DiRXDEjtbh98GdnzIIneuUolvuV2CAlMPROEPa/M5n5JVykm1rDO3K IsZ50h57zNttarDjxwS4w66PvE1kGRK/B537snrUqb1TZzflTkzaaO3umtJR+M/n0ElB 4xybm87rV/T2zcOPwbCrkEkzs+g/us9xGKlFxPNQRDhxRSzQ0E7UFStZpZXc91G+M2mq cempM1R3qk2N8Xb/CRnpiQjngt1Ns/G2UDfHT1tsawSr7hAJsZtITXkQ7fDU8/wmyPBa lZfQ== X-Gm-Message-State: AOJu0YzaK9knNDBeWZUFWzOqMqCF7UHvDCSjN+M8is/G+26pc8IWimKv x84wnhFlPWWeo3rPcR1e2dJgc+vWIWGS4gT49DDU3p4h X-Google-Smtp-Source: AGHT+IHlAFYKQUHMh1rEqftzS1mW2PWKP9ZkB0LLwXrKvaBq8j5So/H3ciAjmfGCmd/c1UKA83ydfQ== X-Received: by 2002:a05:6214:c83:b0:66d:50a6:da73 with SMTP id r3-20020a0562140c8300b0066d50a6da73mr7681771qvr.22.1697941695488; Sat, 21 Oct 2023 19:28:15 -0700 (PDT) Received: from localhost ([2600:4040:7ee9:4100:1908:ac84:cbae:dea2]) by smtp.gmail.com with ESMTPSA id po15-20020a05620a384f00b007776c520488sm1740332qkn.9.2023.10.21.19.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Oct 2023 19:28:15 -0700 (PDT) From: Michael McClimon To: git@vger.kernel.org Cc: Michael McClimon Subject: [RFC PATCH 2/2] pretty: add 'I' placeholder for patch-id Date: Sat, 21 Oct 2023 22:28:00 -0400 Message-ID: <20231022022800.69219-3-michael@mcclimon.org> X-Mailer: git-send-email 2.42.0.424.gceadf0f3 In-Reply-To: <20231022022800.69219-1-michael@mcclimon.org> References: <20231022022800.69219-1-michael@mcclimon.org> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This doesn't actually work yet, and the test is probably in the wrong place, but I think it's sort of close enough to send an RFC patch to ask some questions. Signed-off-by: Michael McClimon --- pretty.c | 11 +++++++++++ t/t4205-log-pretty-formats.sh | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/pretty.c b/pretty.c index cf964b06..47e2e6e9 100644 --- a/pretty.c +++ b/pretty.c @@ -19,6 +19,7 @@ #include "trailer.h" #include "run-command.h" #include "object-name.h" +#include "patch-ids.h" /* * The limit for formatting directives, which enable the caller to append @@ -1571,6 +1572,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ c->pretty_ctx->abbrev); } return 1; + case 'I': + { + struct diff_options diffopt; + struct object_id patch_id; + repo_diff_setup(the_repository, &diffopt); + if (commit_patch_id(commit, &diffopt, &patch_id, 0)) + die(_("cannot get patch id")); + strbuf_addstr(sb, oid_to_hex(&patch_id)); + return 1; + } case 'm': /* left/right/bottom */ strbuf_addstr(sb, get_revision_mark(NULL, commit)); return 1; diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index e3d655e6..1e9fdcfe 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -38,6 +38,13 @@ test_expect_success 'set up basic repos' ' git config --unset i18n.commitEncoding ' +# %I placeholder +test_expect_success '%I placeholder is a patch-id' ' + git diff-tree --patch-with-raw HEAD | git patch-id >expected && + git show -s --pretty="%I %H" >actual && + test_cmp expected actual +' + test_expect_success 'alias builtin format' ' git log --pretty=oneline >expected && git config pretty.test-alias oneline &&