From patchwork Wed Apr 17 14:30:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 10905429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 018A114DB for ; Wed, 17 Apr 2019 14:33:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE7B6287D3 for ; Wed, 17 Apr 2019 14:33:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2CB028B3C; Wed, 17 Apr 2019 14:33:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A714328B2C for ; Wed, 17 Apr 2019 14:33:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732524AbfDQOdK (ORCPT ); Wed, 17 Apr 2019 10:33:10 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52270 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732476AbfDQOdJ (ORCPT ); Wed, 17 Apr 2019 10:33:09 -0400 Received: by mail-wm1-f66.google.com with SMTP id a184so3676921wma.2 for ; Wed, 17 Apr 2019 07:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=XMjIpNyaO5FyQdCuidnj3R1xFj9i6i3i8gEmKbtmaoU=; b=WGxJGVy5MFAzt++0VXkBW6YPbJoYKbcTf4GiUUSYUWPD7VSnotO0ZPDvlC0sNaD064 AVwwIqAgGV1Ea7OiQbTEw9KV85wdhNZ2i2y4Lkw8i4THOH4HWJuZtKUjCM5bKzjkHtMj Hz6A9oORDJP0fPhruQ22ftEb6ExN40O/vXJF4ZPokr+Bkt3KgfZ/rHNIYpMe8nUPHI6X 6Bcr8t29He/t1JNwZ21EsRhI1XgMym/PQIVoofTDbtz/Eag0THRkmQkNg3KbFJ8xeU1B MNhQlmIC3Sih1lQVvIRxKwLp2t5PQqr0Hec+hVMKra2Aiv2wUoPrRs+KywA874TtU+M7 +kog== 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:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=XMjIpNyaO5FyQdCuidnj3R1xFj9i6i3i8gEmKbtmaoU=; b=lm5+yohIdF4zgZ9bRd5jRJgev/83tbgln+hcwUTwyRfWu6nXFVeN4R8y07O307gIW1 qQ3CwqnrUOVLV6mX1nm9w00qHOmuqAcvNVdyfxsIdYylYT8wwfLuqSGb1zu16IavEjTw aEKMJV0tOB5MUfCieiTeh7QlDXNVfUbIwaMUFHZqQWleHMUk8NZkf5v6CC5yb1Zb2RbN yi76CeYk3n3V6F26JbOWbhwyp4MhuF7D4YvOQE8NeFDKG/b8nHgbNRqPzeHkdflNvF2J 7WlrAFsgVVjIbNIWnDPdXx30RC1CUFm1anR8siwFnm5z2nCsZzUQdO354Vz7ArE1lo9i 4jnw== X-Gm-Message-State: APjAAAWNAskpNL6PjbBHAOTfMSEs5ZbsYV7GeFrVRT4+Q5DUArEJV/0V XaGoHrXwICyB4o9dgqPeWLSZQG7S5xE= X-Google-Smtp-Source: APXvYqzBuecUrSGciT9N5FSDZhv+Vh1OUioZ/zUBgI/U4eQvxIOItDnTmRJ7IMxvfoTG3Ipp2ad35Q== X-Received: by 2002:a7b:c458:: with SMTP id l24mr30360362wmi.75.1555511586878; Wed, 17 Apr 2019 07:33:06 -0700 (PDT) Received: from localhost.localdomain (host-92-22-21-176.as13285.net. [92.22.21.176]) by smtp.gmail.com with ESMTPSA id t17sm52127726wrr.26.2019.04.17.07.33.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 07:33:06 -0700 (PDT) From: Phillip Wood To: Git Mailing List Cc: Johannes Schindelin , Junio C Hamano , Elijah Newren , Duy Nguyen , Alban Gruin , Josh Steadmon , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= , Phillip Wood Subject: [PATCH v1 08/12] rebase -i: use struct object_id for squash_onto Date: Wed, 17 Apr 2019 15:30:40 +0100 Message-Id: <20190417143044.17655-9-phillip.wood123@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190417143044.17655-1-phillip.wood123@gmail.com> References: <20190319190317.6632-1-phillip.wood123@gmail.com> <20190417143044.17655-1-phillip.wood123@gmail.com> Reply-To: Phillip Wood MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Phillip Wood More preparation for using `struct rebase_options` in cmd_rebase__interactive(). Using a string was a hangover from the scripted version of rebase, update the functions that use `squash_onto` to take a `sturct object_id`. Signed-off-by: Phillip Wood --- builtin/rebase.c | 21 +++++++++++++-------- parse-options-cb.c | 17 +++++++++++++++++ parse-options.h | 3 +++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 06f6490ca3..3b9da69473 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -198,7 +198,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name, static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *switch_to, struct commit *upstream, struct commit *onto, const char *onto_name, - const char *squash_onto, const char *head_name, + struct object_id *squash_onto, const char *head_name, struct commit *restrict_revision, char *raw_strategies, struct string_list *commands, unsigned autosquash) { @@ -226,7 +226,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, } if (!upstream && squash_onto) - write_file(path_squash_onto(), "%s\n", squash_onto); + write_file(path_squash_onto(), "%s\n", + oid_to_hex(squash_onto)); argv_array_pushl(&make_script_args, "", revisions, NULL); if (restrict_revision) @@ -267,10 +268,11 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) struct replay_opts opts = REPLAY_OPTS_INIT; unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0; int abbreviate_commands = 0, rebase_cousins = -1, ret = 0; - const char *onto_name = NULL, - *squash_onto = NULL, *head_name = NULL, - *switch_to = NULL, *cmd = NULL; + const char *onto_name = NULL, *head_name = NULL, *switch_to = NULL, + *cmd = NULL; struct commit *onto = NULL, *upstream = NULL, *restrict_revision = NULL; + struct object_id squash_onto = null_oid; + struct object_id *squash_onto_opt = NULL; struct string_list commands = STRING_LIST_INIT_DUP; char *raw_strategies = NULL; enum { @@ -311,8 +313,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) { OPTION_CALLBACK, 0, "restrict-revision", &restrict_revision, N_("restrict-revision"), N_("restrict revision"), PARSE_OPT_NONEG, parse_opt_commit, 0 }, - OPT_STRING(0, "squash-onto", &squash_onto, N_("squash-onto"), - N_("squash onto")), + { OPTION_CALLBACK, 0, "squash-onto", &squash_onto, N_("squash-onto"), + N_("squash onto"), PARSE_OPT_NONEG, parse_opt_object_id, 0 }, { OPTION_CALLBACK, 0, "upstream", &upstream, N_("upstream"), N_("the upstream commit"), PARSE_OPT_NONEG, parse_opt_commit, 0 }, @@ -349,6 +351,9 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) opts.gpg_sign = xstrdup_or_null(opts.gpg_sign); + if (!is_null_oid(&squash_onto)) + squash_onto_opt = &squash_onto; + flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0; flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0; flags |= rebase_merges ? TODO_LIST_REBASE_MERGES : 0; @@ -373,7 +378,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) die(_("a base commit must be provided with --upstream or --onto")); ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto, - onto_name, squash_onto, head_name, restrict_revision, + onto_name, squash_onto_opt, head_name, restrict_revision, raw_strategies, &commands, autosquash); break; case SKIP: { diff --git a/parse-options-cb.c b/parse-options-cb.c index 2206eb763c..28ad5cd94b 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -129,6 +129,23 @@ int parse_opt_object_name(const struct option *opt, const char *arg, int unset) return 0; } +int parse_opt_object_id(const struct option *opt, const char *arg, int unset) +{ + struct object_id oid; + struct object_id *target = opt->value; + + if (unset) { + *target = null_oid; + return 0; + } + if (!arg) + return -1; + if (get_oid(arg, &oid)) + return error(_("malformed object name '%s'"), arg); + *target = oid; + return 0; +} + int parse_opt_tertiary(const struct option *opt, const char *arg, int unset) { int *target = opt->value; diff --git a/parse-options.h b/parse-options.h index 5a75646618..0ab1103bc7 100644 --- a/parse-options.h +++ b/parse-options.h @@ -264,7 +264,10 @@ int parse_opt_abbrev_cb(const struct option *, const char *, int); int parse_opt_expiry_date_cb(const struct option *, const char *, int); int parse_opt_color_flag_cb(const struct option *, const char *, int); int parse_opt_verbosity_cb(const struct option *, const char *, int); +/* value is struct oid_array* */ int parse_opt_object_name(const struct option *, const char *, int); +/* value is struct object_id* */ +int parse_opt_object_id(const struct option *, const char *, int); int parse_opt_commits(const struct option *, const char *, int); int parse_opt_commit(const struct option *, const char *, int); int parse_opt_tertiary(const struct option *, const char *, int);