From patchwork Sun Feb 10 13:26:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804767 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 6F7CA746 for ; Sun, 10 Feb 2019 13:27:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6113B29F76 for ; Sun, 10 Feb 2019 13:27:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55F4129F96; Sun, 10 Feb 2019 13:27:15 +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 438C029F91 for ; Sun, 10 Feb 2019 13:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726152AbfBJN1K (ORCPT ); Sun, 10 Feb 2019 08:27:10 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39989 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbfBJN1J (ORCPT ); Sun, 10 Feb 2019 08:27:09 -0500 Received: by mail-wm1-f66.google.com with SMTP id q21so11785324wmc.5 for ; Sun, 10 Feb 2019 05:27:08 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=wkM/ZGhDfJV4zUlu5bubd7IXS+rOC3pRapW96j2EDb8=; b=tzDTFMm3M1FerlkDahgOzfqDukS72DlCW3ReIeOB0IbwS3lUH9/AswlJl0hKlILGj6 H/RVsJITyXMQ+EszLs4nkIzCJVY0Y2g5kvxjn9E4vYAw4F47TdPRxx4tnX+GcClKics+ NWoULtaMdrbjIn+HmNFG3+FfURyydVssWXP2xRgcInN687KnZijxi5Db0hJr18TGSEA9 RkaL0tm4hh489y59pKPUVDLxRnPZOpp9ncDAS/CWus9QNC89cPV1mM00MaRqxId5Xq52 1d6LqZ2Sjtznv+/aY2vAMY+GvIAtA+4LJEvTRQi4lHQXXIkC5nepCQDrBiy9zjk64f9f SaDw== 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:mime-version:content-transfer-encoding; bh=wkM/ZGhDfJV4zUlu5bubd7IXS+rOC3pRapW96j2EDb8=; b=BJfRd0ev23JDmw9lMZ85hZI4RO7oh8ms9bHxsxNL39xLxVajm92JtNhAMMDLipasyt 6sbDMWY4Xk5nZ1s6nNrsOnA2JB/0PlkRDbDoGVwwlAnXJ9oxb9YsSd9qOSfPzykiJydv JDjDEFu5q5pXSNsRopAhS0w3EPviRZqoe1VqqXvbb2yrxS7P5Lx75VoDQNIhQoY2mFRx KbAcYSYhnoBIwO1315M3ZVTvstsiXxoPVun030Wz7aAW76Okp/6/1colo4NIPKUJOxs0 t3yQr7Zr7Fc8Y+KXbsRZoWofJrbOg2f/BeZDOwahuCEkuBXzrHvk990JWGLxpa/06wsY HZqA== X-Gm-Message-State: AHQUAuZw5rGIRZVRW4qHw12D3NyN7xbUM82mKl45VyuIUnVwh9aDoQGs gjSSgw0jPA1Kx/4v37fjkyl9IDm1 X-Google-Smtp-Source: AHgI3IYReiFRWSTjDgVuOgbH2PYfS0JEfTEX5TxD+yAiYL4nMXmtwxRIiHDYGvCOaq3PYYvKd2kRIQ== X-Received: by 2002:adf:efc2:: with SMTP id i2mr5807196wrp.44.1549805227122; Sun, 10 Feb 2019 05:27:07 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:06 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 01/16] sequencer: changes in parse_insn_buffer() Date: Sun, 10 Feb 2019 14:26:33 +0100 Message-Id: <20190210132648.12821-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This clears the number of items of a todo_list before parsing it to allow to parse the same list multiple times without issues. As its items are not dynamically allocated, or don’t need to allocate memory, no additionnal memory management is required here. Furthermore, if a line is invalid, the type of the corresponding command is set to a garbage value, and its argument is defined properly. This will allow to recreate the text of a todo list from its commands, even if one of them is incorrect. Signed-off-by: Alban Gruin --- No changes since v6. sequencer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index b68bca0bef..d605199a54 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2141,6 +2141,8 @@ static int parse_insn_buffer(struct repository *r, char *buf, char *p = buf, *next_p; int i, res = 0, fixup_okay = file_exists(rebase_path_done()); + todo_list->current = todo_list->nr = 0; + for (i = 1; *p; i++, p = next_p) { char *eol = strchrnul(p, '\n'); @@ -2154,7 +2156,10 @@ static int parse_insn_buffer(struct repository *r, char *buf, if (parse_insn_line(r, item, p, eol)) { res = error(_("invalid line %d: %.*s"), i, (int)(eol - p), p); - item->command = TODO_NOOP; + item->command = TODO_COMMENT + 1; + item->arg = p; + item->arg_len = (int)(eol - p); + item->commit = NULL; } if (fixup_okay) From patchwork Sun Feb 10 13:26:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804769 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 B0D8D17FB for ; Sun, 10 Feb 2019 13:27:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A029229F76 for ; Sun, 10 Feb 2019 13:27:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 947FF29F91; Sun, 10 Feb 2019 13:27:15 +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 6753F29F95 for ; Sun, 10 Feb 2019 13:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726191AbfBJN1M (ORCPT ); Sun, 10 Feb 2019 08:27:12 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34447 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfBJN1L (ORCPT ); Sun, 10 Feb 2019 08:27:11 -0500 Received: by mail-wm1-f68.google.com with SMTP id y185so11719064wmd.1 for ; Sun, 10 Feb 2019 05:27:09 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=HXwEsfy/k91iWrlBMkI0DkN3oUjFaiitDTh6Clqi9ws=; b=Z/grBwx5Zp57jE6rW+x9lTvvDTBpT7C5qlrnEawI/ZUMdakJngOo4MknwugQNxI6aT 3ULdXcKBeCagXSGSWbkXkeVPJdNIx40lvmSoDn7MlrIrRqkSHtG4BTf+BTUYXdU3T+5y LBIxwpMw6liqRr9k/17ebPej65yH2tA6pgfGLmo57+n70MiIenPJkNpklc37aVA2LFI3 TvaZ/Ji4PG2S2vULdwFNUZFxZ+MxtafYhe08RpGVIcTOiEJCfSuoff5mUNeHGgNIdh24 rohf9nIjvar7d1ya74zL1UklBb2lFHFU5IA1rlNUyyLAmewnfwkPs1aBJEWNGHl0Ncgp 6EHw== 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:mime-version:content-transfer-encoding; bh=HXwEsfy/k91iWrlBMkI0DkN3oUjFaiitDTh6Clqi9ws=; b=ofqd1BexqfkuLKtF/5BCBDVMOnwuRL4m9Hjgn/+UOq4pK3If679Vl8Z+YNUaybnrRC G5PRpK64lolQu++cph1lf24U6+f+nEVUwJ/BoFBGZjJuHpU6+McvMf+eT3sHhokZzwaV hqXZUZj+UEq5hX7EAyQxr9R6loXsUlK3L73h4kwXjKR2Ttce8W/D9VI+RXdtZ4MXBZZG MUJcM5DZD7S0iiiCqf5sJqdDW4po2dQQrfULJ1UsVOjpSAv25OE1cRBdz9SgK7LLWoh8 1caulki6XNEupABKqNpgxMsMts97X1FqSgl3lkm3DJqS02WN/FSKCsHx0jJxq8nC6DAW 5L+A== X-Gm-Message-State: AHQUAubnlGL0a4Jx8cXvlwRubi/RfcENkYjUdpKgE879p7Quf/jWhnuE +zXOO5M7YtcAiwEHGanKeb6SccLB X-Google-Smtp-Source: AHgI3IbTu6yf9LL44SH2e54QIF9QfqQOYO6Kcg+ZcPwdaHLQpiwTlNklDS2YH15QyVICWX+2x4xrkw== X-Received: by 2002:a1c:6707:: with SMTP id b7mr5868525wmc.138.1549805228433; Sun, 10 Feb 2019 05:27:08 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:07 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 02/16] sequencer: make the todo_list structure public Date: Sun, 10 Feb 2019 14:26:34 +0100 Message-Id: <20190210132648.12821-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This makes the structures todo_list and todo_item, and the functions todo_list_release() and parse_insn_buffer(), accessible outside of sequencer.c. Signed-off-by: Alban Gruin --- No changes since v6. sequencer.c | 69 ++++++++++------------------------------------------- sequencer.h | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/sequencer.c b/sequencer.c index d605199a54..25cc7a9a91 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1510,32 +1510,6 @@ static int allow_empty(struct repository *r, return 1; } -/* - * Note that ordering matters in this enum. Not only must it match the mapping - * below, it is also divided into several sections that matter. When adding - * new commands, make sure you add it in the right section. - */ -enum todo_command { - /* commands that handle commits */ - TODO_PICK = 0, - TODO_REVERT, - TODO_EDIT, - TODO_REWORD, - TODO_FIXUP, - TODO_SQUASH, - /* commands that do something else than handling a single commit */ - TODO_EXEC, - TODO_BREAK, - TODO_LABEL, - TODO_RESET, - TODO_MERGE, - /* commands that do nothing but are counted for reporting progress */ - TODO_NOOP, - TODO_DROP, - /* comments (not counted for reporting progress) */ - TODO_COMMENT -}; - static struct { char c; const char *str; @@ -2012,26 +1986,7 @@ enum todo_item_flags { TODO_EDIT_MERGE_MSG = 1 }; -struct todo_item { - enum todo_command command; - struct commit *commit; - unsigned int flags; - const char *arg; - int arg_len; - size_t offset_in_buf; -}; - -struct todo_list { - struct strbuf buf; - struct todo_item *items; - int nr, alloc, current; - int done_nr, total_nr; - struct stat_data stat; -}; - -#define TODO_LIST_INIT { STRBUF_INIT } - -static void todo_list_release(struct todo_list *todo_list) +void todo_list_release(struct todo_list *todo_list) { strbuf_release(&todo_list->buf); FREE_AND_NULL(todo_list->items); @@ -2134,8 +2089,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, return !item->commit; } -static int parse_insn_buffer(struct repository *r, char *buf, - struct todo_list *todo_list) +int todo_list_parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list) { struct todo_item *item; char *p = buf, *next_p; @@ -2234,7 +2189,7 @@ static int read_populate_todo(struct repository *r, return error(_("could not stat '%s'"), todo_file); fill_stat_data(&todo_list->stat, &st); - res = parse_insn_buffer(r, todo_list->buf.buf, todo_list); + res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); if (res) { if (is_rebase_i(opts)) return error(_("please fix this using " @@ -2265,7 +2220,7 @@ static int read_populate_todo(struct repository *r, FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w"); if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 && - !parse_insn_buffer(r, done.buf.buf, &done)) + !todo_list_parse_insn_buffer(r, done.buf.buf, &done)) todo_list->done_nr = count_commands(&done); else todo_list->done_nr = 0; @@ -4556,7 +4511,7 @@ int sequencer_add_exec_commands(struct repository *r, if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4612,7 +4567,7 @@ int transform_todos(struct repository *r, unsigned flags) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4698,7 +4653,7 @@ int check_todo_list(struct repository *r) goto leave_check; } advise_to_edit_todo = res = - parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); if (res || check_level == MISSING_COMMIT_CHECK_IGNORE) goto leave_check; @@ -4717,7 +4672,7 @@ int check_todo_list(struct repository *r) goto leave_check; } strbuf_release(&todo_file); - res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + res = !!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); /* Find commits in git-rebase-todo.backup yet unseen */ for (i = todo_list.nr - 1; i >= 0; i--) { @@ -4799,7 +4754,7 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } @@ -4887,7 +4842,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (strbuf_read_file(buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, buf->buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4995,7 +4950,7 @@ int rearrange_squash(struct repository *r) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } diff --git a/sequencer.h b/sequencer.h index 9d83f0f3e9..c6360bac66 100644 --- a/sequencer.h +++ b/sequencer.h @@ -73,6 +73,56 @@ enum missing_commit_check_level { int write_message(const void *buf, size_t len, const char *filename, int append_eol); +/* + * Note that ordering matters in this enum. Not only must it match the mapping + * of todo_command_info (in sequencer.c), it is also divided into several + * sections that matter. When adding new commands, make sure you add it in the + * right section. + */ +enum todo_command { + /* commands that handle commits */ + TODO_PICK = 0, + TODO_REVERT, + TODO_EDIT, + TODO_REWORD, + TODO_FIXUP, + TODO_SQUASH, + /* commands that do something else than handling a single commit */ + TODO_EXEC, + TODO_BREAK, + TODO_LABEL, + TODO_RESET, + TODO_MERGE, + /* commands that do nothing but are counted for reporting progress */ + TODO_NOOP, + TODO_DROP, + /* comments (not counted for reporting progress) */ + TODO_COMMENT +}; + +struct todo_item { + enum todo_command command; + struct commit *commit; + unsigned int flags; + const char *arg; + int arg_len; + size_t offset_in_buf; +}; + +struct todo_list { + struct strbuf buf; + struct todo_item *items; + int nr, alloc, current; + int done_nr, total_nr; + struct stat_data stat; +}; + +#define TODO_LIST_INIT { STRBUF_INIT } + +int todo_list_parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list); +void todo_list_release(struct todo_list *todo_list); + /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); int sequencer_pick_revisions(struct repository *repo, From patchwork Sun Feb 10 13:26:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804773 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 3E81F746 for ; Sun, 10 Feb 2019 13:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E27229F76 for ; Sun, 10 Feb 2019 13:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22AC429F99; Sun, 10 Feb 2019 13:27:18 +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 5EA7129F76 for ; Sun, 10 Feb 2019 13:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726207AbfBJN1N (ORCPT ); Sun, 10 Feb 2019 08:27:13 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51952 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbfBJN1N (ORCPT ); Sun, 10 Feb 2019 08:27:13 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so12228427wmj.1 for ; Sun, 10 Feb 2019 05:27:11 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=GP9AsZXhEQ+GX1v8Jy9YgRCFbSM6lBbmOSa2xd2PBik=; b=aG0/s4xfV/OamjrQlp9lGGAvkBx52HeDcfZBuzCky4z+NEem0Arqz4vmFKiWlmbmkI rNurFJ4XY6Yr2Eo2m9DVvj4iokUKTE1LfFA4gs/SRlz/Ijh0/g0aSjQOaCbQxi3gBVlo ILC6+sX9KF5jYgq13+pVJi2GKLPQASTFmRjmnB3mrXkIiR5EkFdoRmf+gvYEXA0vLQY2 8s6J6gb1O25muMJ6nbavK1gjWBWJpKQY2Imq43tcdisA/GkTPpIWavG3CxHdqqNYUwa3 1I4vkWFE/7WJ2xewKIz4cKkVwYvK4WObc2Ys09Ko6ykSwCAWqObr9Rhimh6nT2O+w18x 2yxw== 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:mime-version:content-transfer-encoding; bh=GP9AsZXhEQ+GX1v8Jy9YgRCFbSM6lBbmOSa2xd2PBik=; b=QnFPRHARFysPVhdeaMm9Akd0IAMnjALTqJyYLKVQZu5cc4yLsb1Z5SKoxsB0mDTW0g M4QUSvudLaRb0Y1xx7Q9HzwlKUUid0PmMkOqJnTWDmN93WtrSuJCR6ima1QihM9HhNgI 4Fk2sw5dz5jsdcZ1r4ot0yrenhnxEAE0GdXb6UL1OmKtDzTn57T04LoIUnyOcEfTFcm3 HNiuDlmHhLMsl18Bb9yNC+Yw2Q74Aej/K5S197//6S0PKv75Ygd+24x4hOMjrE5Sd7xx TJDlDqWO6WYVyQmg/2oKS6LEP19bgBuobljtunJ0HtkWuT7JqU010V0im4yFrlpo20To aSwg== X-Gm-Message-State: AHQUAuajkaEG4dtthRuMdd6UozsrxhPXfRMdgN0rFeYdH4mObSuRwYFq SauITQ6z3BfnHB9ZsCpNReD4cJGd X-Google-Smtp-Source: AHgI3Ibn1uYyptc8SEKyjjGOmwigKW4PtSsS+VP3/aq5Fzp26dDCIciZloUxQfgzZgEytzDwVBF/TA== X-Received: by 2002:a1c:7409:: with SMTP id p9mr6101720wmc.136.1549805230003; Sun, 10 Feb 2019 05:27:10 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:09 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 03/16] sequencer: remove the 'arg' field from todo_item Date: Sun, 10 Feb 2019 14:26:35 +0100 Message-Id: <20190210132648.12821-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 The 'arg' field of todo_item used to store the address of the first byte of the parameter of a command in a todo list. It was associated with the length of the parameter (the 'arg_len' field). This replaces the 'arg' field by 'arg_offset'. This new field does not store the address of the parameter, but the position of the first character of the parameter in the buffer. todo_item_get_arg() is added to return the address of the parameter of an item. This will prevent todo_list_add_exec_commands() from having to do awful pointer arithmetics when growing the todo list buffer. Signed-off-by: Alban Gruin --- No changes since v6. sequencer.c | 67 ++++++++++++++++++++++++++++++----------------------- sequencer.h | 6 +++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/sequencer.c b/sequencer.c index 25cc7a9a91..c844a9b7f3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1999,8 +1999,14 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list) return todo_list->items + todo_list->nr++; } +const char *todo_item_get_arg(struct todo_list *todo_list, + struct todo_item *item) +{ + return todo_list->buf.buf + item->arg_offset; +} + static int parse_insn_line(struct repository *r, struct todo_item *item, - const char *bol, char *eol) + const char *buf, const char *bol, char *eol) { struct object_id commit_oid; char *end_of_object_name; @@ -2014,7 +2020,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, if (bol == eol || *bol == '\r' || *bol == comment_line_char) { item->command = TODO_COMMENT; item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = eol - bol; return 0; } @@ -2041,7 +2047,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, return error(_("%s does not accept arguments: '%s'"), command_to_string(item->command), bol); item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = eol - bol; return 0; } @@ -2053,7 +2059,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, if (item->command == TODO_EXEC || item->command == TODO_LABEL || item->command == TODO_RESET) { item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = (int)(eol - bol); return 0; } @@ -2067,7 +2073,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, } else { item->flags |= TODO_EDIT_MERGE_MSG; item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = (int)(eol - bol); return 0; } @@ -2079,8 +2085,9 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, status = get_oid(bol, &commit_oid); *end_of_object_name = saved; - item->arg = end_of_object_name + strspn(end_of_object_name, " \t"); - item->arg_len = (int)(eol - item->arg); + bol = end_of_object_name + strspn(end_of_object_name, " \t"); + item->arg_offset = bol - buf; + item->arg_len = (int)(eol - bol); if (status < 0) return -1; @@ -2108,11 +2115,11 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf, item = append_new_todo(todo_list); item->offset_in_buf = p - todo_list->buf.buf; - if (parse_insn_line(r, item, p, eol)) { + if (parse_insn_line(r, item, buf, p, eol)) { res = error(_("invalid line %d: %.*s"), i, (int)(eol - p), p); item->command = TODO_COMMENT + 1; - item->arg = p; + item->arg_offset = p - buf; item->arg_len = (int)(eol - p); item->commit = NULL; } @@ -2452,7 +2459,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list, item->command = command; item->commit = commit; - item->arg = NULL; + item->arg_offset = 0; item->arg_len = 0; item->offset_in_buf = todo_list->buf.len; subject_len = find_commit_subject(commit_buffer, &subject); @@ -3491,6 +3498,8 @@ static int pick_commits(struct repository *r, while (todo_list->current < todo_list->nr) { struct todo_item *item = todo_list->items + todo_list->current; + const char *arg = todo_item_get_arg(todo_list, item); + if (save_todo(todo_list, opts)) return -1; if (is_rebase_i(opts)) { @@ -3542,10 +3551,9 @@ static int pick_commits(struct repository *r, fprintf(stderr, _("Stopped at %s... %.*s\n"), short_commit_name(commit), - item->arg_len, item->arg); + item->arg_len, arg); return error_with_patch(r, commit, - item->arg, item->arg_len, opts, res, - !res); + arg, item->arg_len, opts, res, !res); } if (is_rebase_i(opts) && !res) record_in_rewritten(&item->commit->object.oid, @@ -3554,7 +3562,7 @@ static int pick_commits(struct repository *r, if (res == 1) intend_to_amend(); return error_failed_squash(r, item->commit, opts, - item->arg_len, item->arg); + item->arg_len, arg); } else if (res && is_rebase_i(opts) && item->commit) { int to_amend = 0; struct object_id oid; @@ -3573,16 +3581,16 @@ static int pick_commits(struct repository *r, to_amend = 1; return res | error_with_patch(r, item->commit, - item->arg, item->arg_len, opts, + arg, item->arg_len, opts, res, to_amend); } } else if (item->command == TODO_EXEC) { - char *end_of_arg = (char *)(item->arg + item->arg_len); + char *end_of_arg = (char *)(arg + item->arg_len); int saved = *end_of_arg; struct stat st; *end_of_arg = '\0'; - res = do_exec(r, item->arg); + res = do_exec(r, arg); *end_of_arg = saved; /* Reread the todo file if it has changed. */ @@ -3599,14 +3607,14 @@ static int pick_commits(struct repository *r, todo_list->current = -1; } } else if (item->command == TODO_LABEL) { - if ((res = do_label(r, item->arg, item->arg_len))) + if ((res = do_label(r, arg, item->arg_len))) reschedule = 1; } else if (item->command == TODO_RESET) { - if ((res = do_reset(r, item->arg, item->arg_len, opts))) + if ((res = do_reset(r, arg, item->arg_len, opts))) reschedule = 1; } else if (item->command == TODO_MERGE) { if ((res = do_merge(r, item->commit, - item->arg, item->arg_len, + arg, item->arg_len, item->flags, opts)) < 0) reschedule = 1; else if (item->commit) @@ -3615,9 +3623,8 @@ static int pick_commits(struct repository *r, if (res > 0) /* failed with merge conflicts */ return error_with_patch(r, item->commit, - item->arg, - item->arg_len, opts, - res, 0); + arg, item->arg_len, + opts, res, 0); } else if (!is_noop(item->command)) return error(_("unknown command %d"), item->command); @@ -3632,9 +3639,8 @@ static int pick_commits(struct repository *r, if (item->commit) return error_with_patch(r, item->commit, - item->arg, - item->arg_len, opts, - res, 0); + arg, item->arg_len, + opts, res, 0); } todo_list->current++; @@ -4575,7 +4581,8 @@ int transform_todos(struct repository *r, unsigned flags) for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { - strbuf_addf(&buf, "%.*s\n", item->arg_len, item->arg); + strbuf_addf(&buf, "%.*s\n", item->arg_len, + todo_item_get_arg(&todo_list, item)); continue; } @@ -4605,7 +4612,8 @@ int transform_todos(struct repository *r, unsigned flags) if (!item->arg_len) strbuf_addch(&buf, '\n'); else - strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg); + strbuf_addf(&buf, " %.*s\n", item->arg_len, + todo_item_get_arg(&todo_list, item)); } i = write_message(buf.buf, buf.len, todo_file, 0); @@ -4681,7 +4689,8 @@ int check_todo_list(struct repository *r) if (commit && !*commit_seen_at(&commit_seen, commit)) { strbuf_addf(&missing, " - %s %.*s\n", short_commit_name(commit), - item->arg_len, item->arg); + item->arg_len, + todo_item_get_arg(&todo_list, item)); *commit_seen_at(&commit_seen, commit) = 1; } } diff --git a/sequencer.h b/sequencer.h index c6360bac66..50d552429c 100644 --- a/sequencer.h +++ b/sequencer.h @@ -104,9 +104,9 @@ struct todo_item { enum todo_command command; struct commit *commit; unsigned int flags; - const char *arg; int arg_len; - size_t offset_in_buf; + /* The offset of the command and its argument in the strbuf */ + size_t offset_in_buf, arg_offset; }; struct todo_list { @@ -122,6 +122,8 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); void todo_list_release(struct todo_list *todo_list); +const char *todo_item_get_arg(struct todo_list *todo_list, + struct todo_item *item); /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); From patchwork Sun Feb 10 13:26:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804775 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 F122B746 for ; Sun, 10 Feb 2019 13:27:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E153D29F76 for ; Sun, 10 Feb 2019 13:27:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D516829F91; Sun, 10 Feb 2019 13:27:18 +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 9402A29F91 for ; Sun, 10 Feb 2019 13:27:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726231AbfBJN1O (ORCPT ); Sun, 10 Feb 2019 08:27:14 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35997 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbfBJN1N (ORCPT ); Sun, 10 Feb 2019 08:27:13 -0500 Received: by mail-wm1-f65.google.com with SMTP id p6so11761413wmc.1 for ; Sun, 10 Feb 2019 05:27:12 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=1RmveoYqh5IyIZIv6ifYtPLwFuHxBd5ZqU/8w7NqSMo=; b=SFDPElAXSeNqjrsFLcXKwiPQtUZpjl0yXG7cTLwdBds7IIBtVLK9LhZLttVpWT0qEg E7FDyOm7STy1KiYXrSM1ad3em+EV4yr2cK6zixSLshR8JmGJJ+ezxCUQ9RurcC9tkSEd gxdX+Dt7C2jkNnh8vc8SVPZbjR6tur8TCaQLsvsBCoUV+RmfODB63QmwSCW2XeDLSaDL bNsmJHAk6dQRF2KKCfkaD0aqq4HNb2Vj63Hz2ERqDBVQxyLzuGyHzRbBdZYBV8V+Wx70 J96aVDgFWhHl5dSASVlwAvff7SFg6D/cJkN173QV4v4PxU1H5v7B/D+8BFKilUQURt61 EtKg== 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:mime-version:content-transfer-encoding; bh=1RmveoYqh5IyIZIv6ifYtPLwFuHxBd5ZqU/8w7NqSMo=; b=tWP2wlu750DvDuuR2iRphdSdXeltE5IQ6UueJQ0ksjDVy3x7hh/zG7piHJbKZe/7BF 7h4euFPSibw1GkgIuosPYUZVsjm45tABkFh82DFMGdb6mW/qdOmFS2infyKBdj4lCJ3Z HKrG9JmeyYmf3LdDVN7Km/aCcbzNRyzukAM0t33whu1/UZAXK8Cxl0kSxGfjoIdp1pk9 lT5rl8aaWXkRiSSer7W0/6kmcUQv09m96YhdQEp3bHW/6mzuc75KSOes418tA2EIlq4F MGfN3jxzMCoEPTIU04fPBvcC0Jz5aW3FjaM0XJOC4XYlTaZEO4cCyMG9G7LdXNCdhAKa Cjrw== X-Gm-Message-State: AHQUAuZ9/zn3XqLRkrWxWBZy+pV4mqDajqTsG9FjhKf2v93mrCIrFua7 kv556rlJSuo87CfHcZ2sqBBmZx+g X-Google-Smtp-Source: AHgI3IYjAfP7OdKDAaDPPcdCNGmOSZTvZb3uc99TS/5cjcIn0nckx1M0RNy1CcqQRKmXoxpTUzqWaQ== X-Received: by 2002:a1c:c181:: with SMTP id r123mr5704694wmf.8.1549805231017; Sun, 10 Feb 2019 05:27:11 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:10 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 04/16] sequencer: refactor transform_todos() to work on a todo_list Date: Sun, 10 Feb 2019 14:26:36 +0100 Message-Id: <20190210132648.12821-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This refactors transform_todos() to work on a todo_list. The function is renamed todo_list_transform(). As rebase -p still need to check the todo list from the disk, a new function is introduced, transform_todo_file(). It is still used by complete_action() and edit_todo_list() for now, but they will be replaced in a future commit. todo_list_transform() is not a static function, because it will be used by edit_todo_list() from rebase-interactive.c in a future commit. Signed-off-by: Alban Gruin --- No changes since v6. builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 4 +-- sequencer.c | 54 +++++++++++++++++++++++------------ sequencer.h | 4 ++- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index dd2a55ab1d..0898eb4c59 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -253,7 +253,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) } case SHORTEN_OIDS: case EXPAND_OIDS: - ret = transform_todos(the_repository, flags); + ret = transform_todo_file(the_repository, flags); break; case CHECK_TODO_LIST: ret = check_todo_list(the_repository); diff --git a/rebase-interactive.c b/rebase-interactive.c index 68aff1dac2..842fa07e7e 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -69,7 +69,7 @@ int edit_todo_list(struct repository *r, unsigned flags) strbuf_release(&buf); - transform_todos(r, flags | TODO_LIST_SHORTEN_IDS); + transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS); if (strbuf_read_file(&buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); @@ -85,7 +85,7 @@ int edit_todo_list(struct repository *r, unsigned flags) if (launch_sequence_editor(todo_file, NULL, NULL)) return -1; - transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS)); + transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS)); return 0; } diff --git a/sequencer.c b/sequencer.c index c844a9b7f3..346706029c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4562,27 +4562,18 @@ int sequencer_add_exec_commands(struct repository *r, return i; } -int transform_todos(struct repository *r, unsigned flags) +void todo_list_transform(struct repository *r, struct todo_list *todo_list, + unsigned flags) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; struct strbuf buf = STRBUF_INIT; struct todo_item *item; int i; - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) { + for (item = todo_list->items, i = 0; i < todo_list->nr; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { strbuf_addf(&buf, "%.*s\n", item->arg_len, - todo_item_get_arg(&todo_list, item)); + todo_item_get_arg(todo_list, item)); continue; } @@ -4613,12 +4604,39 @@ int transform_todos(struct repository *r, unsigned flags) strbuf_addch(&buf, '\n'); else strbuf_addf(&buf, " %.*s\n", item->arg_len, - todo_item_get_arg(&todo_list, item)); + todo_item_get_arg(todo_list, item)); } - i = write_message(buf.buf, buf.len, todo_file, 0); + strbuf_reset(&todo_list->buf); + strbuf_add(&todo_list->buf, buf.buf, buf.len); + strbuf_release(&buf); + + if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list)) + BUG("unusable todo list"); +} + +int transform_todo_file(struct repository *r, unsigned flags) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_transform(r, &todo_list, flags); + + res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); todo_list_release(&todo_list); - return i; + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } enum missing_commit_check_level get_missing_commit_check_level(void) @@ -4880,7 +4898,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return error(_("could not copy '%s' to '%s'."), todo_file, rebase_path_todo_backup()); - if (transform_todos(r, flags | TODO_LIST_SHORTEN_IDS)) + if (transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS)) return error(_("could not transform the todo list")); strbuf_reset(buf); @@ -4909,7 +4927,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return -1; } - if (transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS))) + if (transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS))) return error(_("could not transform the todo list")); if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) diff --git a/sequencer.h b/sequencer.h index 50d552429c..2ddb20cbc1 100644 --- a/sequencer.h +++ b/sequencer.h @@ -121,6 +121,8 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); +void todo_list_transform(struct repository *r, struct todo_list *todo_list, + unsigned flags); void todo_list_release(struct todo_list *todo_list); const char *todo_item_get_arg(struct todo_list *todo_list, struct todo_item *item); @@ -148,7 +150,7 @@ int sequencer_make_script(struct repository *repo, FILE *out, unsigned flags); int sequencer_add_exec_commands(struct repository *r, const char *command); -int transform_todos(struct repository *r, unsigned flags); +int transform_todo_file(struct repository *r, unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, From patchwork Sun Feb 10 13:26:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804779 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 40BB91515 for ; Sun, 10 Feb 2019 13:27:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3094529F76 for ; Sun, 10 Feb 2019 13:27:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 251FF29F95; Sun, 10 Feb 2019 13:27:21 +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 8D73629F91 for ; Sun, 10 Feb 2019 13:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726300AbfBJN1T (ORCPT ); Sun, 10 Feb 2019 08:27:19 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39734 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfBJN1P (ORCPT ); Sun, 10 Feb 2019 08:27:15 -0500 Received: by mail-wm1-f68.google.com with SMTP id f16so11803071wmh.4 for ; Sun, 10 Feb 2019 05:27:13 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=ypvarG23z6LsE+bVjri92/lC3x2Q8MHCustBK1rP8kk=; b=tzaiAigMNUqflIhzpxhmEtzCrF5shFTHdCatHde/SE/i+ICvbgtOZcWDzq3i09zxHn lnxxiwTK9CjCTMT+5FuabiH9wpT43m/MEvAK+vUFzlkBPIpTyUX4fPu3ZshR/ZjIEjCI CJG1vawuxBOH2RwPqZIg2pGB6dMfT80HWD65hBGcgZ7fM+Mql08889maU9wuBU42KiA9 EIxlLIl0xcXAwVJqaTZxj/lDJ9MgMEs/0bqypMxQzE02NaLtmepqLSzrRpZXE9wpwflN o82yU7F1B0zCJYudgjYE7b+h8TMyn09AbjdZJasHY++NkS9ah4fwZy8vxUtnVH9wtptZ dCVw== 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:mime-version:content-transfer-encoding; bh=ypvarG23z6LsE+bVjri92/lC3x2Q8MHCustBK1rP8kk=; b=PPVVGlrjyjCsyvb6p/QrBV/2/QeX3NEffF9uUathn2tDEqE+tkpBfWwRI1mg58sow2 qQDpbFUUmHhXKj+Sx+MT3jtWhvaA69LlDZZLXvUDmtPVF5oEbHMO0BWrqd7N+J3ES88N rLACZzkGQuT0am5LJX7QWNmhkR8t42jnYs6QAq8zqKn61gtdoe45G1gEIkYDufUw70NM GR9mNrdhg+9XBSe0M0tBpg3OPC292tApzUYjtxCb0QI9NE1W5kOS7qaOyTKHdWT3Oe48 rriEYhbKy/c7lyLrnthMlBiiVd+CHUpm83AUZjY7e++6aQlBHls8KQAepXfn+EUQfonp FyGA== X-Gm-Message-State: AHQUAuaTLxAqaS4Tf1BlMJ2lfYMfKU2u3H9KTLiLhq08OGnuOe9Z9jSC dyCFaFFaCTykqaVFniYGuG6sfl2m X-Google-Smtp-Source: AHgI3IZsR6gnr2qG2v9myv8TsOpUQAgst6WLbphSgUf52xmNL8djlBJUNTAGRIDPLrI/lK55GylSGw== X-Received: by 2002:a1c:f919:: with SMTP id x25mr5847225wmh.61.1549805232339; Sun, 10 Feb 2019 05:27:12 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:11 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 05/16] sequencer: introduce todo_list_write_to_file() Date: Sun, 10 Feb 2019 14:26:37 +0100 Message-Id: <20190210132648.12821-6-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This introduces a new function to recreate the text of a todo list from its commands and write it to a file. This will be useful as the next few commits will change the use of the buffer in struct todo_list so it will no longer be a mirror of the file on disk. This functionality already exists in todo_list_transform(), but this function was made to replace the buffer of a todo list, which is not what we want here. Thus, the part of todo_list_transform() that replaces the buffer is dropped, and the function is renamed todo_list_to_strbuf(). It is called by todo_list_write_to_file() to fill the buffer to write to the disk. todo_list_write_to_file() can also take care of appending the help text to the buffer before writing it to the disk, or to write only the first n items of the list. This feature will be used by skip_unnecessary_picks(), which has to write done commands in a file. Signed-off-by: Alban Gruin --- No changes since v6. sequencer.c | 61 +++++++++++++++++++++++++++++++++++------------------ sequencer.h | 11 ++++++---- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/sequencer.c b/sequencer.c index 346706029c..4809b22ce4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4562,26 +4562,28 @@ int sequencer_add_exec_commands(struct repository *r, return i; } -void todo_list_transform(struct repository *r, struct todo_list *todo_list, - unsigned flags) +static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list, + struct strbuf *buf, int num, unsigned flags) { - struct strbuf buf = STRBUF_INIT; struct todo_item *item; - int i; + int i, max = todo_list->nr; - for (item = todo_list->items, i = 0; i < todo_list->nr; i++, item++) { + if (num > 0 && num < max) + max = num; + + for (item = todo_list->items, i = 0; i < max; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { - strbuf_addf(&buf, "%.*s\n", item->arg_len, + strbuf_addf(buf, "%.*s\n", item->arg_len, todo_item_get_arg(todo_list, item)); continue; } /* add command to the buffer */ if (flags & TODO_LIST_ABBREVIATE_CMDS) - strbuf_addch(&buf, command_to_char(item->command)); + strbuf_addch(buf, command_to_char(item->command)); else - strbuf_addstr(&buf, command_to_string(item->command)); + strbuf_addstr(buf, command_to_string(item->command)); /* add commit id */ if (item->commit) { @@ -4591,28 +4593,48 @@ void todo_list_transform(struct repository *r, struct todo_list *todo_list, if (item->command == TODO_MERGE) { if (item->flags & TODO_EDIT_MERGE_MSG) - strbuf_addstr(&buf, " -c"); + strbuf_addstr(buf, " -c"); else - strbuf_addstr(&buf, " -C"); + strbuf_addstr(buf, " -C"); } - strbuf_addf(&buf, " %s", oid); + strbuf_addf(buf, " %s", oid); } /* add all the rest */ if (!item->arg_len) - strbuf_addch(&buf, '\n'); + strbuf_addch(buf, '\n'); else - strbuf_addf(&buf, " %.*s\n", item->arg_len, + strbuf_addf(buf, " %.*s\n", item->arg_len, todo_item_get_arg(todo_list, item)); } +} - strbuf_reset(&todo_list->buf); - strbuf_add(&todo_list->buf, buf.buf, buf.len); +int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, + const char *file, const char *shortrevisions, + const char *shortonto, int num, unsigned flags) +{ + int edit_todo = !(shortrevisions && shortonto), res; + struct strbuf buf = STRBUF_INIT; + + todo_list_to_strbuf(r, todo_list, &buf, num, flags); + + if (flags & TODO_LIST_APPEND_TODO_HELP) { + int command_count = count_commands(todo_list); + if (!edit_todo) { + strbuf_addch(&buf, '\n'); + strbuf_commented_addf(&buf, Q_("Rebase %s onto %s (%d command)", + "Rebase %s onto %s (%d commands)", + command_count), + shortrevisions, shortonto, command_count); + } + append_todo_help(edit_todo, flags & TODO_LIST_KEEP_EMPTY, &buf); + } + + res = write_message(buf.buf, buf.len, file, 0); strbuf_release(&buf); - if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list)) - BUG("unusable todo list"); + return res; } int transform_todo_file(struct repository *r, unsigned flags) @@ -4629,9 +4651,8 @@ int transform_todo_file(struct repository *r, unsigned flags) return error(_("unusable todo list: '%s'"), todo_file); } - todo_list_transform(r, &todo_list, flags); - - res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); + res = todo_list_write_to_file(r, &todo_list, todo_file, + NULL, NULL, -1, flags); todo_list_release(&todo_list); if (res) diff --git a/sequencer.h b/sequencer.h index 2ddb20cbc1..7278f9675b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -121,8 +121,9 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); -void todo_list_transform(struct repository *r, struct todo_list *todo_list, - unsigned flags); +int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, + const char *file, const char *shortrevisions, + const char *shortonto, int num, unsigned flags); void todo_list_release(struct todo_list *todo_list); const char *todo_item_get_arg(struct todo_list *todo_list, struct todo_item *item); @@ -145,8 +146,10 @@ int sequencer_remove_state(struct replay_opts *opts); * commits should be rebased onto the new base, this flag needs to be passed. */ #define TODO_LIST_REBASE_COUSINS (1U << 4) -int sequencer_make_script(struct repository *repo, FILE *out, - int argc, const char **argv, +#define TODO_LIST_APPEND_TODO_HELP (1U << 5) + +int sequencer_make_script(struct repository *r, FILE *out, int argc, + const char **argv, unsigned flags); int sequencer_add_exec_commands(struct repository *r, const char *command); From patchwork Sun Feb 10 13:26:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804777 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 F211F14E1 for ; Sun, 10 Feb 2019 13:27:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E308929F76 for ; Sun, 10 Feb 2019 13:27:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D711229F96; Sun, 10 Feb 2019 13:27:20 +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 01DC529F76 for ; Sun, 10 Feb 2019 13:27:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726267AbfBJN1S (ORCPT ); Sun, 10 Feb 2019 08:27:18 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51961 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726220AbfBJN1R (ORCPT ); Sun, 10 Feb 2019 08:27:17 -0500 Received: by mail-wm1-f67.google.com with SMTP id b11so12228584wmj.1 for ; Sun, 10 Feb 2019 05:27:14 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=NEToLgcmjiglqk2mWo+fsniRux0BCHOiLYlC59fakIs=; b=dCsQELPwHRjIUGBwgUZ6UVLBwncIs4Dd56a3SKV1jUQAmEIPpoW6iNqJ3IgshVAmmr BvPPAb+Qk6yYxrQvCqat+sxnfsjpQfhYW2nUs4NQ6oFn+f9NPuglFIr/n+qT1sBi2ywY j+IR3HuUrs2UMplUP1z3QQxPtkiz1u16P3h4OcLMjsDTw2NLFPlE6XDbRdC07124YMVD aJxzdLmBlejSxKdQYfH0fQua4x0fgmseoVqAy6ylYbjR4GGn883AOh4VfQ2whF1qhDtZ XqrPH7XJaZfRr02UBI8uXpXwKQZtOt/hS/IowrkUJg9J8BmuTMaJbqzZpS49wSGs8IsS z6ow== 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:mime-version:content-transfer-encoding; bh=NEToLgcmjiglqk2mWo+fsniRux0BCHOiLYlC59fakIs=; b=I3NJJSCIGB/eyAbkJjjlcZbSzMq3fQSWP5fcmMla7+QqJQMnlSG2AUpFnkqeUK4av6 mfR6AcqOC8NZx3aX3aHPK9k8qGAQciZqgJYx3Azmr8jqiwV7CA6tuBpcvyoqUFOYYcPn vTwu2BApeYpgHL7dua00Au/zk1T1+ljWG7SNvYhuUnod2/DZO5hpQkEvuK7DQVfPNDgQ ikYLmIqY7SmflQN1I5bFy3NaSkG9Kuy7ig6wknVh/dbB6TBbJxHeA8xuRkwfpQORZu9I aQDWLIYLJDS3729FHTeM88BEFNjA0uF65T9hCOyFCgp3aPJy7hpc+jLNDabou3l8wEBS qBmw== X-Gm-Message-State: AHQUAuY1LadkjuxBxeReC/V9t8a8p9M/haCPci1zG6qDTITr9R78b6AN uf6SwjkjCz3Tes07nfS76kCodrnj X-Google-Smtp-Source: AHgI3IZSCEjr1KaE1V8cpytgodHvPr0v+2GTAtGMdcuG/U/0E/k9R2gSUqK4mZ/4NQAQP+NI0Ekt/Q== X-Received: by 2002:a05:600c:220b:: with SMTP id z11mr5661549wml.37.1549805233416; Sun, 10 Feb 2019 05:27:13 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:13 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 06/16] sequencer: refactor check_todo_list() to work on a todo_list Date: Sun, 10 Feb 2019 14:26:38 +0100 Message-Id: <20190210132648.12821-7-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This refactors check_todo_list() to work on a todo_list to avoid redundant reads and writes to the disk. The function is renamed todo_list_check(). The parsing of the two todo lists is left to the caller. As rebase -p still need to check the todo list from the disk, a new function is introduced, check_todo_list_from_file(). It reads the file from the disk, parses it, pass the todo_list to todo_list_check(), and writes it back to the disk. As get_missing_commit_check_level() and the enum missing_commit_check_level are no longer needed inside of sequencer.c, they are moved to rebase-interactive.c, and made static again. Signed-off-by: Alban Gruin --- No changes since v6. builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 91 ++++++++++++++++++++++++- rebase-interactive.h | 2 + sequencer.c | 121 +++++++--------------------------- sequencer.h | 9 +-- 5 files changed, 117 insertions(+), 108 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 0898eb4c59..df19ccaeb9 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -256,7 +256,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = transform_todo_file(the_repository, flags); break; case CHECK_TODO_LIST: - ret = check_todo_list(the_repository); + ret = check_todo_list_from_file(the_repository); break; case REARRANGE_SQUASH: ret = rearrange_squash(the_repository); diff --git a/rebase-interactive.c b/rebase-interactive.c index 842fa07e7e..dfa6dd530f 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -1,8 +1,32 @@ #include "cache.h" #include "commit.h" -#include "rebase-interactive.h" #include "sequencer.h" +#include "rebase-interactive.h" #include "strbuf.h" +#include "commit-slab.h" +#include "config.h" + +enum missing_commit_check_level { + MISSING_COMMIT_CHECK_IGNORE = 0, + MISSING_COMMIT_CHECK_WARN, + MISSING_COMMIT_CHECK_ERROR +}; + +static enum missing_commit_check_level get_missing_commit_check_level(void) +{ + const char *value; + + if (git_config_get_value("rebase.missingcommitscheck", &value) || + !strcasecmp("ignore", value)) + return MISSING_COMMIT_CHECK_IGNORE; + if (!strcasecmp("warn", value)) + return MISSING_COMMIT_CHECK_WARN; + if (!strcasecmp("error", value)) + return MISSING_COMMIT_CHECK_ERROR; + warning(_("unrecognized setting %s for option " + "rebase.missingCommitsCheck. Ignoring."), value); + return MISSING_COMMIT_CHECK_IGNORE; +} void append_todo_help(unsigned edit_todo, unsigned keep_empty, struct strbuf *buf) @@ -89,3 +113,68 @@ int edit_todo_list(struct repository *r, unsigned flags) return 0; } + +define_commit_slab(commit_seen, unsigned char); +/* + * Check if the user dropped some commits by mistake + * Behaviour determined by rebase.missingCommitsCheck. + * Check if there is an unrecognized command or a + * bad SHA-1 in a command. + */ +int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo) +{ + enum missing_commit_check_level check_level = get_missing_commit_check_level(); + struct strbuf missing = STRBUF_INIT; + int res = 0, i; + struct commit_seen commit_seen; + + init_commit_seen(&commit_seen); + + if (check_level == MISSING_COMMIT_CHECK_IGNORE) + goto leave_check; + + /* Mark the commits in git-rebase-todo as seen */ + for (i = 0; i < new_todo->nr; i++) { + struct commit *commit = new_todo->items[i].commit; + if (commit) + *commit_seen_at(&commit_seen, commit) = 1; + } + + /* Find commits in git-rebase-todo.backup yet unseen */ + for (i = old_todo->nr - 1; i >= 0; i--) { + struct todo_item *item = old_todo->items + i; + struct commit *commit = item->commit; + if (commit && !*commit_seen_at(&commit_seen, commit)) { + strbuf_addf(&missing, " - %s %.*s\n", + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), + item->arg_len, + todo_item_get_arg(old_todo, item)); + *commit_seen_at(&commit_seen, commit) = 1; + } + } + + /* Warn about missing commits */ + if (!missing.len) + goto leave_check; + + if (check_level == MISSING_COMMIT_CHECK_ERROR) + res = 1; + + fprintf(stderr, + _("Warning: some commits may have been dropped accidentally.\n" + "Dropped commits (newer to older):\n")); + + /* Make the list user-friendly and display */ + fputs(missing.buf, stderr); + strbuf_release(&missing); + + fprintf(stderr, _("To avoid this message, use \"drop\" to " + "explicitly remove a commit.\n\n" + "Use 'git config rebase.missingCommitsCheck' to change " + "the level of warnings.\n" + "The possible behaviours are: ignore, warn, error.\n\n")); + +leave_check: + clear_commit_seen(&commit_seen); + return res; +} diff --git a/rebase-interactive.h b/rebase-interactive.h index 17b6c9f6d0..187b5032d6 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -3,9 +3,11 @@ struct strbuf; struct repository; +struct todo_list; void append_todo_help(unsigned edit_todo, unsigned keep_empty, struct strbuf *buf); int edit_todo_list(struct repository *r, unsigned flags); +int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); #endif diff --git a/sequencer.c b/sequencer.c index 4809b22ce4..99e12c751e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4660,112 +4660,37 @@ int transform_todo_file(struct repository *r, unsigned flags) return 0; } -enum missing_commit_check_level get_missing_commit_check_level(void) -{ - const char *value; - - if (git_config_get_value("rebase.missingcommitscheck", &value) || - !strcasecmp("ignore", value)) - return MISSING_COMMIT_CHECK_IGNORE; - if (!strcasecmp("warn", value)) - return MISSING_COMMIT_CHECK_WARN; - if (!strcasecmp("error", value)) - return MISSING_COMMIT_CHECK_ERROR; - warning(_("unrecognized setting %s for option " - "rebase.missingCommitsCheck. Ignoring."), value); - return MISSING_COMMIT_CHECK_IGNORE; -} +static const char edit_todo_list_advice[] = +N_("You can fix this with 'git rebase --edit-todo' " +"and then run 'git rebase --continue'.\n" +"Or you can abort the rebase with 'git rebase" +" --abort'.\n"); -define_commit_slab(commit_seen, unsigned char); -/* - * Check if the user dropped some commits by mistake - * Behaviour determined by rebase.missingCommitsCheck. - * Check if there is an unrecognized command or a - * bad SHA-1 in a command. - */ -int check_todo_list(struct repository *r) +int check_todo_list_from_file(struct repository *r) { - enum missing_commit_check_level check_level = get_missing_commit_check_level(); - struct strbuf todo_file = STRBUF_INIT; - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf missing = STRBUF_INIT; - int advise_to_edit_todo = 0, res = 0, i; - struct commit_seen commit_seen; - - init_commit_seen(&commit_seen); + struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT; + int res = 0; - strbuf_addstr(&todo_file, rebase_path_todo()); - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file.buf) < 0) { + if (strbuf_read_file_or_whine(&new_todo.buf, rebase_path_todo()) < 0) { res = -1; - goto leave_check; - } - advise_to_edit_todo = res = - todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - - if (res || check_level == MISSING_COMMIT_CHECK_IGNORE) - goto leave_check; - - /* Mark the commits in git-rebase-todo as seen */ - for (i = 0; i < todo_list.nr; i++) { - struct commit *commit = todo_list.items[i].commit; - if (commit) - *commit_seen_at(&commit_seen, commit) = 1; + goto out; } - todo_list_release(&todo_list); - strbuf_addstr(&todo_file, ".backup"); - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file.buf) < 0) { + if (strbuf_read_file_or_whine(&old_todo.buf, rebase_path_todo_backup()) < 0) { res = -1; - goto leave_check; - } - strbuf_release(&todo_file); - res = !!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - - /* Find commits in git-rebase-todo.backup yet unseen */ - for (i = todo_list.nr - 1; i >= 0; i--) { - struct todo_item *item = todo_list.items + i; - struct commit *commit = item->commit; - if (commit && !*commit_seen_at(&commit_seen, commit)) { - strbuf_addf(&missing, " - %s %.*s\n", - short_commit_name(commit), - item->arg_len, - todo_item_get_arg(&todo_list, item)); - *commit_seen_at(&commit_seen, commit) = 1; - } + goto out; } - /* Warn about missing commits */ - if (!missing.len) - goto leave_check; - - if (check_level == MISSING_COMMIT_CHECK_ERROR) - advise_to_edit_todo = res = 1; - - fprintf(stderr, - _("Warning: some commits may have been dropped accidentally.\n" - "Dropped commits (newer to older):\n")); - - /* Make the list user-friendly and display */ - fputs(missing.buf, stderr); - strbuf_release(&missing); - - fprintf(stderr, _("To avoid this message, use \"drop\" to " - "explicitly remove a commit.\n\n" - "Use 'git config rebase.missingCommitsCheck' to change " - "the level of warnings.\n" - "The possible behaviours are: ignore, warn, error.\n\n")); - -leave_check: - clear_commit_seen(&commit_seen); - strbuf_release(&todo_file); - todo_list_release(&todo_list); - - if (advise_to_edit_todo) - fprintf(stderr, - _("You can fix this with 'git rebase --edit-todo' " - "and then run 'git rebase --continue'.\n" - "Or you can abort the rebase with 'git rebase" - " --abort'.\n")); + res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo); + if (!res) + res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo); + if (!res) + res = todo_list_check(&old_todo, &new_todo); + if (res) + fprintf(stderr, _(edit_todo_list_advice)); +out: + todo_list_release(&old_todo); + todo_list_release(&new_todo); return res; } @@ -4943,7 +4868,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla todo_list_release(&todo_list); - if (check_todo_list(r)) { + if (check_todo_list_from_file(r)) { checkout_onto(opts, onto_name, onto, orig_head); return -1; } diff --git a/sequencer.h b/sequencer.h index 7278f9675b..217353e9f0 100644 --- a/sequencer.h +++ b/sequencer.h @@ -64,12 +64,6 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } -enum missing_commit_check_level { - MISSING_COMMIT_CHECK_IGNORE = 0, - MISSING_COMMIT_CHECK_WARN, - MISSING_COMMIT_CHECK_ERROR -}; - int write_message(const void *buf, size_t len, const char *filename, int append_eol); @@ -154,8 +148,7 @@ int sequencer_make_script(struct repository *r, FILE *out, int argc, int sequencer_add_exec_commands(struct repository *r, const char *command); int transform_todo_file(struct repository *r, unsigned flags); -enum missing_commit_check_level get_missing_commit_check_level(void); -int check_todo_list(struct repository *r); +int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, const char *cmd, From patchwork Sun Feb 10 13:26:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804781 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 51336746 for ; Sun, 10 Feb 2019 13:27:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41EF229F76 for ; Sun, 10 Feb 2019 13:27:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3673329F95; Sun, 10 Feb 2019 13:27:23 +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 6A12929F76 for ; Sun, 10 Feb 2019 13:27:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726244AbfBJN1S (ORCPT ); Sun, 10 Feb 2019 08:27:18 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37649 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbfBJN1R (ORCPT ); Sun, 10 Feb 2019 08:27:17 -0500 Received: by mail-wm1-f65.google.com with SMTP id x10so6469542wmg.2 for ; Sun, 10 Feb 2019 05:27:15 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=5sFUFdeqb4GrxQbCPKvPcWsb/66BdY8rctjkjoU987E=; b=eM4C8ARzriFoIXAPecLIt+xcpv6zBulvlxHzdAZpkMOLJDzCStP4ipIQQIHs1qkQ8n YBwGWeRtfiT+10DcidEmy2mz1geH42yQaNhfmunjaBXkMmjDcu3WCAgbOJCgBoxFd3vE RF4wW56XPkTRnp5MO1j2uyfFMvmac5nU6oq6eipY2IVuzKNvUZJeh+hw1SAOdzNJK0Fu BTrFQMKrwOLOthgjFI/ntsEstjX92PxWYxYtJAn4+ytPBlpS2dShcKgdQuGxOAiabpO7 IK7RRMzDF5L+kfvBUQMmYrO3x26myJtwT8luAlqWZrK5FYA44BdSj+AG9gxsCO2fFJQI QshQ== 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:mime-version:content-transfer-encoding; bh=5sFUFdeqb4GrxQbCPKvPcWsb/66BdY8rctjkjoU987E=; b=goY5XLPU1Q+REIQEEvXyAGAAFrdXRpg+mpIeBnsrpzyJ7X7ZJ03qlKsQkBaid3HASY USnG5dYlwzbiUyoj/axcdvJbDmUwhiUq6wuRWMXnz8HYFzsnrosFiyYR46KY0eT8DTkY 83PaPYgmd3WCcL+t0kO4oMeF3i/G6iRHEt7R6sV9AAaaR9G4PjLKIA2ZVimuQrnZp1Dw BiPKs7Z3NHnU2rgm1B0pppJbCJbRXRpm9f3OZfnNKiLy1rz8IlvWQpuEG5Qo3p2mYql4 Fmq8KQL6tjHuO5jpkPYv6Cbs9NObMhY0jH6hFwz7qBFbNluYg72f5kGQxg1cM7Z7IJby BcGg== X-Gm-Message-State: AHQUAuYojzanJakI6C8qWIF3QVjYdou6NEeS6KLbTDQ10g6hSvZpGfrK IfMQh89YqnoGzRgd9cpmkN7vz8Jh X-Google-Smtp-Source: AHgI3IY95QCY64+Hj6pWIUJ8BiEDEbr0pb865Ck1qoPsViQ+xVKxAJKC0Jx4tlWPxsqAAQODFnw5sg== X-Received: by 2002:a1c:7c07:: with SMTP id x7mr5907141wmc.82.1549805234486; Sun, 10 Feb 2019 05:27:14 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:14 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 07/16] sequencer: refactor sequencer_add_exec_commands() to work on a todo_list Date: Sun, 10 Feb 2019 14:26:39 +0100 Message-Id: <20190210132648.12821-8-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This refactors sequencer_add_exec_commands() to work on a todo_list to avoid redundant reads and writes to the disk. Instead of inserting the `exec' commands between the other commands and re-parsing the buffer at the end, they are appended to the buffer once, and a new list of items is created. Items from the old list are copied across and new `exec' items are appended when necessary. This eliminates the need to reparse the buffer, but this also means we have to use todo_list_write_to_disk() to write the file. todo_list_add_exec_commands() and sequencer_add_exec_commands() are modified to take a string list instead of a string -- one item for each command. This makes it easier to insert a new command to the todo list for each command to execute. sequencer_add_exec_commands() still reads the todo list from the disk, as it is needed by rebase -p. complete_action() still uses sequencer_add_exec_commands() for now. This will be changed in a future commit. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 15 +++-- sequencer.c | 109 +++++++++++++++++++++------------- sequencer.h | 5 +- 3 files changed, 82 insertions(+), 47 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index df19ccaeb9..c131fd4a27 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -65,7 +65,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *onto, const char *onto_name, const char *squash_onto, const char *head_name, const char *restrict_revision, char *raw_strategies, - const char *cmd, unsigned autosquash) + struct string_list *commands, unsigned autosquash) { int ret; const char *head_hash = NULL; @@ -116,7 +116,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, discard_cache(); ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name, onto, - head_hash, cmd, autosquash); + head_hash, commands, autosquash); } free(revisions); @@ -139,6 +139,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) const char *onto = NULL, *onto_name = NULL, *restrict_revision = NULL, *squash_onto = NULL, *upstream = NULL, *head_name = NULL, *switch_to = NULL, *cmd = NULL; + struct string_list commands = STRING_LIST_INIT_DUP; char *raw_strategies = NULL; enum { NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH, @@ -221,6 +222,11 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) warning(_("--[no-]rebase-cousins has no effect without " "--rebase-merges")); + if (cmd && *cmd) { + string_list_split(&commands, cmd, '\n', -1); + --commands.nr; + } + switch (command) { case NONE: if (!onto && !upstream) @@ -228,7 +234,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto, onto_name, squash_onto, head_name, restrict_revision, - raw_strategies, cmd, autosquash); + raw_strategies, &commands, autosquash); break; case SKIP: { struct string_list merge_rr = STRING_LIST_INIT_DUP; @@ -262,11 +268,12 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = rearrange_squash(the_repository); break; case ADD_EXEC: - ret = sequencer_add_exec_commands(the_repository, cmd); + ret = sequencer_add_exec_commands(the_repository, &commands); break; default: BUG("invalid command '%d'", command); } + string_list_clear(&commands, 1); return !!ret; } diff --git a/sequencer.c b/sequencer.c index 99e12c751e..82ca3432cd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4505,21 +4505,27 @@ int sequencer_make_script(struct repository *r, FILE *out, * Add commands after pick and (series of) squash/fixup commands * in the todo list. */ -int sequencer_add_exec_commands(struct repository *r, - const char *commands) +static void todo_list_add_exec_commands(struct todo_list *todo_list, + struct string_list *commands) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf *buf = &todo_list.buf; - size_t offset = 0, commands_len = strlen(commands); - int i, insert; + struct strbuf *buf = &todo_list->buf; + size_t base_offset = buf->len; + int i, insert, nr = 0, alloc = 0; + struct todo_item *items = NULL, *base_items = NULL; - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); + base_items = xcalloc(commands->nr, sizeof(struct todo_item)); + for (i = 0; i < commands->nr; i++) { + size_t command_len = strlen(commands->items[i].string); - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); + strbuf_addstr(buf, commands->items[i].string); + strbuf_addch(buf, '\n'); + + base_items[i].command = TODO_EXEC; + base_items[i].offset_in_buf = base_offset; + base_items[i].arg_offset = base_offset + strlen("exec "); + base_items[i].arg_len = command_len - strlen("exec "); + + base_offset += command_len + 1; } /* @@ -4527,39 +4533,60 @@ int sequencer_add_exec_commands(struct repository *r, * are considered part of the pick, so we insert the commands *after* * those chains if there are any. */ - insert = -1; - for (i = 0; i < todo_list.nr; i++) { - enum todo_command command = todo_list.items[i].command; - - if (insert >= 0) { - /* skip fixup/squash chains */ - if (command == TODO_COMMENT) - continue; - else if (is_fixup(command)) { - insert = i + 1; - continue; - } - strbuf_insert(buf, - todo_list.items[insert].offset_in_buf + - offset, commands, commands_len); - offset += commands_len; - insert = -1; + insert = 0; + for (i = 0; i < todo_list->nr; i++) { + enum todo_command command = todo_list->items[i].command; + if (insert && !is_fixup(command)) { + ALLOC_GROW(items, nr + commands->nr, alloc); + COPY_ARRAY(items + nr, base_items, commands->nr); + nr += commands->nr; + + insert = 0; } - if (command == TODO_PICK || command == TODO_MERGE) - insert = i + 1; + ALLOC_GROW(items, nr + 1, alloc); + items[nr++] = todo_list->items[i]; + + if (command == TODO_PICK || command == TODO_MERGE || is_fixup(command)) + insert = 1; } /* insert or append final */ - if (insert >= 0 && insert < todo_list.nr) - strbuf_insert(buf, todo_list.items[insert].offset_in_buf + - offset, commands, commands_len); - else if (insert >= 0 || !offset) - strbuf_add(buf, commands, commands_len); + if (insert || nr == todo_list->nr) { + ALLOC_GROW(items, nr + commands->nr, alloc); + COPY_ARRAY(items + nr, base_items, commands->nr); + nr += commands->nr; + } + + free(base_items); + FREE_AND_NULL(todo_list->items); + todo_list->items = items; + todo_list->nr = nr; + todo_list->alloc = alloc; +} - i = write_message(buf->buf, buf->len, todo_file, 0); +int sequencer_add_exec_commands(struct repository *r, + struct string_list *commands) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_add_exec_commands(&todo_list, commands); + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); todo_list_release(&todo_list); - return i; + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list, @@ -4790,7 +4817,7 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - const char *onto, const char *orig_head, const char *cmd, + const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash) { const char *shortonto, *todo_file = rebase_path_todo(); @@ -4809,8 +4836,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (autosquash && rearrange_squash(r)) return -1; - if (cmd && *cmd) - sequencer_add_exec_commands(r, cmd); + if (commands->nr) + sequencer_add_exec_commands(r, commands); if (strbuf_read_file(buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); diff --git a/sequencer.h b/sequencer.h index 217353e9f0..87d04a3b9b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -146,12 +146,13 @@ int sequencer_make_script(struct repository *r, FILE *out, int argc, const char **argv, unsigned flags); -int sequencer_add_exec_commands(struct repository *r, const char *command); +int sequencer_add_exec_commands(struct repository *r, + struct string_list *commands); int transform_todo_file(struct repository *r, unsigned flags); int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - const char *onto, const char *orig_head, const char *cmd, + const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash); int rearrange_squash(struct repository *r); From patchwork Sun Feb 10 13:26:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804787 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 6FC7A746 for ; Sun, 10 Feb 2019 13:27:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6034229F76 for ; Sun, 10 Feb 2019 13:27:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C2529F95; Sun, 10 Feb 2019 13:27:27 +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 B07B929F76 for ; Sun, 10 Feb 2019 13:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726340AbfBJN1W (ORCPT ); Sun, 10 Feb 2019 08:27:22 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36004 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbfBJN1S (ORCPT ); Sun, 10 Feb 2019 08:27:18 -0500 Received: by mail-wm1-f66.google.com with SMTP id p6so11761622wmc.1 for ; Sun, 10 Feb 2019 05:27:16 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=cmySRFzqSA2TlNGJUsvn+SuA2Sf+KVeqMGpgq3KXvS8=; b=FrLWljzlRbRmkANX4XG+y54GX9oMW2LOvUkIPkD1klmFt6BPwjQ5jZqHdYb5Kk3cys zCH3nvPGogl2qIUVTNrxfDnbdh6RjAu/1PC5inBRHUCqhQrhnkesldhufaP7UDC1y9FI tHtXos7E/en7PeS3wjpUOW4Uybl3jD8ZTICZwKtdExLhJOYL1Lh9XEWk/GKLMN+3xx3+ E2Z6CwM6GSjhQVIzxex3QR2q5niL/Cou4xB98GEperZ7RfJKxVOoIL1hLap9B2B17bRP TUDIzlwzKdRPvnvL11tQvdAiKFCcnSU8BEyUELFhdc1jnDCAlu4/Mk0K/ZGyBj/jiPAX fUtA== 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:mime-version:content-transfer-encoding; bh=cmySRFzqSA2TlNGJUsvn+SuA2Sf+KVeqMGpgq3KXvS8=; b=ZBdDuEc8DhN9QiBaN3h4CIv/0S0oDZhFdc/zBJF0s/Y0cEVSVNt7y+jg9KOzKz3CZ3 IM4m5+JgJw91XEejmvcEVMdBskWOsQb0ecwY0CEh+5ZQO0eTsM69IUDEEHzTSkokKgSL 6pDz2mAMG4V71gSOmf4eFjPVYX3WYCCZdTbwgvEYSHwZ2VP1AncMkBjnHsJmNX/NGlno tGoADKN6R5G/N3uwq16Q0nFTVA1jsEaC3Zwk7n+De2VFw2JXGUGv85l84iSL3UqLW3UF 2GMva9ZCHJLbYbjGcFLlo9koj4iyGx20F5Q8B5bdRHjIdnjKEwehJhTRAd2x4kmAXs6R Wmow== X-Gm-Message-State: AHQUAuYpNUwfVy2KLuNqan5lfFiWeUOawHuLxiFCfdmfGqL8SOLBL9HF qxdRhOT7uYKukGx+LNDiEPU/EZYD X-Google-Smtp-Source: AHgI3IbuBqOQgXzOQm0X7Q7F/PWuOXGXaX+mBIy6RmflXsfzZ+EjnZ5QrYbRI18+eYFIzoFts9fbiA== X-Received: by 2002:adf:fc51:: with SMTP id e17mr23408150wrs.268.1549805235900; Sun, 10 Feb 2019 05:27:15 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:15 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 08/16] sequencer: refactor rearrange_squash() to work on a todo_list Date: Sun, 10 Feb 2019 14:26:40 +0100 Message-Id: <20190210132648.12821-9-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This refactors rearrange_squash() to work on a todo_list to avoid redundant reads and writes. The function is renamed todo_list_rearrange_squash(). The old version created a new buffer, which was directly written to the disk. This new version creates a new item list by just copying items from the old item list, without creating a new buffer. This eliminates the need to reparse the todo list, but this also means its buffer cannot be directly written to the disk. As rebase -p still need to check the todo list from the disk, a new function is introduced, rearrange_squash_in_todo_file(). complete_action() still uses rearrange_squash_in_todo_file() for now. This will be changed in a future commit. Signed-off-by: Alban Gruin --- No changes since v6. builtin/rebase--interactive.c | 2 +- sequencer.c | 92 ++++++++++++++++++----------------- sequencer.h | 2 +- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index c131fd4a27..74ebe7a10e 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -265,7 +265,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = check_todo_list_from_file(the_repository); break; case REARRANGE_SQUASH: - ret = rearrange_squash(the_repository); + ret = rearrange_squash_in_todo_file(the_repository); break; case ADD_EXEC: ret = sequencer_add_exec_commands(the_repository, &commands); diff --git a/sequencer.c b/sequencer.c index 82ca3432cd..ffa4c4da1a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4833,7 +4833,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla write_message("noop\n", 5, todo_file, 0)) return -1; - if (autosquash && rearrange_squash(r)) + if (autosquash && rearrange_squash_in_todo_file(r)) return -1; if (commands->nr) @@ -4939,21 +4939,13 @@ define_commit_slab(commit_todo_item, struct todo_item *); * message will have to be retrieved from the commit (as the oneline in the * script cannot be trusted) in order to normalize the autosquash arrangement. */ -int rearrange_squash(struct repository *r) +static int todo_list_rearrange_squash(struct todo_list *todo_list) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; struct hashmap subject2item; - int res = 0, rearranged = 0, *next, *tail, i; + int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0; char **subjects; struct commit_todo_item commit_todo; - - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) - return -1; - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { - todo_list_release(&todo_list); - return -1; - } + struct todo_item *items = NULL; init_commit_todo_item(&commit_todo); /* @@ -4966,13 +4958,13 @@ int rearrange_squash(struct repository *r) * be moved to appear after the i'th. */ hashmap_init(&subject2item, (hashmap_cmp_fn) subject2item_cmp, - NULL, todo_list.nr); - ALLOC_ARRAY(next, todo_list.nr); - ALLOC_ARRAY(tail, todo_list.nr); - ALLOC_ARRAY(subjects, todo_list.nr); - for (i = 0; i < todo_list.nr; i++) { + NULL, todo_list->nr); + ALLOC_ARRAY(next, todo_list->nr); + ALLOC_ARRAY(tail, todo_list->nr); + ALLOC_ARRAY(subjects, todo_list->nr); + for (i = 0; i < todo_list->nr; i++) { struct strbuf buf = STRBUF_INIT; - struct todo_item *item = todo_list.items + i; + struct todo_item *item = todo_list->items + i; const char *commit_buffer, *subject, *p; size_t subject_len; int i2 = -1; @@ -4985,7 +4977,6 @@ int rearrange_squash(struct repository *r) } if (is_fixup(item->command)) { - todo_list_release(&todo_list); clear_commit_todo_item(&commit_todo); return error(_("the script was already rearranged.")); } @@ -5020,7 +5011,7 @@ int rearrange_squash(struct repository *r) *commit_todo_item_at(&commit_todo, commit2)) /* found by commit name */ i2 = *commit_todo_item_at(&commit_todo, commit2) - - todo_list.items; + - todo_list->items; else { /* copy can be a prefix of the commit subject */ for (i2 = 0; i2 < i; i2++) @@ -5033,7 +5024,7 @@ int rearrange_squash(struct repository *r) } if (i2 >= 0) { rearranged = 1; - todo_list.items[i].command = + todo_list->items[i].command = starts_with(subject, "fixup!") ? TODO_FIXUP : TODO_SQUASH; if (next[i2] < 0) @@ -5051,10 +5042,8 @@ int rearrange_squash(struct repository *r) } if (rearranged) { - struct strbuf buf = STRBUF_INIT; - - for (i = 0; i < todo_list.nr; i++) { - enum todo_command command = todo_list.items[i].command; + for (i = 0; i < todo_list->nr; i++) { + enum todo_command command = todo_list->items[i].command; int cur = i; /* @@ -5065,37 +5054,50 @@ int rearrange_squash(struct repository *r) continue; while (cur >= 0) { - const char *bol = - get_item_line(&todo_list, cur); - const char *eol = - get_item_line(&todo_list, cur + 1); - - /* replace 'pick', by 'fixup' or 'squash' */ - command = todo_list.items[cur].command; - if (is_fixup(command)) { - strbuf_addstr(&buf, - todo_command_info[command].str); - bol += strcspn(bol, " \t"); - } - - strbuf_add(&buf, bol, eol - bol); - + ALLOC_GROW(items, nr + 1, alloc); + items[nr++] = todo_list->items[cur]; cur = next[cur]; } } - res = rewrite_file(todo_file, buf.buf, buf.len); - strbuf_release(&buf); + FREE_AND_NULL(todo_list->items); + todo_list->items = items; + todo_list->nr = nr; + todo_list->alloc = alloc; } free(next); free(tail); - for (i = 0; i < todo_list.nr; i++) + for (i = 0; i < todo_list->nr; i++) free(subjects[i]); free(subjects); hashmap_free(&subject2item, 1); - todo_list_release(&todo_list); clear_commit_todo_item(&commit_todo); - return res; + + return 0; +} + +int rearrange_squash_in_todo_file(struct repository *r) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res = 0; + + if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) + return -1; + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + todo_list_release(&todo_list); + return -1; + } + + res = todo_list_rearrange_squash(&todo_list); + if (!res) + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); + + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } diff --git a/sequencer.h b/sequencer.h index 87d04a3b9b..add50f04f1 100644 --- a/sequencer.h +++ b/sequencer.h @@ -154,7 +154,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash); -int rearrange_squash(struct repository *r); +int rearrange_squash_in_todo_file(struct repository *r); extern const char sign_off_header[]; From patchwork Sun Feb 10 13:26:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804795 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 68648746 for ; Sun, 10 Feb 2019 13:27:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 591D529F76 for ; Sun, 10 Feb 2019 13:27:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D8A429F95; Sun, 10 Feb 2019 13:27:31 +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 A101129F76 for ; Sun, 10 Feb 2019 13:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbfBJN13 (ORCPT ); Sun, 10 Feb 2019 08:27:29 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51093 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726235AbfBJN1T (ORCPT ); Sun, 10 Feb 2019 08:27:19 -0500 Received: by mail-wm1-f68.google.com with SMTP id z5so12198839wmf.0 for ; Sun, 10 Feb 2019 05:27:18 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=GfzLf/bBYUiUtgxa7x3u7/Y9hQyZpK5GQX3yufor5MA=; b=lVbZ87ikC6i2y2q17+80oYBq/yS86fPIhGFGIrn47zS3SiImfHGl01YPT+PzemQTjz pfiGBLZUDM1ML0RenS9OD7wEhEPnHQ3H6CD/fSc6wpIxCiTxr118rrbmBDm5JnNaM18+ zD6qVrDZ2gmkPpzIPQt746+WwNX1dxmeOnoECgcFPGQEGjGbFQ8Cer/QLNUDvLRFmckp tipD/Ni5Jan2UgQk2LATDve7GETHBg3ZdNmZkX9bIs6Jhzq0LRN7qXJ8O6p7m6cadbQx GkqEYfZ//70Ugy2ZwtttQPHXse6JCGcJdbMcHQLR9mAyd4lpmQUcvtKj8F+5j/YGsGj8 FBuA== 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:mime-version:content-transfer-encoding; bh=GfzLf/bBYUiUtgxa7x3u7/Y9hQyZpK5GQX3yufor5MA=; b=TPN0WG0Jc+PQ0bzWO0AHVGTgPKeZ/OrGJXduY+7XQ08AFVsauf9zBr3ecIbCf2XhaF 6fh0xp2d2Bwjb3DJO4GCJTtK3B+tnapxKX1JJnHZwYiLFnqatiuNWT9pyLjA2qZrcjvv IDANMZiFDGQb5ZxmtYB0mRkRIEEZLFrhXqSWjFrPNdbAvX/ajxNaMcMVS9LzAvpwmVaF pZYARTwPtC0tQVhr0KNy47uAmnWwEk2dxJ0M64Xzr7vVTO+uX/zlTGUj0/OxLdHOS7uv Oim5RvEwvN0KpdT1iLLXv3gVIXsO144Mgrnrqj0BCsvYCNlph4xWtl5/pXJzUkio2Dz1 x7Wg== X-Gm-Message-State: AHQUAuYOtnL/CKyz6IQDQkRfFYG3G+b9nurYqgdkA4g7s1guhukzxRyN O2trsFz/XR2ydqSz8IBYAhU3CQZ+ X-Google-Smtp-Source: AHgI3IZc4+oDwMVCC0/b80RJLh5FEE/B22Irmmlmxmt8Lw+6cR+CYJ4e2UZvvpyV2cW/yyJPZrbIcg== X-Received: by 2002:a05:6000:1044:: with SMTP id c4mr15731224wrx.296.1549805237097; Sun, 10 Feb 2019 05:27:17 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:16 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 09/16] sequencer: make sequencer_make_script() write its script to a strbuf Date: Sun, 10 Feb 2019 14:26:41 +0100 Message-Id: <20190210132648.12821-10-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This makes sequencer_make_script() write its script to a strbuf (ie. the buffer of a todo_list) instead of a FILE. This reduce the amount of read/write made by rebase interactive. Signed-off-by: Alban Gruin --- No changes since v6. builtin/rebase--interactive.c | 13 ++++++----- sequencer.c | 41 +++++++++++++++-------------------- sequencer.h | 5 ++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 74ebe7a10e..506154b5e2 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -71,7 +71,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *head_hash = NULL; char *revisions = NULL, *shortrevisions = NULL; struct argv_array make_script_args = ARGV_ARRAY_INIT; - FILE *todo_list; + FILE *todo_list_file; + struct todo_list todo_list = TODO_LIST_INIT; if (prepare_branch_to_be_rebased(opts, switch_to)) return -1; @@ -93,8 +94,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); - todo_list = fopen(rebase_path_todo(), "w"); - if (!todo_list) { + todo_list_file = fopen(rebase_path_todo(), "w"); + if (!todo_list_file) { free(revisions); free(shortrevisions); @@ -105,10 +106,11 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, if (restrict_revision) argv_array_push(&make_script_args, restrict_revision); - ret = sequencer_make_script(the_repository, todo_list, + ret = sequencer_make_script(the_repository, &todo_list.buf, make_script_args.argc, make_script_args.argv, flags); - fclose(todo_list); + fputs(todo_list.buf.buf, todo_list_file); + fclose(todo_list_file); if (ret) error(_("could not generate todo list")); @@ -121,6 +123,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, free(revisions); free(shortrevisions); + todo_list_release(&todo_list); argv_array_clear(&make_script_args); return ret; diff --git a/sequencer.c b/sequencer.c index ffa4c4da1a..dbef2547f7 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4215,7 +4215,7 @@ static const char *label_oid(struct object_id *oid, const char *label, } static int make_script_with_merges(struct pretty_print_context *pp, - struct rev_info *revs, FILE *out, + struct rev_info *revs, struct strbuf *out, unsigned flags) { int keep_empty = flags & TODO_LIST_KEEP_EMPTY; @@ -4360,7 +4360,7 @@ static int make_script_with_merges(struct pretty_print_context *pp, * gathering commits not yet shown, reversing the list on the fly, * then outputting that list (labeling revisions as needed). */ - fprintf(out, "%s onto\n", cmd_label); + strbuf_addf(out, "%s onto\n", cmd_label); for (iter = tips; iter; iter = iter->next) { struct commit_list *list = NULL, *iter2; @@ -4370,9 +4370,9 @@ static int make_script_with_merges(struct pretty_print_context *pp, entry = oidmap_get(&state.commit2label, &commit->object.oid); if (entry) - fprintf(out, "\n%c Branch %s\n", comment_line_char, entry->string); + strbuf_addf(out, "\n%c Branch %s\n", comment_line_char, entry->string); else - fprintf(out, "\n"); + strbuf_addch(out, '\n'); while (oidset_contains(&interesting, &commit->object.oid) && !oidset_contains(&shown, &commit->object.oid)) { @@ -4385,8 +4385,8 @@ static int make_script_with_merges(struct pretty_print_context *pp, } if (!commit) - fprintf(out, "%s %s\n", cmd_reset, - rebase_cousins ? "onto" : "[new root]"); + strbuf_addf(out, "%s %s\n", cmd_reset, + rebase_cousins ? "onto" : "[new root]"); else { const char *to = NULL; @@ -4399,12 +4399,12 @@ static int make_script_with_merges(struct pretty_print_context *pp, &state); if (!to || !strcmp(to, "onto")) - fprintf(out, "%s onto\n", cmd_reset); + strbuf_addf(out, "%s onto\n", cmd_reset); else { strbuf_reset(&oneline); pretty_print_commit(pp, commit, &oneline); - fprintf(out, "%s %s # %s\n", - cmd_reset, to, oneline.buf); + strbuf_addf(out, "%s %s # %s\n", + cmd_reset, to, oneline.buf); } } @@ -4413,11 +4413,11 @@ static int make_script_with_merges(struct pretty_print_context *pp, entry = oidmap_get(&commit2todo, oid); /* only show if not already upstream */ if (entry) - fprintf(out, "%s\n", entry->string); + strbuf_addf(out, "%s\n", entry->string); entry = oidmap_get(&state.commit2label, oid); if (entry) - fprintf(out, "%s %s\n", - cmd_label, entry->string); + strbuf_addf(out, "%s %s\n", + cmd_label, entry->string); oidset_insert(&shown, oid); } @@ -4439,13 +4439,11 @@ static int make_script_with_merges(struct pretty_print_context *pp, return 0; } -int sequencer_make_script(struct repository *r, FILE *out, - int argc, const char **argv, - unsigned flags) +int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, + const char **argv, unsigned flags) { char *format = NULL; struct pretty_print_context pp = {0}; - struct strbuf buf = STRBUF_INIT; struct rev_info revs; struct commit *commit; int keep_empty = flags & TODO_LIST_KEEP_EMPTY; @@ -4488,16 +4486,13 @@ int sequencer_make_script(struct repository *r, FILE *out, if (!is_empty && (commit->object.flags & PATCHSAME)) continue; - strbuf_reset(&buf); if (!keep_empty && is_empty) - strbuf_addf(&buf, "%c ", comment_line_char); - strbuf_addf(&buf, "%s %s ", insn, + strbuf_addf(out, "%c ", comment_line_char); + strbuf_addf(out, "%s %s ", insn, oid_to_hex(&commit->object.oid)); - pretty_print_commit(&pp, commit, &buf); - strbuf_addch(&buf, '\n'); - fputs(buf.buf, out); + pretty_print_commit(&pp, commit, out); + strbuf_addch(out, '\n'); } - strbuf_release(&buf); return 0; } diff --git a/sequencer.h b/sequencer.h index add50f04f1..e25f5151d3 100644 --- a/sequencer.h +++ b/sequencer.h @@ -142,9 +142,8 @@ int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_REBASE_COUSINS (1U << 4) #define TODO_LIST_APPEND_TODO_HELP (1U << 5) -int sequencer_make_script(struct repository *r, FILE *out, int argc, - const char **argv, - unsigned flags); +int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, + const char **argv, unsigned flags); int sequencer_add_exec_commands(struct repository *r, struct string_list *commands); From patchwork Sun Feb 10 13:26:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804785 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 C29EF14E1 for ; Sun, 10 Feb 2019 13:27:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F0229F91 for ; Sun, 10 Feb 2019 13:27:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A77CE29F95; Sun, 10 Feb 2019 13:27:26 +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 0A7CA29F76 for ; Sun, 10 Feb 2019 13:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbfBJN1X (ORCPT ); Sun, 10 Feb 2019 08:27:23 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40011 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbfBJN1V (ORCPT ); Sun, 10 Feb 2019 08:27:21 -0500 Received: by mail-wm1-f68.google.com with SMTP id q21so11785786wmc.5 for ; Sun, 10 Feb 2019 05:27:19 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=z0NDArt2ZOnPddPKB0bqPTGH17eRLhjgKJKk5Pm4QjI=; b=ep4NS9A2pGtpr+nFIwe7MaSOyWhn+RO9Sty10qZYq/NN2muGpM+rs+UCPNI3McK1XZ 3/M/NiNKhRd7wc4lZWkV2Yo80NAdyeTdj7JgoGIXrqdOMRDzR9+coE+oZMs//S3DUkQn kMSzGzJXDhOMVarbJSXt/CSEBGlMHzP+16uVkIip1mTpOe5rHQk1UFPUTua7X6F+vTJD QdS6Z6GH1L0Khs9sc732wBcAa2Sw4jL+Ts6W5mcyQy56aS4mMYcgY09rtVRsEu6fipl7 MjwE2X9mbvJiNsPuNvHjp0VL3+CR+HxxL9xnmNyrfiIXGr3limcSruSJvh6yznNK+Ds8 12OA== 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:mime-version:content-transfer-encoding; bh=z0NDArt2ZOnPddPKB0bqPTGH17eRLhjgKJKk5Pm4QjI=; b=Soe0yDyKHvKlFPpaC1sT1PFnAIKh+iYLOP/0e2V8OXZCAxqKHQ5iUvzdwaFjiOrwuF Kfwbak95NPDnu3NJIoZ2OaFtMIPpCQ+3gwZ9XNuWPapNvtBJobGbqlJbdvEB+QahlZoN RCL08PAmGTvlVSjQhCQQLmeCKn9QPRsXBp4yRkChA0ywjHnx9ZXyye5K22wGDLsZOB7D J2GGSZb3B05+moVwdDwaY/7iCOjpvy+cm2iXqPkClRymvfRtqkHEfRCB/JHjS8ccQ88G qqXltjr5uPjpSC98oFHDrVFZESWRsFloSmjD1A9l8FvBPDr8b/uRxzr97L4Pk5clpfMx iQ0Q== X-Gm-Message-State: AHQUAua69aftgnugEI8aej/mVS/qGx71URtwQ1HkaXe6fWY2R8nxJKBc 95RourhKshHXtbHTcytuNJh9qNjr X-Google-Smtp-Source: AHgI3IZt0sVDyJSty43MdbgFVpcu9anA9KTuJMHwmyhUyOarFXESx3wYHtgFM9/1W87cE1Rjyunmng== X-Received: by 2002:a5d:67cf:: with SMTP id n15mr23125663wrw.211.1549805238201; Sun, 10 Feb 2019 05:27:18 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:17 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 10/16] sequencer: change complete_action() to use the refactored functions Date: Sun, 10 Feb 2019 14:26:42 +0100 Message-Id: <20190210132648.12821-11-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 complete_action() used functions that read the todo-list file, made some changes to it, and wrote it back to the disk. The previous commits were dedicated to separate the part that deals with the file from the actual logic of these functions. Now that this is done, we can call directly the "logic" functions to avoid useless file access. The parsing of the list has to be done by the caller. If the buffer of the todo list provided by the caller is empty, a `noop' command is directly added to the todo list, without touching the buffer. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 20 +++------ sequencer.c | 79 +++++++++++++++-------------------- sequencer.h | 2 +- 3 files changed, 41 insertions(+), 60 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 506154b5e2..4f2949922f 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -71,7 +71,6 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *head_hash = NULL; char *revisions = NULL, *shortrevisions = NULL; struct argv_array make_script_args = ARGV_ARRAY_INIT; - FILE *todo_list_file; struct todo_list todo_list = TODO_LIST_INIT; if (prepare_branch_to_be_rebased(opts, switch_to)) @@ -94,14 +93,6 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, if (!upstream && squash_onto) write_file(path_squash_onto(), "%s\n", squash_onto); - todo_list_file = fopen(rebase_path_todo(), "w"); - if (!todo_list_file) { - free(revisions); - free(shortrevisions); - - return error_errno(_("could not open %s"), rebase_path_todo()); - } - argv_array_pushl(&make_script_args, "", revisions, NULL); if (restrict_revision) argv_array_push(&make_script_args, restrict_revision); @@ -109,16 +100,17 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, ret = sequencer_make_script(the_repository, &todo_list.buf, make_script_args.argc, make_script_args.argv, flags); - fputs(todo_list.buf.buf, todo_list_file); - fclose(todo_list_file); if (ret) error(_("could not generate todo list")); else { discard_cache(); - ret = complete_action(the_repository, opts, flags, - shortrevisions, onto_name, onto, - head_hash, commands, autosquash); + if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, + &todo_list)) + BUG("unusable todo list"); + + ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name, + onto, head_hash, commands, autosquash, &todo_list); } free(revisions); diff --git a/sequencer.c b/sequencer.c index dbef2547f7..eb8a622af0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4810,93 +4810,82 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output return 0; } +static int todo_list_rearrange_squash(struct todo_list *todo_list); + int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, - unsigned autosquash) + unsigned autosquash, struct todo_list *todo_list) { const char *shortonto, *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf *buf = &(todo_list.buf); + struct todo_list new_todo = TODO_LIST_INIT; + struct strbuf *buf = &todo_list->buf; struct object_id oid; - struct stat st; get_oid(onto, &oid); shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); - if (!lstat(todo_file, &st) && st.st_size == 0 && - write_message("noop\n", 5, todo_file, 0)) - return -1; + if (buf->len == 0) { + struct todo_item *item = append_new_todo(todo_list); + item->command = TODO_NOOP; + item->commit = NULL; + item->arg_len = item->arg_offset = item->flags = item->offset_in_buf = 0; + } - if (autosquash && rearrange_squash_in_todo_file(r)) + if (autosquash && todo_list_rearrange_squash(todo_list)) return -1; if (commands->nr) - sequencer_add_exec_commands(r, commands); + todo_list_add_exec_commands(todo_list, commands); - if (strbuf_read_file(buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - if (count_commands(&todo_list) == 0) { + if (count_commands(todo_list) == 0) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); return error(_("nothing to do")); } - strbuf_addch(buf, '\n'); - strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", - "Rebase %s onto %s (%d commands)", - count_commands(&todo_list)), - shortrevisions, shortonto, count_commands(&todo_list)); - append_todo_help(0, flags & TODO_LIST_KEEP_EMPTY, buf); - - if (write_message(buf->buf, buf->len, todo_file, 0)) { - todo_list_release(&todo_list); - return -1; - } + if (todo_list_write_to_file(r, todo_list, todo_file, + shortrevisions, shortonto, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) + return error_errno(_("could not write '%s'"), todo_file); if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) return error(_("could not copy '%s' to '%s'."), todo_file, rebase_path_todo_backup()); - if (transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS)) - return error(_("could not transform the todo list")); - - strbuf_reset(buf); - - if (launch_sequence_editor(todo_file, buf, NULL)) { + if (launch_sequence_editor(todo_file, &new_todo.buf, NULL)) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); return -1; } - strbuf_stripspace(buf, 1); - if (buf->len == 0) { + strbuf_stripspace(&new_todo.buf, 1); + if (new_todo.buf.len == 0) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); + todo_list_release(&new_todo); return error(_("nothing to do")); } - todo_list_release(&todo_list); - - if (check_todo_list_from_file(r)) { + if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) || + todo_list_check(todo_list, &new_todo)) { + fprintf(stderr, _(edit_todo_list_advice)); checkout_onto(opts, onto_name, onto, orig_head); + todo_list_release(&new_todo); + return -1; } - if (transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS))) - return error(_("could not transform the todo list")); + if (todo_list_write_to_file(r, &new_todo, todo_file, NULL, NULL, -1, + flags & ~(TODO_LIST_SHORTEN_IDS))) { + todo_list_release(&new_todo); + return error_errno(_("could not write '%s'"), todo_file); + } + + todo_list_release(&new_todo); if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) return error(_("could not skip unnecessary pick commands")); diff --git a/sequencer.h b/sequencer.h index e25f5151d3..7029b39cd6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -152,7 +152,7 @@ int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, - unsigned autosquash); + unsigned autosquash, struct todo_list *todo_list); int rearrange_squash_in_todo_file(struct repository *r); extern const char sign_off_header[]; From patchwork Sun Feb 10 13:26:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804789 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 C60A0746 for ; Sun, 10 Feb 2019 13:27:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A2829F76 for ; Sun, 10 Feb 2019 13:27:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA2FA29F95; Sun, 10 Feb 2019 13:27:28 +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 3592729F76 for ; Sun, 10 Feb 2019 13:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726699AbfBJN11 (ORCPT ); Sun, 10 Feb 2019 08:27:27 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55266 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfBJN1W (ORCPT ); Sun, 10 Feb 2019 08:27:22 -0500 Received: by mail-wm1-f65.google.com with SMTP id a62so12204182wmh.4 for ; Sun, 10 Feb 2019 05:27:20 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=NCCMXnk/QC9967cjOWBhRPOzBQ+hp5/JMaKiI2Tq0VQ=; b=gHV3mc+oMiRAB8Vh9ELhtqE+MF83nfMhTrP4gXO/sXXW1XKHO2Qu6hoTTb0nrdESq/ 1eEPcRMlhcl6AWKICq+L48C99jdW5Oyw8Vy1klfBP4AjoJZ7irHe8Z+F1di89PGdFGA7 zKtaI083lyrh3DgodX+OrDpu8AuafnlWtHiZe6q6fOkqTwqFG2gCwnkbq8MaqzrYhMmy WBZjMNRfNBW3Yde0UzjwNc3j4hDjCw9mUx9KVggKIj3uFxBtYSPRk5k5zbdCygTRl+Wb XlBTncAPquMp85yNuohe7KP7z+R8F3gkm7gS9ycs9nIvlwgpX30e0LdtqcfMh3aHq99X g7Vg== 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:mime-version:content-transfer-encoding; bh=NCCMXnk/QC9967cjOWBhRPOzBQ+hp5/JMaKiI2Tq0VQ=; b=SFPcsfHWpf3i3kUQTvgsWZwt5YKiVsnrfxT4mAo9Xy8YDhECXXdYFg9cl+QeAB1nIQ Xw+IqWjKaVWdbUeLuy93MzmeAohrOHlrQOfLxdcpdNka/22bVmqANEQ5egyKhWeYGt1T j4wDmOeMHefkGMfyjzuz6ezbvTIu4brJM91PE6IBFwoFXJYkBebr8bZ6Wa5m9k7J4bYG 3eAa3IfUiFuqbgwbX/JWzV+ItwtFhEbsk/ktKEDEO+s4fqMOSvHYNWQ/0QKBLdxCaiXg imN0wM80l20HZIA/TkKS32BHuO0yz27adyU2C4m6mwqMMN+SkNiWkbac8l3T0HajQfqy ksRw== X-Gm-Message-State: AHQUAua+v7BTyZbhawRX1jr4sOhaNMMFGd/4tT6z4InogKEONYNjJJDF ATI5orBRBf4+YfSdZriKEJjC5f2Y X-Google-Smtp-Source: AHgI3IY7jRqUj9+xtFyndKSvk+IwGm81bE7+hHeCEUeELtsukoCmL6lVodXEQMX/lOO8klVoG8Fucg== X-Received: by 2002:a05:6000:8b:: with SMTP id m11mr1718424wrx.243.1549805239404; Sun, 10 Feb 2019 05:27:19 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:18 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 11/16] sequencer: refactor skip_unnecessary_picks() to work on a todo_list Date: Sun, 10 Feb 2019 14:26:43 +0100 Message-Id: <20190210132648.12821-12-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This refactors skip_unnecessary_picks() to work on a todo_list. As this function is only called by complete_action() (and thus is not used by rebase -p), the file-handling logic is completely dropped here. Instead of truncating the todo list’s buffer, the items are moved to the beginning of the list, eliminating the need to reparse the list. This also means its buffer cannot be directly written to the disk. rewrite_file() is then removed, as it is now unused. Signed-off-by: Alban Gruin --- sequencer.c | 82 +++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 63 deletions(-) diff --git a/sequencer.c b/sequencer.c index eb8a622af0..eacaf52250 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4717,52 +4717,22 @@ int check_todo_list_from_file(struct repository *r) return res; } -static int rewrite_file(const char *path, const char *buf, size_t len) -{ - int rc = 0; - int fd = open(path, O_WRONLY | O_TRUNC); - if (fd < 0) - return error_errno(_("could not open '%s' for writing"), path); - if (write_in_full(fd, buf, len) < 0) - rc = error_errno(_("could not write to '%s'"), path); - if (close(fd) && !rc) - rc = error_errno(_("could not close '%s'"), path); - return rc; -} - /* skip picking commits whose parents are unchanged */ -static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid) +static int skip_unnecessary_picks(struct repository *r, + struct todo_list *todo_list, + struct object_id *base_oid) { - const char *todo_file = rebase_path_todo(); - struct strbuf buf = STRBUF_INIT; - struct todo_list todo_list = TODO_LIST_INIT; struct object_id *parent_oid; - int fd, i; - - if (!read_oneliner(&buf, rebase_path_onto(), 0)) - return error(_("could not read 'onto'")); - if (get_oid(buf.buf, output_oid)) { - strbuf_release(&buf); - return error(_("need a HEAD to fixup")); - } - strbuf_release(&buf); - - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) - return -1; - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { - todo_list_release(&todo_list); - return -1; - } + int i; - for (i = 0; i < todo_list.nr; i++) { - struct todo_item *item = todo_list.items + i; + for (i = 0; i < todo_list->nr; i++) { + struct todo_item *item = todo_list->items + i; if (item->command >= TODO_NOOP) continue; if (item->command != TODO_PICK) break; if (parse_commit(item->commit)) { - todo_list_release(&todo_list); return error(_("could not parse commit '%s'"), oid_to_hex(&item->commit->object.oid)); } @@ -4771,42 +4741,26 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output if (item->commit->parents->next) break; /* merge commit */ parent_oid = &item->commit->parents->item->object.oid; - if (!oideq(parent_oid, output_oid)) + if (!oideq(parent_oid, base_oid)) break; - oidcpy(output_oid, &item->commit->object.oid); + oidcpy(base_oid, &item->commit->object.oid); } if (i > 0) { - int offset = get_item_line_offset(&todo_list, i); const char *done_path = rebase_path_done(); - fd = open(done_path, O_CREAT | O_WRONLY | O_APPEND, 0666); - if (fd < 0) { - error_errno(_("could not open '%s' for writing"), - done_path); - todo_list_release(&todo_list); - return -1; - } - if (write_in_full(fd, todo_list.buf.buf, offset) < 0) { + if (todo_list_write_to_file(r, todo_list, done_path, NULL, NULL, i, 0)) { error_errno(_("could not write to '%s'"), done_path); - todo_list_release(&todo_list); - close(fd); return -1; } - close(fd); - if (rewrite_file(rebase_path_todo(), todo_list.buf.buf + offset, - todo_list.buf.len - offset) < 0) { - todo_list_release(&todo_list); - return -1; - } + MOVE_ARRAY(todo_list->items, todo_list->items + i, todo_list->nr - i); + todo_list->nr -= i; + todo_list->current = 0; - todo_list.current = i; - if (is_fixup(peek_command(&todo_list, 0))) - record_in_rewritten(output_oid, peek_command(&todo_list, 0)); + if (is_fixup(peek_command(todo_list, 0))) + record_in_rewritten(base_oid, peek_command(todo_list, 0)); } - todo_list_release(&todo_list); - return 0; } @@ -4879,6 +4833,11 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return -1; } + if (opts->allow_ff && skip_unnecessary_picks(r, &new_todo, &oid)) { + todo_list_release(&new_todo); + return error(_("could not skip unnecessary pick commands")); + } + if (todo_list_write_to_file(r, &new_todo, todo_file, NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) { todo_list_release(&new_todo); @@ -4887,9 +4846,6 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla todo_list_release(&new_todo); - if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) - return error(_("could not skip unnecessary pick commands")); - if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head)) return -1; From patchwork Sun Feb 10 13:26:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804783 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 A140814E1 for ; Sun, 10 Feb 2019 13:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9243C29F76 for ; Sun, 10 Feb 2019 13:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86A3229F95; Sun, 10 Feb 2019 13:27:25 +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 1E3F329F76 for ; Sun, 10 Feb 2019 13:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726530AbfBJN1Y (ORCPT ); Sun, 10 Feb 2019 08:27:24 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52826 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbfBJN1W (ORCPT ); Sun, 10 Feb 2019 08:27:22 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so12210069wml.2 for ; Sun, 10 Feb 2019 05:27:21 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=DkjQlhoRMRJdt5YQicAHVb7qFbWTiWUunKNcdxo6elk=; b=Ov/Jmay6PtvdKKaa934crkMpJx0XX8Y3dioFb4fH/DxNyUvVdkb7Z6NdcWJ7DpzTWe FIDVzwL44bz6tzUSCoClqCL6siyTG1A4/V1NEgbTGgTIbmdeAUBk4ga4s8Ps0bqvcEzt o7bLm73AQA4ba4/H7KRhGnNYlInwhWa4S/LKuD1DwwbDgpWbXbyQUOFZ4AZOu6vhS0C2 PbD5zTNEIWYXxbtcEqbkCoBlZMf07sxeTCJSzcRUk+PzwG3PVatLedR9pONoWbPM6Myy urcsiA4za92a6pw3UxAsYmI+of026fAnD6zkjw1JBlSUpdKLwfs6Hc5N2VkpEyV8zc6H cmPA== 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:mime-version:content-transfer-encoding; bh=DkjQlhoRMRJdt5YQicAHVb7qFbWTiWUunKNcdxo6elk=; b=Pf7hICM2WZHEzszLKXd+5R+t38lPRgqBSV842Ij45bRRg39NM8uCGKglkZVz/ANSgf vOGWU/35nJR+U3nD0SPF1UQPD+3Hh2xDVkHpdBXyZOJAZExb8eubM74bEPth8ouvCRlb W3sRhQGQd9zOIhlKt6GdKv7EcQSBN6cXctIIcSUVV3pA5tqgiwO87v5knvDGhJ25w9Ib s2+M70psNJk8THUDkQcGxB7Z+WmoBrrc9V6NNWMS2wMWANQV1M84p8TKtR8lKtiLkJ3A dXSEgcZjyyKyoC12fzQKgOq4S6/J3Z4W+4VsKfoHFa3Kibc3wgvELXg+XTa9d7PDP+Ee BrrA== X-Gm-Message-State: AHQUAuYb0IpXMZWJsDF/unaQ1+24R/2UlHCuK+aSvwNCQOFaumf8rhvn jbAqqU20IlhgdLqKdCcNbNCvJOPw X-Google-Smtp-Source: AHgI3IasnrgBhyU2+hs5TklckLeqWDMg2jQccYJbRSjj/HsR0Sxpyl1+/zFvPw5NXkAwnNWrjb3sRQ== X-Received: by 2002:adf:df08:: with SMTP id y8mr22748723wrl.23.1549805240731; Sun, 10 Feb 2019 05:27:20 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:20 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 12/16] rebase-interactive: use todo_list_write_to_file() in edit_todo_list() Date: Sun, 10 Feb 2019 14:26:44 +0100 Message-Id: <20190210132648.12821-13-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 Just like complete_action(), edit_todo_list() used a function (transform_todo_file()) that read the todo list from the disk and wrote it back, resulting in useless disk accesses. This changes edit_todo_list() to call directly todo_list_write_to_file() instead. Signed-off-by: Alban Gruin --- No changes since v6. rebase-interactive.c | 38 ++++++++++++++++---------------------- sequencer.c | 4 ++-- sequencer.h | 3 --- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index dfa6dd530f..d396ecc599 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -79,39 +79,33 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty, int edit_todo_list(struct repository *r, unsigned flags) { - struct strbuf buf = STRBUF_INIT; const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res = 0; - if (strbuf_read_file(&buf, todo_file, 0) < 0) + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - strbuf_stripspace(&buf, 1); - if (write_message(buf.buf, buf.len, todo_file, 0)) { - strbuf_release(&buf); + strbuf_stripspace(&todo_list.buf, 1); + todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) { + todo_list_release(&todo_list); return -1; } - strbuf_release(&buf); - - transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS); - - if (strbuf_read_file(&buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - append_todo_help(1, 0, &buf); - if (write_message(buf.buf, buf.len, todo_file, 0)) { - strbuf_release(&buf); + strbuf_reset(&todo_list.buf); + if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { + todo_list_release(&todo_list); return -1; } - strbuf_release(&buf); + if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, + flags & ~(TODO_LIST_SHORTEN_IDS)); - if (launch_sequence_editor(todo_file, NULL, NULL)) - return -1; - - transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS)); - - return 0; + todo_list_release(&todo_list); + return res; } define_commit_slab(commit_seen, unsigned char); diff --git a/sequencer.c b/sequencer.c index eacaf52250..74fbb14153 100644 --- a/sequencer.c +++ b/sequencer.c @@ -383,8 +383,8 @@ static void print_advice(struct repository *r, int show_hint, } } -int write_message(const void *buf, size_t len, const char *filename, - int append_eol) +static int write_message(const void *buf, size_t len, const char *filename, + int append_eol) { struct lock_file msg_file = LOCK_INIT; diff --git a/sequencer.h b/sequencer.h index 7029b39cd6..c80990659c 100644 --- a/sequencer.h +++ b/sequencer.h @@ -64,9 +64,6 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } -int write_message(const void *buf, size_t len, const char *filename, - int append_eol); - /* * Note that ordering matters in this enum. Not only must it match the mapping * of todo_command_info (in sequencer.c), it is also divided into several From patchwork Sun Feb 10 13:26:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804791 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 6AA531515 for ; Sun, 10 Feb 2019 13:27:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B8B429F76 for ; Sun, 10 Feb 2019 13:27:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FEB529F95; Sun, 10 Feb 2019 13:27:29 +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 DD42429F76 for ; Sun, 10 Feb 2019 13:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726756AbfBJN11 (ORCPT ); Sun, 10 Feb 2019 08:27:27 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33005 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbfBJN1Y (ORCPT ); Sun, 10 Feb 2019 08:27:24 -0500 Received: by mail-wm1-f66.google.com with SMTP id h22so11716874wmb.0 for ; Sun, 10 Feb 2019 05:27:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=+NiKZSwkto6M1ls6y+aDFk+4AOBgwy95xYvdIeZeTIs=; b=WGg3EEqwG0uzf3G6LP7RTQNghS7D0FNvJ4zK0hZ4qpk6YT2YXAd7zfj7q7awoyAIoL Mxe5JRTBAJgr3MOUdI18whNhwzfu33H3b4Q05uszj88783adLANylRIDpdZU6WTyq3+a Xfo5hKL3mabXVGTYEzQ9NyI8SxOqtuO5UDN2YN97IbIjqJFrUzGLMWTZWTNXNTZPreio +1XQIkBmH8bI8VEAZLC2q4vbU8KX2057GG77G5VZznRcf8W3a5L/IlvCgjr0vBDBLa4f SwWJjbZKq/eO6xWuO0VByIPPtooXNkV/4IoqO2Nr2z0p2glZ2PosoFSuaRKIAEdkhd1v rHdg== 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:mime-version:content-transfer-encoding; bh=+NiKZSwkto6M1ls6y+aDFk+4AOBgwy95xYvdIeZeTIs=; b=DPntfQU92woIo1FTC2Dl+04BbylXlH39lHNDMhGoDXd+Kk5tW2URRpAgWl8RPRdgVn O5cv7VrDzoIIA4RiGivom2Kx+DQAvwzCl5S0X+eoNZSPxKzug+Cp1naSy0RbAGL3RV+M YuWQc8YFiSuCuZJGQjlfxl8wZTndew8QT4+jZnWci171B8Kclcc17iIIsbKEnsAR9XgL v+KFz1KvpoDkTY+MwwzQxACxosrwpGNreBAzP9uISesvs4ESM1WRCGJ2LJcua/2dutRh fAODptQ05H/H9+ep9FdzGY58MfGmCdAdDT9tEk/mJD8Ie4bbcXyEXimxyuh+iIxQbeXw tX1g== X-Gm-Message-State: AHQUAuYM4V7vzNEbVYCMaLqrn70srR3JR1llMgOZcCvJnOaF2tOkIMqQ SNFYJvWnXYsAtYrmeCN2r0TJ8M/c X-Google-Smtp-Source: AHgI3IZljCcayND1MWzeDog4MUYLE7ozqSHX/hkU/WioQYsTxYCK+B/e6NPuQi298ca5TCo6YIJmSw== X-Received: by 2002:a1c:22c5:: with SMTP id i188mr5741236wmi.39.1549805241929; Sun, 10 Feb 2019 05:27:21 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:21 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 13/16] rebase-interactive: append_todo_help() changes Date: Sun, 10 Feb 2019 14:26:45 +0100 Message-Id: <20190210132648.12821-14-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This moves the writing of the comment "Rebase $shortrevisions onto $shortonto ($command_count commands)" from todo_list_write_to_file() to append_todo_help(). shortrevisions, shortonto, and command_count are passed as parameters to append_todo_help(). During the initial edit of the todo list, shortrevisions and shortonto are not NULL. Therefore, if shortrevisions or shortonto is NULL, then edit_todo would be true, otherwise it would be false. Thus, edit_todo is removed from the parameters of append_todo_help(). Signed-off-by: Alban Gruin --- No changes since v6. rebase-interactive.c | 12 +++++++++++- rebase-interactive.h | 3 ++- sequencer.c | 17 ++++------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index d396ecc599..807f8370db 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -28,7 +28,8 @@ static enum missing_commit_check_level get_missing_commit_check_level(void) return MISSING_COMMIT_CHECK_IGNORE; } -void append_todo_help(unsigned edit_todo, unsigned keep_empty, +void append_todo_help(unsigned keep_empty, int command_count, + const char *shortrevisions, const char *shortonto, struct strbuf *buf) { const char *msg = _("\nCommands:\n" @@ -48,6 +49,15 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty, ". specified). Use -c to reword the commit message.\n" "\n" "These lines can be re-ordered; they are executed from top to bottom.\n"); + unsigned edit_todo = !(shortrevisions && shortonto); + + if (!edit_todo) { + strbuf_addch(buf, '\n'); + strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", + "Rebase %s onto %s (%d commands)", + command_count), + shortrevisions, shortonto, command_count); + } strbuf_add_commented_lines(buf, msg, strlen(msg)); diff --git a/rebase-interactive.h b/rebase-interactive.h index 187b5032d6..0e5925e3aa 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -5,7 +5,8 @@ struct strbuf; struct repository; struct todo_list; -void append_todo_help(unsigned edit_todo, unsigned keep_empty, +void append_todo_help(unsigned keep_empty, int command_count, + const char *shortrevisions, const char *shortonto, struct strbuf *buf); int edit_todo_list(struct repository *r, unsigned flags); int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); diff --git a/sequencer.c b/sequencer.c index 74fbb14153..64d698032c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4636,22 +4636,13 @@ int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, const char *file, const char *shortrevisions, const char *shortonto, int num, unsigned flags) { - int edit_todo = !(shortrevisions && shortonto), res; + int res; struct strbuf buf = STRBUF_INIT; todo_list_to_strbuf(r, todo_list, &buf, num, flags); - - if (flags & TODO_LIST_APPEND_TODO_HELP) { - int command_count = count_commands(todo_list); - if (!edit_todo) { - strbuf_addch(&buf, '\n'); - strbuf_commented_addf(&buf, Q_("Rebase %s onto %s (%d command)", - "Rebase %s onto %s (%d commands)", - command_count), - shortrevisions, shortonto, command_count); - } - append_todo_help(edit_todo, flags & TODO_LIST_KEEP_EMPTY, &buf); - } + if (flags & TODO_LIST_APPEND_TODO_HELP) + append_todo_help(flags & TODO_LIST_KEEP_EMPTY, count_commands(todo_list), + shortrevisions, shortonto, &buf); res = write_message(buf.buf, buf.len, file, 0); strbuf_release(&buf); From patchwork Sun Feb 10 13:26:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804793 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 76433746 for ; Sun, 10 Feb 2019 13:27:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65D1729F76 for ; Sun, 10 Feb 2019 13:27:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A23C29F95; Sun, 10 Feb 2019 13:27:30 +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 C160729F76 for ; Sun, 10 Feb 2019 13:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726792AbfBJN12 (ORCPT ); Sun, 10 Feb 2019 08:27:28 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40016 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726541AbfBJN1Z (ORCPT ); Sun, 10 Feb 2019 08:27:25 -0500 Received: by mail-wm1-f68.google.com with SMTP id q21so11785968wmc.5 for ; Sun, 10 Feb 2019 05:27:24 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=AVRrBEJxojslbzgeM5QC9mzWNArR0LW8Q4OeDlon1Ls=; b=ihFMdUlpFaB8eQxLz19mqZXX0gLlEf+Ul0I5A1o/Qk1efDENfhg1/9oqm05VKBuPVD ARu2GOO+NrWQ3DNkUZ1vTSt74PkYliAlhD9jWlzqN17ydQDwx+vu1j7B3GLlla91cRCx 7uDa00JC55rQ3pkvwSa3sXyRRcgvy0zLj85SIMttA00IuiEjmzSgmTCp2M21RLOmlfJw 7W9yKmCRG6fuewwV2ZyFd3Ri4LWT1VHKubfu7DaEPg69mIID757yoKm9UfKvsaKCYywZ jly3ktUtCPlpOP/c664+c3oPySRkNC9lXvpviYPywKVLUzc60ZN9HOh54fP0z5mPuHZd 0O8A== 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:mime-version:content-transfer-encoding; bh=AVRrBEJxojslbzgeM5QC9mzWNArR0LW8Q4OeDlon1Ls=; b=uHkSj+l+Sj2duHred2m6NN2xMBT2Jls7PM1cPD770orMbd3MxVE9TGTv6FJWFyt4Vf cUnwJeWYPV962xKPjNVbsD1bAix3gbKZo5C2SOn1V0uwFKDIOarDNYtLueQcJIHhWCCP 5J18jPEVlDzDFp4y1R5xkzhKfO+Dkec31nuJKrqm1xiHf6UFdQuhbjJLTI8It3P/y5BU 5tRZw2d4DbBQgCOlqnqeTMrSRjB765Z3rFTWwLhp31VH2Ma+yjeK3fYJyDvdEiwHIKVO 5kGovKusGLmnK8F/PGHvWJweRhkJ+FfpZiRtCjpodCDLx7+Ao3DV3RppkRLREpiOPpBT 0F7g== X-Gm-Message-State: AHQUAuaqdVo9oD/etFrzQjhOcvrAidECLWqs9DfIJLBCshVZSK/inCIr 6WAjiHUBbCAmRa2BvbzDSobRMNZn X-Google-Smtp-Source: AHgI3Iaynonw2u6jbKce8B9F9iyPuBJJnhwa2T+TGWJ80n1shA0+3QG7uzOsNxzNerl1KEhcAxQxKw== X-Received: by 2002:adf:c704:: with SMTP id k4mr1197835wrg.142.1549805243227; Sun, 10 Feb 2019 05:27:23 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:22 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 14/16] rebase-interactive: rewrite edit_todo_list() to handle the initial edit Date: Sun, 10 Feb 2019 14:26:46 +0100 Message-Id: <20190210132648.12821-15-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 edit_todo_list() is changed to work on a todo_list, and to handle the initial edition of the todo list (ie. making a backup of the todo list). It does not check for dropped commits yet, as todo_list_check() does not take the commits that have already been processed by the rebase (ie. the todo list is edited in the middle of a rebase session). Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 24 +++++++++++++++++- rebase-interactive.c | 48 +++++++++++++++++------------------ rebase-interactive.h | 4 ++- sequencer.c | 3 +-- sequencer.h | 1 + 5 files changed, 52 insertions(+), 28 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 4f2949922f..370d584683 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -13,6 +13,28 @@ static GIT_PATH_FUNC(path_state_dir, "rebase-merge/") static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto") static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive") +static int edit_todo_file(unsigned flags) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT, + new_todo = TODO_LIST_INIT; + int res = 0; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + strbuf_stripspace(&todo_list.buf, 1); + res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags); + if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file, + NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) + res = error_errno(_("could not write '%s'"), todo_file); + + todo_list_release(&todo_list); + todo_list_release(&new_todo); + + return res; +} + static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, char **revisions, char **shortrevisions) @@ -241,7 +263,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) break; } case EDIT_TODO: - ret = edit_todo_list(the_repository, flags); + ret = edit_todo_file(flags); break; case SHOW_CURRENT_PATCH: { struct child_process cmd = CHILD_PROCESS_INIT; diff --git a/rebase-interactive.c b/rebase-interactive.c index 807f8370db..96c70d1959 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -87,35 +87,35 @@ void append_todo_help(unsigned keep_empty, int command_count, } } -int edit_todo_list(struct repository *r, unsigned flags) +int edit_todo_list(struct repository *r, struct todo_list *todo_list, + struct todo_list *new_todo, const char *shortrevisions, + const char *shortonto, unsigned flags) { const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res = 0; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - strbuf_stripspace(&todo_list.buf, 1); - todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) { - todo_list_release(&todo_list); - return -1; - } + unsigned initial = shortrevisions && shortonto; - strbuf_reset(&todo_list.buf); - if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { - todo_list_release(&todo_list); - return -1; - } + if (!initial) + todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); - if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) - res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags & ~(TODO_LIST_SHORTEN_IDS)); + if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto, + -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) + return error_errno(_("could not write '%s'"), todo_file); - todo_list_release(&todo_list); - return res; + if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666)) + return error(_("could not copy '%s' to '%s'."), todo_file, + rebase_path_todo_backup()); + + if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) + return -2; + + strbuf_stripspace(&new_todo->buf, 1); + if (initial && new_todo->buf.len == 0) + return -3; + + if (!initial) + return todo_list_parse_insn_buffer(r, new_todo->buf.buf, new_todo); + + return 0; } define_commit_slab(commit_seen, unsigned char); diff --git a/rebase-interactive.h b/rebase-interactive.h index 0e5925e3aa..44dbb06311 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -8,7 +8,9 @@ struct todo_list; void append_todo_help(unsigned keep_empty, int command_count, const char *shortrevisions, const char *shortonto, struct strbuf *buf); -int edit_todo_list(struct repository *r, unsigned flags); +int edit_todo_list(struct repository *r, struct todo_list *todo_list, + struct todo_list *new_todo, const char *shortrevisions, + const char *shortonto, unsigned flags); int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); #endif diff --git a/sequencer.c b/sequencer.c index 64d698032c..f6ed4e21e9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -55,8 +55,7 @@ static GIT_PATH_FUNC(rebase_path, "rebase-merge") * file and written to the tail of 'done'. */ GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo") -static GIT_PATH_FUNC(rebase_path_todo_backup, - "rebase-merge/git-rebase-todo.backup") +GIT_PATH_FUNC(rebase_path_todo_backup, "rebase-merge/git-rebase-todo.backup") /* * The rebase command lines that have already been processed. A line diff --git a/sequencer.h b/sequencer.h index c80990659c..b0688ba2a1 100644 --- a/sequencer.h +++ b/sequencer.h @@ -10,6 +10,7 @@ struct repository; const char *git_path_commit_editmsg(void); const char *git_path_seq_dir(void); const char *rebase_path_todo(void); +const char *rebase_path_todo_backup(void); #define APPEND_SIGNOFF_DEDUP (1u << 0) From patchwork Sun Feb 10 13:26:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804797 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 842A314E1 for ; Sun, 10 Feb 2019 13:27:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 747C929F76 for ; Sun, 10 Feb 2019 13:27:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6622029F95; Sun, 10 Feb 2019 13:27:34 +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 10EEC29F76 for ; Sun, 10 Feb 2019 13:27:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726827AbfBJN1c (ORCPT ); Sun, 10 Feb 2019 08:27:32 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55281 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbfBJN11 (ORCPT ); Sun, 10 Feb 2019 08:27:27 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so12204441wmh.4 for ; Sun, 10 Feb 2019 05:27:25 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=lmhlurXZsGsBs2IcDPWEncXOvBp+o8f/ujq4NdZ2avo=; b=UT4MHPxU4suCo2W2e/u7iD01qj6aNjlVhIu8MBlu3+/V1qA/lJ9yZdKFH4ccEsCMRx VXBD7Ef0vPBdp4rMfjyDHFKygZtrhsVyy4Ap2+Y39R+vScyAhQzjzE6/uwn0XQb4IUoj hkySq0OgCwWhMpwm9GhCrDbjV3QcCdQFaRpWrZNMdGlQ+TwzYkyzAI2+xphJRzZ5mYqR g7UMbcyCbUox4EZMFlk4m46x8bb5zPWvGRQfvFkBBhuSHLWxJnc9nMjgCj+ETn7Wxwtz rD8b/wX7wzRKbkhkF9q7L3AA/b1cyZp1k8u7TMIEkMFZYztSLdByKScZEMk8bGxDUN8Q g3pA== 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:mime-version:content-transfer-encoding; bh=lmhlurXZsGsBs2IcDPWEncXOvBp+o8f/ujq4NdZ2avo=; b=bUG3XLyqZLMjZixP9mWFeCLI8JMPAHWN23FZaeGQuAVUA/rV8d9qZtU0bO2sgeYPef IMsfirjbRVLU+VikWuLIICEf958xcDAN/afoOzpYf4mwMxgL51fBKP5Fan+yo8qDYHZN KOvIos8ErCHFaTQEISfdiGTme6PaSQ6mWiEgiUOtcWDo/oecaYknDfRlCvDfuNuy5zDn 7fLrurnqHFVxz/CHPrvvVDeOV16EdUYMYNcxJHQuxLO3cWn2I1N1rgl0CzQO5S0HhksG BYRA1J1NqZqQMbGCZ08Q5SuHl62U1taEB3yPJttH08ql2pZCJMY05S5Es6PbgTiHl9tt fEgw== X-Gm-Message-State: AHQUAuZUYpOvTbKVTZaWsiR9o9QN3Z8BIHUofEy/bUnhyB6mC4JgGe6h 2DQK3g1jNfw4sAo6/tUvy84Rgarx X-Google-Smtp-Source: AHgI3IYLP6hYGpwfD9+WtzwgR2L+YmL99Hjurony/zNNXodT/i+C8mKRtflex2NPX5gQ0G3N6Ohbag== X-Received: by 2002:a5d:67cd:: with SMTP id n13mr9079870wrw.316.1549805244359; Sun, 10 Feb 2019 05:27:24 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:23 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 15/16] sequencer: use edit_todo_list() in complete_action() Date: Sun, 10 Feb 2019 14:26:47 +0100 Message-Id: <20190210132648.12821-16-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 This changes complete_action() to use edit_todo_list(), now that it can handle the initial edit of the todo list. Signed-off-by: Alban Gruin --- No changes since v6. sequencer.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/sequencer.c b/sequencer.c index f6ed4e21e9..df8b239fdc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4765,6 +4765,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla struct todo_list new_todo = TODO_LIST_INIT; struct strbuf *buf = &todo_list->buf; struct object_id oid; + int res; get_oid(onto, &oid); shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); @@ -4789,24 +4790,16 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return error(_("nothing to do")); } - if (todo_list_write_to_file(r, todo_list, todo_file, - shortrevisions, shortonto, -1, - flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) - return error_errno(_("could not write '%s'"), todo_file); - - if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) - return error(_("could not copy '%s' to '%s'."), todo_file, - rebase_path_todo_backup()); - - if (launch_sequence_editor(todo_file, &new_todo.buf, NULL)) { + res = edit_todo_list(r, todo_list, &new_todo, shortrevisions, + shortonto, flags); + if (res == -1) + return -1; + else if (res == -2) { apply_autostash(opts); sequencer_remove_state(opts); return -1; - } - - strbuf_stripspace(&new_todo.buf, 1); - if (new_todo.buf.len == 0) { + } else if (res == -3) { apply_autostash(opts); sequencer_remove_state(opts); todo_list_release(&new_todo); From patchwork Sun Feb 10 13:26:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10804799 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 B1F6614E1 for ; Sun, 10 Feb 2019 13:27:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2D8629F76 for ; Sun, 10 Feb 2019 13:27:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96F0329F95; Sun, 10 Feb 2019 13:27:35 +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 E0B6829F76 for ; Sun, 10 Feb 2019 13:27:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726819AbfBJN1c (ORCPT ); Sun, 10 Feb 2019 08:27:32 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40019 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726634AbfBJN1a (ORCPT ); Sun, 10 Feb 2019 08:27:30 -0500 Received: by mail-wm1-f67.google.com with SMTP id q21so11786057wmc.5 for ; Sun, 10 Feb 2019 05:27:26 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=GyI1/KTY2mSiSd43Sv7znguxqUauw5shFzD3u75E6Yg=; b=pTmagMTuUVgcWdtvsQov0nhL4bXBWNsGhUi5GRF9AaJGRPCgCB07ItdZXVrbQkRx9x yiHWRhrYHJMEZ12V+jqYA57Ji8815RVelQq+9m7XuLANMafrVMi2z50B054PricACFBZ RdirCNtepu0QnlciaSvbqeP+QAaw+ok1vN+P+ZMWozNVY6bvd1TQrIA6bto/izmiy3tM Jgm8wbCE/WpCHaRWQ7ZY1rd8VcCI8KmOwlTe7NSzJf+/fL7j0dya+qVWSNhjiTXSVxKU Wi7pY9a63LnKzLRKTYt0jCn/iRhCBN4w2aEYrUAx7+FoVGAJOOFi0pMTWVHDeq3ZQunC Yngw== 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:mime-version:content-transfer-encoding; bh=GyI1/KTY2mSiSd43Sv7znguxqUauw5shFzD3u75E6Yg=; b=iwZSv7/QkzkAehR1BJQoVZu/5sFEJZrQdLaTxizy7McAgqgW+67u48eHXTWyCrLgNt frjnfwxDVsnDk0jNpcXTdtrte2DZ9/vuZWnk11MwaBB2tsDisy+Xr9BFVjPI2uPhpWEU n/6GWfFaPQgERwDg2J4D+kRgvvif6/Jof7QC377kTAKmypWUBpl9dl37gkPP1wfqiMVB 4D2NVb1hiyaIZ//pV5KDTSqpvpkre5JjygD0XZZrXbjnWhESsBZLArI2W9IFmtqNOepS N6Y287TXyff2skRFSFs41vYICPKAGAPwHsB5MSuyDvOtF5u92JaZecdXrTBY3OrxA4mv yE7w== X-Gm-Message-State: AHQUAubZi3DrfrhwVamQYQtRoOOWpEkI5SLohOEHraWcNYYEynPaCygy m64/bMy2xoYi6hkP5HaASUJDZ7eV X-Google-Smtp-Source: AHgI3IZ+cXq51zGyBF8kLvEPPe0dLxdqQTCGLsBiQlfxxbAo7OlQyzrvnJtbb9gtZ/NiOHdRWvP2Bw== X-Received: by 2002:a1c:c441:: with SMTP id u62mr6351608wmf.69.1549805245544; Sun, 10 Feb 2019 05:27:25 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-21-92.w86-222.abo.wanadoo.fr. [86.222.20.92]) by smtp.googlemail.com with ESMTPSA id z26sm5266314wml.44.2019.02.10.05.27.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Feb 2019 05:27:25 -0800 (PST) From: Alban Gruin To: Git Mailing List Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v7 16/16] rebase--interactive: move several functions to rebase--interactive.c Date: Sun, 10 Feb 2019 14:26:48 +0100 Message-Id: <20190210132648.12821-17-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190210132648.12821-1-alban.gruin@gmail.com> References: <20190129150159.10588-1-alban.gruin@gmail.com> <20190210132648.12821-1-alban.gruin@gmail.com> 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 As sequencer_add_exec_commands(), rearrange_squash_in_todo_file(), and transform_todo_file() are only needed inside of rebase--interactive.c for rebase -p, they are moved there from sequencer.c. The parameter r (repository) is dropped from them, and the error handling of rearrange_squash_in_todo_file() is slightly improved. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 81 +++++++++++++++++++++++++++++++++-- sequencer.c | 79 ++-------------------------------- sequencer.h | 7 ++- 3 files changed, 84 insertions(+), 83 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 370d584683..fb11f23692 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -13,6 +13,81 @@ static GIT_PATH_FUNC(path_state_dir, "rebase-merge/") static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto") static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive") +static int add_exec_commands(struct string_list *commands) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, + &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_add_exec_commands(&todo_list, commands); + res = todo_list_write_to_file(the_repository, &todo_list, + todo_file, NULL, NULL, -1, 0); + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; +} + +static int rearrange_squash_in_todo_file(void) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res = 0; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, + &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + res = todo_list_rearrange_squash(&todo_list); + if (!res) + res = todo_list_write_to_file(the_repository, &todo_list, + todo_file, NULL, NULL, -1, 0); + + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; +} + +static int transform_todo_file(unsigned flags) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, + &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + res = todo_list_write_to_file(the_repository, &todo_list, todo_file, + NULL, NULL, -1, flags); + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; +} + static int edit_todo_file(unsigned flags) { const char *todo_file = rebase_path_todo(); @@ -276,16 +351,16 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) } case SHORTEN_OIDS: case EXPAND_OIDS: - ret = transform_todo_file(the_repository, flags); + ret = transform_todo_file(flags); break; case CHECK_TODO_LIST: ret = check_todo_list_from_file(the_repository); break; case REARRANGE_SQUASH: - ret = rearrange_squash_in_todo_file(the_repository); + ret = rearrange_squash_in_todo_file(); break; case ADD_EXEC: - ret = sequencer_add_exec_commands(the_repository, &commands); + ret = add_exec_commands(&commands); break; default: BUG("invalid command '%d'", command); diff --git a/sequencer.c b/sequencer.c index df8b239fdc..7d35f83f4c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4499,8 +4499,8 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, * Add commands after pick and (series of) squash/fixup commands * in the todo list. */ -static void todo_list_add_exec_commands(struct todo_list *todo_list, - struct string_list *commands) +void todo_list_add_exec_commands(struct todo_list *todo_list, + struct string_list *commands) { struct strbuf *buf = &todo_list->buf; size_t base_offset = buf->len; @@ -4559,30 +4559,6 @@ static void todo_list_add_exec_commands(struct todo_list *todo_list, todo_list->alloc = alloc; } -int sequencer_add_exec_commands(struct repository *r, - struct string_list *commands) -{ - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - todo_list_add_exec_commands(&todo_list, commands); - res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); - todo_list_release(&todo_list); - - if (res) - return error_errno(_("could not write '%s'."), todo_file); - return 0; -} - static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list, struct strbuf *buf, int num, unsigned flags) { @@ -4649,29 +4625,6 @@ int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, return res; } -int transform_todo_file(struct repository *r, unsigned flags) -{ - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - res = todo_list_write_to_file(r, &todo_list, todo_file, - NULL, NULL, -1, flags); - todo_list_release(&todo_list); - - if (res) - return error_errno(_("could not write '%s'."), todo_file); - return 0; -} - static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' " "and then run 'git rebase --continue'.\n" @@ -4754,8 +4707,6 @@ static int skip_unnecessary_picks(struct repository *r, return 0; } -static int todo_list_rearrange_squash(struct todo_list *todo_list); - int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, @@ -4862,7 +4813,7 @@ define_commit_slab(commit_todo_item, struct todo_item *); * message will have to be retrieved from the commit (as the oneline in the * script cannot be trusted) in order to normalize the autosquash arrangement. */ -static int todo_list_rearrange_squash(struct todo_list *todo_list) +int todo_list_rearrange_squash(struct todo_list *todo_list) { struct hashmap subject2item; int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0; @@ -5000,27 +4951,3 @@ static int todo_list_rearrange_squash(struct todo_list *todo_list) return 0; } - -int rearrange_squash_in_todo_file(struct repository *r) -{ - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res = 0; - - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) - return -1; - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { - todo_list_release(&todo_list); - return -1; - } - - res = todo_list_rearrange_squash(&todo_list); - if (!res) - res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); - - todo_list_release(&todo_list); - - if (res) - return error_errno(_("could not write '%s'."), todo_file); - return 0; -} diff --git a/sequencer.h b/sequencer.h index b0688ba2a1..7cca49eff2 100644 --- a/sequencer.h +++ b/sequencer.h @@ -143,15 +143,14 @@ int sequencer_remove_state(struct replay_opts *opts); int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, const char **argv, unsigned flags); -int sequencer_add_exec_commands(struct repository *r, - struct string_list *commands); -int transform_todo_file(struct repository *r, unsigned flags); +void todo_list_add_exec_commands(struct todo_list *todo_list, + struct string_list *commands); int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash, struct todo_list *todo_list); -int rearrange_squash_in_todo_file(struct repository *r); +int todo_list_rearrange_squash(struct todo_list *todo_list); extern const char sign_off_header[];