From patchwork Thu Dec 1 22:49:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13061887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B038FC3A5A7 for ; Thu, 1 Dec 2022 22:50:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231721AbiLAWuc (ORCPT ); Thu, 1 Dec 2022 17:50:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231724AbiLAWuH (ORCPT ); Thu, 1 Dec 2022 17:50:07 -0500 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 544D3A80BA for ; Thu, 1 Dec 2022 14:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1669934951; bh=XcVr80Rsrak1rZf/eMZq5cWtksFz2VBJcB9yYzLIqvs=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=Eozb21aluwZi8p6g5oiLoKB9kJFSLjC7NX46xr7JnoouSXtLh3Rpf9ZXmiHViTZgq ied55VhCBp0srcL9En4ZOeXBVCJqDYuXqfiahDA7buXdYfAjCchRdZQtwJWB/JBTUd QtWvCEPiJmAn6vR+HHXE/+SsbqGXtueWYq5KEugF3Vfka8BZguQcrXKguD/gtqUCnZ ZUvum+vYP92aKJSOqRZXgX/BQyvoJvDr2qSxu5uJ2A6NCp6AWlEnEDcGTSRaBd2oWi OnN/lFPJb0n27yCdQqVvMNeN1xmsvkPy5NMuxMZBmzdNoyvGdYqS92f//8b/XijaX2 5mLsJiB7+98hA== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.34] ([91.47.154.159]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MpCmT-1oe9nM0gjn-00qZVC; Thu, 01 Dec 2022 23:49:11 +0100 Message-ID: <31f0e4ed-4a31-2423-65f0-2f9f1f6c7df3@web.de> Date: Thu, 1 Dec 2022 23:49:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: [PATCH v3 1/3] diff: factor out add_diff_options() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jeff King , ZheNing Hu References: <0620b4a6-b80a-d8a0-5a35-857b9fe0c986@web.de> <19325420-5630-87bb-0c2c-362151214b36@web.de> In-Reply-To: <19325420-5630-87bb-0c2c-362151214b36@web.de> X-Provags-ID: V03:K1:cEujPDKxwYP4nW/W3SXe1aY1iUuBJHtzCyqMqY0muStW7jLBx4F /2Y//dtWJcfafL1RZ2x6CyqR6hCYDc/sU6F3YBBD0w4LrnpshM8+SksPbXdFjZpVf140k/+ et23g1v3KyPdjnt6j82dIqc2e+KFP3lMd6s+pb5zsTVio7ovIPeC635n6SOWji3h3CgjnS2 7/gRZ6NJXw+FCNrTzNrWQ== UI-OutboundReport: notjunk:1;M01:P0:v1O9FIb9Ds4=;EWzFu/lmIj3XMmisIGJG5Vsalcv qhkqkxuGBT596LCceW2S2aoE6yGx1Q5msMh2x8fqGrTpRBIZC/MgF2sJ4AhbswQbKRXAJBuYN +7qcXufFMxkPYMTr0L5e+RoubDPoZ3/UKQtBCQtom+TP//mq22cxas36nkEDU1sGJmVLDObDQ 7TvA9H35kWzKw6OEm5tmuc3xTTpaUomcJAkeA7imaSgefBt3thc+YNOhW7BILcvR5hqmLhFjV 5CPe4bybU3v6hqg6nOk1cG6m29EVupVyxmEwb46VV9r7dJDWVkF+39LZ76XiDlTUYY2vPPhJF d2GiTmne527b92bXcxBkETlaaH4OOQJlVqLnK8097FiCl81mAnPQG2sd1fruY8IzWyb8/zlal NuolDdS9wPKU257740SGSkOg/EVxhtbS7Elpa8tkn8FXDyEQz6e6xVCs5hh2tSJzGO4cRpNqp dBUXG3JjPVXsdt93X6BsWl1I7pmT6yUayKJ9fUCagOY91FpfuyJ8zK9MWMCC2z6c95N1keqTv 3TYveGbob3MYKoN2/t21980kBUREdyUtpM8V+IXJ4u8Q3iva/vW2bZcYUB58B6dOK6bEKZxbh mVAahEkBqw42QLrwhmVuN+tQsljUSYG32pWU+AqJOmjpyF/ik3BACKXQiaBG1A45KzOti2riQ ZpZDa6cEC+VqhWSxjQSn/k3fkdyZ251CxfT9nTmO0UDwzlrMnPjk6vcRe7RMAr1PDJXwIqCDX Bgk6w5YXX4+TGV64qkYoM8RyICS90vRt+dIUe/XwSs0RnJ3GfA8iUDPxFWEtlxIjTOkzoHNfb Ln2q+Q6oDOlNUholf7W/DEqzXY2+XMNh7OcjKs4obudYXG0000gW5JOOdqv0omoG8iAOO8l8i 1N4NFd2OhPF704MptEKjYQ1uuHbz8J2PKZsX7yXvoEhFQrqICkUEfMjqj0oyf1ALUDDSkx1uS tTZDXQ== Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a function for appending the parseopts member of struct diff_options to a struct option array. Use it in two sites instead of accessing the parseopts member directly. Decoupling callers from diff internals like that allows us to change the latter. Signed-off-by: René Scharfe --- builtin/range-diff.c | 2 +- diff-no-index.c | 3 +-- diff.c | 6 ++++++ diff.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/builtin/range-diff.c b/builtin/range-diff.c index e2a74efb42..aecfae12d3 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -47,7 +47,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) repo_diff_setup(the_repository, &diffopt); - options = parse_options_concat(range_diff_options, diffopt.parseopts); + options = add_diff_options(range_diff_options, &diffopt); argc = parse_options(argc, argv, prefix, options, builtin_range_diff_usage, PARSE_OPT_KEEP_DASHDASH); diff --git a/diff-no-index.c b/diff-no-index.c index 18edbdf4b5..05fafd0019 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -255,8 +255,7 @@ int diff_no_index(struct rev_info *revs, }; struct option *options; - options = parse_options_concat(no_index_options, - revs->diffopt.parseopts); + options = add_diff_options(no_index_options, &revs->diffopt); argc = parse_options(argc, argv, revs->prefix, options, diff_no_index_usage, 0); if (argc != 2) { diff --git a/diff.c b/diff.c index 1054a4b732..f1cf13e8e7 100644 --- a/diff.c +++ b/diff.c @@ -5419,6 +5419,12 @@ static int diff_opt_rotate_to(const struct option *opt, const char *arg, int uns return 0; } +struct option *add_diff_options(const struct option *opts, + struct diff_options *options) +{ + return parse_options_concat(opts, options->parseopts); +} + static void prep_parse_options(struct diff_options *options) { struct option parseopts[] = { diff --git a/diff.h b/diff.h index fd33caeb25..c20a1ad76d 100644 --- a/diff.h +++ b/diff.h @@ -539,6 +539,7 @@ int git_diff_ui_config(const char *var, const char *value, void *cb); #define diff_setup(diffopts) repo_diff_setup(the_repository, diffopts) #endif void repo_diff_setup(struct repository *, struct diff_options *); +struct option *add_diff_options(const struct option *, struct diff_options *); int diff_opt_parse(struct diff_options *, const char **, int, const char *); void diff_setup_done(struct diff_options *); int git_config_rename(const char *var, const char *value); From patchwork Thu Dec 1 22:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13061888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C72BC4332F for ; Thu, 1 Dec 2022 22:52:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231676AbiLAWwl (ORCPT ); Thu, 1 Dec 2022 17:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbiLAWwB (ORCPT ); Thu, 1 Dec 2022 17:52:01 -0500 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3860BC7253 for ; Thu, 1 Dec 2022 14:51:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1669935081; bh=MUngMwHgZXfs9MLcUwCNVBl9EwIl2t6hsj4NmxAAkSY=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=uocb5iLjh9FcgR2U+b1hUXouqR4sOVHweXX0NtxXriZw4jWn2UjMCtHLVRf/wT/y+ 1008fIwbGAvuXW1V4HKS39D+nJXkrrNYpewl0OyHHJXlFFUPhbNkr0KlNDlQapkR2D nC3TQCW3dO5IhXFOp6fGFmHmzfjVJLhdn914RxkgaPzeUseeI5xYLu9LRxz9HO1TP4 V5JEhO05JsC+IEfsQkI/UQMKvfPeGXbVMrEnUR4k0i1hlysm2jBBBLPlkJay9sZv6p KAYulHrsH5EqUA7OMWtDieD65lZbTnMnoE8Z7Ei8DJBQmUMuK6Oaciqtnmo/OGZSjR ng5fY3aZzK9kg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.34] ([91.47.154.159]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M7ux6-1p5qDT2gUs-0055bj; Thu, 01 Dec 2022 23:51:21 +0100 Message-ID: Date: Thu, 1 Dec 2022 23:51:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: [PATCH v3 2/3] diff: use add_diff_options() in diff_opt_parse() From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jeff King , ZheNing Hu References: <0620b4a6-b80a-d8a0-5a35-857b9fe0c986@web.de> <19325420-5630-87bb-0c2c-362151214b36@web.de> In-Reply-To: <19325420-5630-87bb-0c2c-362151214b36@web.de> X-Provags-ID: V03:K1:De7q0LdTGtEz+2hH1WpVx3onwDDhhLDWfr1V/vyejEXwX4VqOje ARGI4cYJen586ARETMZdVS2oFBFBUslvdQUbpsV4WwM66EjTukJuOwt+7SXretBiHFMJ3Nd cm/N+6CiIs6n0MfJSQCvGIEUdb2TUNYkMLi6jBHladh4tQtUzXt1cejqw1ia0y/H6wzFqju uX/NzdtRBuE+n38FjDXXA== UI-OutboundReport: notjunk:1;M01:P0:XSvMA9Llsz4=;icm/YofIo1so/4HbRci+xQX0SwO jubnXm8F+mX+3k3KwA5/4KljlWVbCkD/T0GFGp2jlJgXCTv1XFcZLQL5x+v4XNYs/qJETNEtH ksooLIZDJ9XJ9I7i3sIxNymxvkQ3rWOh9YClW3dl28NCcO1cjAtVnJ2mq57jlcuv+XbfShN3c YhBD3iraAOqR4NkqicfIHq1hJKkt7chHQ8VGeT4SWBCAKl3YGNMWSsd3ymEsTuHF46aezlhBU gU96q2AIthSCXUxtoM7kX7OgbGra3U28ClFUZlkf1ZBQ6ISFERl4ZNXGfPfY+JV10+/tBypNb GwwQZUM4t0JfRyHinh3+N2ifXWFSMx2QeeAbJgi1faVwi3PLwbkT0011xfYVdDibEXWWS2T5T rUF1BjVt7gQWtRaNrggtAwoivrPYZzl/ZMdlFvhcHl1kBNR2l8STOgiUkE8+FevL55/6DcoZC T6Ov9cis03IR8ODYsXAV37ZCpRaE6s+PTlN22MShUp0ztA0PNKVb6ODjkhOJClXD496crXBqW c5hZ2FS5luLYMDRiNvJS5gkwq1qO+TuEY6YCD78KJBOk9Ptwzy7bpfcX0FSsw/SocIuRVwVvi QgCS6zp8P+tHLtq6Ue3UsbARc1OjgjM5RXUHoR+BRdnKK4NVXhQ1zoLuQgb8QnxcqKpjaneaK 3Zku6o78zoifxDVF96HBTgBY6FDaNuGTUEzJ7yNffAvGdm3bGIuOb6gidpj4tQnOQ676zAPH6 byeiIZaZDvO3c2gCqG/wTW4S0jF23xsajrxaAqAkk0R+tyuksoxBMhgR++3Befwz8/y8Bxy6w bJg3Bi0CrjBWMZc4zonDDa7DwNdBwM87U1XTBVW6GiYudYEYo/1tfsRYgRwRC+BgkWW61Skok 0R7ULawn7tqk9DDPheURmttHmh0Cu5yA9jY9mPGKCMj7+a5H6ymPgG93dytPp5ROWMix94jzl y/ZeeFKPvTbT+8w6vxUcT/xAO5U= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Prepare the removal of the parseopts member of struct diff_options by using the API function add_diff_options() instead of accessing it directly to get the command line option definitions. Building the copy by concatenating with an empty option array is slightly awkward, but simpler than a non-concat version of add_diff_options() would be to use in places that need concatenation. Suggested-by: Ævar Arnfjörð Bjarmason Signed-off-by: René Scharfe --- diff.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/diff.c b/diff.c index f1cf13e8e7..f6d85122a9 100644 --- a/diff.c +++ b/diff.c @@ -5702,15 +5702,19 @@ static void prep_parse_options(struct diff_options *options) int diff_opt_parse(struct diff_options *options, const char **av, int ac, const char *prefix) { + struct option no_options[] = { OPT_END() }; + struct option *parseopts = add_diff_options(no_options, options); + if (!prefix) prefix = ""; - ac = parse_options(ac, av, prefix, options->parseopts, NULL, + ac = parse_options(ac, av, prefix, parseopts, NULL, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT | PARSE_OPT_NO_INTERNAL_HELP | PARSE_OPT_ONE_SHOT | PARSE_OPT_STOP_AT_NON_OPTION); + free(parseopts); return ac; } From patchwork Thu Dec 1 22:53:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13061889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E063C4332F for ; Thu, 1 Dec 2022 22:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbiLAWxb (ORCPT ); Thu, 1 Dec 2022 17:53:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbiLAWx1 (ORCPT ); Thu, 1 Dec 2022 17:53:27 -0500 Received: from mout.web.de (mout.web.de [212.227.17.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 414427660 for ; Thu, 1 Dec 2022 14:53:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1669935197; bh=YlMPo0eF7dsyvxRXVaCLOkLL22l8alVyaOEaekmHgp8=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=C9WevTnIZknvkj6tZpkvROiEEUB5+k9HEGVsNX+n7J/d9QtJ+qU1scxDYdxyblU14 LOxbsgFNIt3faKnMW/ly2NWOdmluk6mO83XzJxl8zqgoZcFSSUGgSKfQEoV4cOzL7x 55UnPE/LsJ6ZyKxJefxe2AdKde/Y9oiUeeULJfHnK0+E12fiUbjtWCKaTtL3OAQHYg 262E3tbImXiHGDr2parNmm6HpSWJSAtpf5QGqWFym90eJPZ5uFkyeCDoHmP7qxUHGq orDp+5+xPwF2K6x3MkuVG317Mey09BX/CqKZbrG8rMljc5ZVDAVNSFPWyslhJOaTFs 8ukBstliOodsQ== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.34] ([91.47.154.159]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MT7WH-1pQV622TT5-00UnGs; Thu, 01 Dec 2022 23:53:17 +0100 Message-ID: <3816dd61-ee61-94b4-a2b2-49ee07986c5b@web.de> Date: Thu, 1 Dec 2022 23:53:17 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: [PATCH v3 3/3] diff: remove parseopts member from struct diff_options From: =?utf-8?q?Ren=C3=A9_Scharfe?= To: Git List Cc: Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Jeff King , ZheNing Hu References: <0620b4a6-b80a-d8a0-5a35-857b9fe0c986@web.de> <19325420-5630-87bb-0c2c-362151214b36@web.de> In-Reply-To: <19325420-5630-87bb-0c2c-362151214b36@web.de> X-Provags-ID: V03:K1:5hvn7/o7gWz25o74SEbQ0baXFq5Sy9thubQP3aV+BIKqFHAkbjP 4uIIPV/s0VOE5FV5mQynNb6UUzveoFLvaxThOlml9wD7oaVk7Zs9yYoJvdl+1K97D5ZEC4Q glN1By2Dqsm9d5rA1vxN71K9kdwnQD9m96wQJ+NSsAmjrRf0Kxif+1LRC0Ws/p5R/fo9VoS 01SNeSpSxbY5U2VAu9Pbw== UI-OutboundReport: notjunk:1;M01:P0:fZnoYyY319Y=;nBF4dvLK8z2rOaKSCwr31rLOaJ/ JkdnL2F9bUYPxcurYaINd4XxxJ6hQrDwn2lEcaSE5zH6uwt7HdhynKXhkcoUtG73AERd4r6OD dFpbBh1ANk4t7v0N+Jb3NHDep5/wxw43PpoS6nmpftpwUUwDyNGD3taMXkcU9yQU2gg/z0UEZ GS2t+C4nZTEi49jqkQRBb0kmHO5e1Y/3SeqfD1+7lrBUqgEE1GnmwQAfnuTlpH/2PQ1LaCrDB UML2UBrrQlxCuzXMtdxIPgA12UCZObpL2w902R2vnw3mVXOd3PCpjGh7IEJ+o+i0NbiW5Wu3L jaPzAOiWhnAHpymnVy7gpP6i4rD+jZwMbYhlxZo+0Hs8/MbIhScvdU0qJHfAVvj02NDCFCS7e C/P7zH4+eG/NSGbWG5PcdE39Zt6MYDPcLCr6NqzegwtH+r92h9xQebiiLApeH/52c0FNuhByR u1RnbsFMv7CDwjqo6b2C36anL5jLH9CiCWY7z7T4yRvXmqJX/AxuKLLWLomxSbOQK3XeU5Q5/ yjYzQPpfEiGsGmCqeylcUe45HVnxTrREoTDVoVkbbRtWlu3dGn/Kl0eQT/bc6I2aWYBtJjDvQ XVa/7W9tIZEn9HxfxqAV84GYHr3Ua1o3C/uGmRkcEpk2gU3tv8+OrHz0Aj9URJu/KhsVkTtRq 4wba+cz2bnf9OEAKXBku9N2N5MSH++H6FeRr+sjt4UKVt/0oOXzcfS0m4q7zs9hEeFKSsyBC5 0DWfodhAxUdPiOWMAh7TaAmQki3iNWEqLGkMFh8fmhsYB/aTE/2Y0NDlBoZFxRZjlZvwRIY/t sqfZaa9V1i+iPGc/oODBg5010lrjrQCi2jt+vnl61ocAH2C10Zp1r3/ahW5M6napm2ZS0mE0U nuW4uTyP5fWPU/9gqtM8twWAWqbL2ule0c0N7jhULJEmPV27kxcJ0cbJ9Mntz9b4lDfqXpvvo ZeGEx0oTQ/zzGQAhJJ6DJqHFEpg= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org repo_diff_setup() builds the struct option array with git diff's command line options and stores a pointer to it in the parseopts member of struct diff_options. The array is freed by diff_setup_done(), but not by release_revisions(). Thus calling only repo_diff_setup() and release_revisions() leaks that array. We could free it in release_revisions() as well to plug that leak, but there is a better way: Only build it when needed. Absorb prep_parse_options() into the last place that uses the parseopts member of struct diff_options, add_diff_parseopts(), and get rid of said member. Signed-off-by: René Scharfe --- diff.c | 15 +-------------- diff.h | 1 - 2 files changed, 1 insertion(+), 15 deletions(-) -- 2.30.2 diff --git a/diff.c b/diff.c index f6d85122a9..4dfe824c85 100644 --- a/diff.c +++ b/diff.c @@ -4615,8 +4615,6 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o) builtin_checkdiff(name, other, attr_path, p->one, p->two, o); } -static void prep_parse_options(struct diff_options *options); - void repo_diff_setup(struct repository *r, struct diff_options *options) { memcpy(options, &default_diff_options, sizeof(*options)); @@ -4662,8 +4660,6 @@ void repo_diff_setup(struct repository *r, struct diff_options *options) options->color_moved = diff_color_moved_default; options->color_moved_ws_handling = diff_color_moved_ws_default; - - prep_parse_options(options); } static const char diff_status_letters[] = { @@ -4821,8 +4817,6 @@ void diff_setup_done(struct diff_options *options) options->filter = ~filter_bit[DIFF_STATUS_FILTER_AON]; options->filter &= ~options->filter_not; } - - FREE_AND_NULL(options->parseopts); } int parse_long_opt(const char *opt, const char **argv, @@ -5421,11 +5415,6 @@ static int diff_opt_rotate_to(const struct option *opt, const char *arg, int uns struct option *add_diff_options(const struct option *opts, struct diff_options *options) -{ - return parse_options_concat(opts, options->parseopts); -} - -static void prep_parse_options(struct diff_options *options) { struct option parseopts[] = { OPT_GROUP(N_("Diff output format options")), @@ -5695,8 +5684,7 @@ static void prep_parse_options(struct diff_options *options) OPT_END() }; - ALLOC_ARRAY(options->parseopts, ARRAY_SIZE(parseopts)); - memcpy(options->parseopts, parseopts, sizeof(parseopts)); + return parse_options_concat(opts, parseopts); } int diff_opt_parse(struct diff_options *options, @@ -6523,7 +6511,6 @@ void diff_free(struct diff_options *options) diff_free_file(options); diff_free_ignore_regex(options); clear_pathspec(&options->pathspec); - FREE_AND_NULL(options->parseopts); } void diff_flush(struct diff_options *options) diff --git a/diff.h b/diff.h index c20a1ad76d..41eb2c3d42 100644 --- a/diff.h +++ b/diff.h @@ -394,7 +394,6 @@ struct diff_options { unsigned color_moved_ws_handling; struct repository *repo; - struct option *parseopts; struct strmap *additional_path_headers; int no_free;