From mboxrd@z Thu Jan 1 00:00:00 1970 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 3AC82C433EF for ; Thu, 6 Jan 2022 19:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243200AbiAFTG2 (ORCPT ); Thu, 6 Jan 2022 14:06:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243164AbiAFTGZ (ORCPT ); Thu, 6 Jan 2022 14:06:25 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3EA1C061245 for ; Thu, 6 Jan 2022 11:06:24 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id k18so6652046wrg.11 for ; Thu, 06 Jan 2022 11:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=VpiZ5jZ3d+dnGMOxcTmS1IsOgl6i+ekmZauA/yErcbE=; b=J+HGrpYZPppodDni72QLLnVIfjUE9Hsaj/NZH6CVesHqQUoWokQFEjjTvnnt33KcZH RHHE+jYHFGlz6PiOBJadYT2xgWagXTufi8KMiwMPPAwDoIjf4h7b7baJfTvcdbIPImDc 6tJTuxHDe8SpfxzrzXliaTR4oe9d/9fmrfKMaiPjDX1G6gpP/k+nsRDiMwOL3SzwC4CR NYqMA2SuhRPEBT7UNOL07R9hWnpofbOarujdYAnuX3b4Nuu+4UAQezsjJvcZpfq7h4qs uwZ8Rg807gGCPLPTaARjlewY6NXZkEkZzPHwnVHm6X0ZPEgi9qRyEDl4G4Ejp2OiaqJh LXvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=VpiZ5jZ3d+dnGMOxcTmS1IsOgl6i+ekmZauA/yErcbE=; b=ZjIxombajHWawE0V+yEPFEXJsM6U/3tpreB9n7q2NgWLSXeGN0Xwk3/q79bNsfLe7n QKc8zzMytuJloUnjKLfb+IetyzHw4J/vQWOYg3q/TMXnocG37BdJfaYY4qiBEHJRnd+A msie7SMakBx8LtkXFXtchY1ZMGi0Z7xSMBqU8RsHgNM2N5+1DeC0kYIMPEcFboww+BBJ 6c7dkFk4z4d3yzhpdTtvyvHjH5pu8FFUFOQ/uvMB6TRsD7tU7ORtFGqU8SE9ONfrsTba gmCTUfIrEgjG/vy9eKIf8OkToxEL7XLtTdmQHTKsBHjlDjo9IMOu4jbAMDI+FSg3ebig tWLQ== X-Gm-Message-State: AOAM532Dl2T4ceKvmaQZEGtws9aFczLABNdeT3mENhcqRuEgbnIpOxs7 gOl6mJLkSznpJfxI1n2+/R774+1fnvo= X-Google-Smtp-Source: ABdhPJw6rGtvEOjJM36tIsbCLZ9TwFzikuC6gExMEZLQ8UYDILzlx6i/DyyKX10KGKRS2ytUVrbGZw== X-Received: by 2002:a5d:64c8:: with SMTP id f8mr55936934wri.158.1641495983023; Thu, 06 Jan 2022 11:06:23 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n17sm2748247wmc.32.2022.01.06.11.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 11:06:22 -0800 (PST) Message-Id: In-Reply-To: References: From: "John Cai via GitGitGadget" Date: Thu, 06 Jan 2022 19:06:21 +0000 Subject: [PATCH v5] builtin/reflog.c: use parse-options api for expire, delete subcommands Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?UTF-8?Q?Ren=C3=A9?= Scharfe , John Cai , John Cai Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: John Cai Switching out manual arg parsing for the parse-options API for the expire and delete subcommands. Move explicit_expiry flag into cmd_reflog_expire_cb struct so callbacks can set both the value of the timestamp as well as the explicit_expiry flag. Signed-off-by: "John Cai" --- reflog.c: switch to use parse-options API Switch out manual argv parsing for the reflog expire subcommand to use the parse-options API. This reduces code redundancy by consolidating option parsing logic. NOTE: this patch was based off of next. I know now that I should base it off of master. But practically, nothing in master touched reflog.c except for ab/reflog-prep changes since v4: * fixed indentation of option blocks * adjusted error message for invalid timestamps changes since v3: * fixed indentation changes since v2: * got rid of parse_opt_expiry_date helper based on feedback from Junio. Just call parse_expiry_date directly in the callbacks, and don't worry about unset, as we can just set the PARSE_OPT_NONEG flag for --expire and --expire-unreachable since the original code didn't support a negated version of those flags anyway. The documentation also explicitly states to use "never" as the argument. * fix places where we set int i inside a for loop construct. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1175%2Fjohn-cai%2Fjc%2Freflog-switch-to-option-parse-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1175/john-cai/jc/reflog-switch-to-option-parse-v5 Pull-Request: https://github.com/git/git/pull/1175 Range-diff vs v4: 1: 0efdf3d2cb1 ! 1: 9bb4de0f543 builtin/reflog.c: use parse-options api for expire, delete subcommands @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + struct cmd_reflog_expire_cb *cmd = opt->value; + + if (parse_expiry_date(arg, &cmd->expire_unreachable)) -+ die(_("malformed expiration date '%s'"), arg); ++ die(_("invalid timestamp '%s' given to '--%s'"), ++ arg, opt->long_name); + + cmd->explicit_expiry |= EXPIRE_UNREACH; + return 0; @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + struct cmd_reflog_expire_cb *cmd = opt->value; + + if (parse_expiry_date(arg, &cmd->expire_total)) -+ die(_("malformed expiration date '%s'"), arg); ++ die(_("invalid timestamp '%s' given to '--%s'"), ++ arg, opt->long_name); + + cmd->explicit_expiry |= EXPIRE_TOTAL; + return 0; @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + const struct option options[] = { + OPT_BIT(0, "dry-run", &flags, N_("do not actually prune any entries"), + EXPIRE_REFLOGS_DRY_RUN), -+ OPT_BIT(0, "rewrite", &flags, ++ OPT_BIT(0, "rewrite", &flags, + N_("rewrite the old SHA1 with the new SHA1 of the entry that now precedes it"), + EXPIRE_REFLOGS_REWRITE), + OPT_BIT(0, "updateref", &flags, @@ builtin/reflog.c: static void set_reflog_expiry_param(struct cmd_reflog_expire_c + EXPIRE_REFLOGS_UPDATE_REF), + OPT_BOOL(0, "verbose", &verbose, N_("print extra information on screen.")), + OPT_CALLBACK_F(0, "expire", &cmd, N_("timestamp"), -+ N_("prune entries older than the specified time"), -+ PARSE_OPT_NONEG, -+ expire_total_callback), ++ N_("prune entries older than the specified time"), ++ PARSE_OPT_NONEG, ++ expire_total_callback), + OPT_CALLBACK_F(0, "expire-unreachable", &cmd, N_("timestamp"), -+ N_("prune entries older than