From patchwork Fri Nov 9 08:07:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675461 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 EBB29175A for ; Fri, 9 Nov 2018 08:08:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEF0A2DBE5 for ; Fri, 9 Nov 2018 08:08:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D29462DDE2; Fri, 9 Nov 2018 08:08: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 80E042DBE5 for ; Fri, 9 Nov 2018 08:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbeKIRr6 (ORCPT ); Fri, 9 Nov 2018 12:47:58 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37994 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRr6 (ORCPT ); Fri, 9 Nov 2018 12:47:58 -0500 Received: by mail-wm1-f67.google.com with SMTP id f2-v6so1076555wme.3 for ; Fri, 09 Nov 2018 00:08:32 -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=XaRItsr0/AQnDuDwZ2VKpF1bK7lMEDMF6L9h5lxR2nI=; b=pz8BeTN1m5XVnk8BdqogvVdaAhNMa5lmwuRDFuunnVwpzY5AwumPIjX7T4RDxYw0VJ ga+/e139S53JxfVd8EfW0e/aU2Z0xcw1TYd2KRpDUbJBwx1/z7eVeigTxeGbqil5i0Cw GjJDLL+e1YIDoljvBrFrkP9U687i1FqvqNKUQKrRrwWWYS6o2pylVlsfQMhlEbfkKtHO QZn2Fhjp4RLwaSX5xBVR7JdyN8rHDbczooCwCAd906Tm0Qp+PP1SlWTN5Kb1K1knA80a USjEmuKLW3pr6xX+JA4IqXBLxN36jM1jEGTYdytFbZTbDaT4MmLrsuvuhkDNx41Zs6jL Z+Uw== 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=XaRItsr0/AQnDuDwZ2VKpF1bK7lMEDMF6L9h5lxR2nI=; b=fG26iUZ87dLLXcTRtJBbGXkWz6WLlCGJuyWucB7gjQ4gsaCixHN11JSLsJsQQkiQ3Q +DeHDp7SRM0ATmR+Q1SAfX+HDODBmQpdArLqc86qyfXa3ZSLFDvCiGPvb+NlMUn1JHa/ jYxIR68tnti1lZL8D1gk8gVCa1LxPtPCI5MRMey6Jm3efwrF1COl64lpAMRLSiZWix8v fpgpfQwHUYzkmWuIxBmclCPqr3CEDDbDbfcGF3tO/ELoxsQgEltipWbTraAYY87QhPke kTY+bRYI1IOiadKRLPff/nIvkftWQEvTFfGBEJCAZT/7Tajv/HN2HaeXxkHzeTAJwcuD FDDg== X-Gm-Message-State: AGRZ1gLqaifg6szk1OOcXPxy+b/9hWvTYY+cXniEuChlBtyf4TVizJKm fjFv5ABx8zAQvlNbonB026AGVu2E X-Google-Smtp-Source: AJdET5ddSmQEfATCqJ2Hee6OdulY0J9C02piqR1dlpe8ecPe4/Q8+CwuSHCdH7lEZVwF9TxoC0Y9WQ== X-Received: by 2002:a1c:b513:: with SMTP id e19-v6mr3704008wmf.114.1541750911208; Fri, 09 Nov 2018 00:08:31 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:30 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 01/16] sequencer: changes in parse_insn_buffer() Date: Fri, 9 Nov 2018 09:07:50 +0100 Message-Id: <20181109080805.6350-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 v2. sequencer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 9e1ab3a2a7..07cc91d8db 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2066,6 +2066,8 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list) 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'); @@ -2079,7 +2081,10 @@ static int parse_insn_buffer(char *buf, struct todo_list *todo_list) if (parse_insn_line(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 Fri Nov 9 08:07:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675495 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 5015814BD for ; Fri, 9 Nov 2018 08:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41F642E29C for ; Fri, 9 Nov 2018 08:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 368932E4C1; Fri, 9 Nov 2018 08:09:01 +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 9B4712E29C for ; Fri, 9 Nov 2018 08:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728485AbeKIRsX (ORCPT ); Fri, 9 Nov 2018 12:48:23 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35603 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728165AbeKIRr7 (ORCPT ); Fri, 9 Nov 2018 12:47:59 -0500 Received: by mail-wm1-f67.google.com with SMTP id t15-v6so1093383wmt.0 for ; Fri, 09 Nov 2018 00:08:33 -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=FcjhqDLWqeSOFhuzUuhqeT3vuOH78r9kJ6FN+M08c3w=; b=D3nwBKDriYFQCrHCJ2EYyyAKASmNfvcPvHa+NjsCt3NPPAOIAspfFsKIXmxwtlXK3C Nudi2M/X9pS0SVR37Xm/RdVREPSk+NwXt93FgvHLtkLFgXCRLAqCJHz1YGfz5zuWZzqT TIDOJQU/6aKrgKvPQJwwu/Zlb5HjO3UKT8t/X9pFF/mquF9YUw3as5EGtqDxbGbSpa7o tGydOEynwoE+g2h82J1wXXMO1CUwZ1WgxPhX4woPU1WCtSWI2b/MFRzp1RvJ5Ldd31ET rwBB1fE7CqWRMv9XjiFUZHtF3eEnXPzQv8n1fXWi86hQdV5Pc8kg757y0D91fueMHjhh aeww== 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=FcjhqDLWqeSOFhuzUuhqeT3vuOH78r9kJ6FN+M08c3w=; b=m+UymS4REBu3soV/HNOks0mVg6KezOKltSdZLRG1lq2l0+JAQTp8M51TnkRrC6CBRK xxCJ9N69vk4X7UxyJqnY3EudsTU0Cg6KeYY3Y7OQc6RK6bhcGZoY9ZXfZkE7FJDVjW+V NvsKDiistob/GDy++vQSTQrALSy9MoY23Oy+AJ/bpUVvKGhoryvYGg3A1CATNzvNx8B5 jfPOPsohfMSPN4/DBZxdHQnU7COkw2vmsvs3NVID8+UzKKmTEdqwjrCDyUfgbFaRVN6r kdWKEsp8vnwnodv6U7Rvtg0Yga4IOqC4eENrjoCfxzD2yfAdlGbB2vt7WaEPtOXmasDk j6Mg== X-Gm-Message-State: AGRZ1gLmyuP2LLDgscR9ty7m35Cz9PJpzrIT0X+7UT4gCTKnDBnJe+WL 0K7WUfGMHjk6FHiP7NMHMj1VZShO X-Google-Smtp-Source: AJdET5e0kfd1LGKYFvI89nQPfiEj+b+qL9DQMZsoVXNBezVP81Dk/cAcdYGTyvDm7uuFYt/BydTzrQ== X-Received: by 2002:a1c:ee0c:: with SMTP id m12-v6mr3932529wmh.75.1541750912390; Fri, 09 Nov 2018 00:08:32 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:31 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 02/16] sequencer: make the todo_list structure public Date: Fri, 9 Nov 2018 09:07:51 +0100 Message-Id: <20181109080805.6350-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 --- sequencer.c | 67 +++++++++-------------------------------------------- sequencer.h | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/sequencer.c b/sequencer.c index 07cc91d8db..7adbeaa27d 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1443,32 +1443,6 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit) 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; @@ -1939,26 +1913,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); @@ -2060,7 +2015,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) return !item->commit; } -static int parse_insn_buffer(char *buf, struct todo_list *todo_list) +int todo_list_parse_insn_buffer(char *buf, struct todo_list *todo_list) { struct todo_item *item; char *p = buf, *next_p; @@ -2158,7 +2113,7 @@ static int read_populate_todo(struct todo_list *todo_list, return error(_("could not stat '%s'"), todo_file); fill_stat_data(&todo_list->stat, &st); - res = parse_insn_buffer(todo_list->buf.buf, todo_list); + res = todo_list_parse_insn_buffer(todo_list->buf.buf, todo_list); if (res) { if (is_rebase_i(opts)) return error(_("please fix this using " @@ -2189,7 +2144,7 @@ static int read_populate_todo(struct todo_list *todo_list, FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w"); if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 && - !parse_insn_buffer(done.buf.buf, &done)) + !todo_list_parse_insn_buffer(done.buf.buf, &done)) todo_list->done_nr = count_commands(&done); else todo_list->done_nr = 0; @@ -4454,7 +4409,7 @@ int sequencer_add_exec_commands(const char *commands) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4510,7 +4465,7 @@ int transform_todos(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(todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4596,7 +4551,7 @@ int check_todo_list(void) goto leave_check; } advise_to_edit_todo = res = - parse_insn_buffer(todo_list.buf.buf, &todo_list); + todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list); if (res || check_level == MISSING_COMMIT_CHECK_IGNORE) goto leave_check; @@ -4615,7 +4570,7 @@ int check_todo_list(void) goto leave_check; } strbuf_release(&todo_file); - res = !!parse_insn_buffer(todo_list.buf.buf, &todo_list); + res = !!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list); /* Find commits in git-rebase-todo.backup yet unseen */ for (i = todo_list.nr - 1; i >= 0; i--) { @@ -4697,7 +4652,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } @@ -4785,7 +4740,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, if (strbuf_read_file(buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(buf->buf, &todo_list)) { + if (todo_list_parse_insn_buffer(buf->buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4893,7 +4848,7 @@ int rearrange_squash(void) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } diff --git a/sequencer.h b/sequencer.h index 660cff5050..84f813305f 100644 --- a/sequencer.h +++ b/sequencer.h @@ -72,6 +72,55 @@ 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(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 replay_opts *opts); From patchwork Fri Nov 9 08:07:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675465 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 ABF5714BD for ; Fri, 9 Nov 2018 08:08:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CC772DBE5 for ; Fri, 9 Nov 2018 08:08:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 906ED2DDE2; Fri, 9 Nov 2018 08:08:39 +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 055B42DBE5 for ; Fri, 9 Nov 2018 08:08:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728429AbeKIRsB (ORCPT ); Fri, 9 Nov 2018 12:48:01 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:51711 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsB (ORCPT ); Fri, 9 Nov 2018 12:48:01 -0500 Received: by mail-wm1-f66.google.com with SMTP id w7-v6so1121519wmc.1 for ; Fri, 09 Nov 2018 00:08:34 -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=Exp+mu6XuVwmjhpACiZNnBEtgTwuzf1zzqw7njFsWDI=; b=jiPUVH2YMQZD2PAFqDyXzV/OvLGQ7+RKVsn+Maz49FYb51aFDSD3v5bSVWvaeVX+R9 wj8rDtiXqL33lE9AF1TPq3HNs6HijWRKV3j38kyzOIeK06Qv8ybGY41fdsTJX9gHmJ/o Fh5fsEdUBMa/2oV+WXEgT5aYIiUZb/JPk9omqqm+90tfLGOx7c6i+4akNEx/8aqyoaYd 6GtBirTUYUyJKWLjtSptUq3QjoS2eGL2Gl62BUcXuYHRbvTcb1jDnxrq8BYGp56VdGeT X0spqDFSR0mzsvLiJRjWfBofClGdX0zuPR74BNey3mqU2lbt6+iE1WCrDDQe5+AsP5uz zdvQ== 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=Exp+mu6XuVwmjhpACiZNnBEtgTwuzf1zzqw7njFsWDI=; b=ucuP+svWUO3bwvh7oMC0FG5OIQ82B9tCApDmecjYVoDACSEjwIDkeswI+1Rnuj/4Sl wTaf7ygfY1TVwbJ8NanHtF7BRa9IyyoUqk77nRiM4vFoG3QCnx3tFEb5ecl9T5N8ZCTz xbPbdpPyYVOG6eom3CgBL8sxWL6p2RmNXAhfvKK+kiAmjk50b9UC+YSDaIEFw2xEEbKD uLzt5CU4SK8R/e4qHcUyiCUsUgQLGVEGH5pHj0yxlAVH6aH4g/5lKKYDeT/6Zk7ykDcg deJb9arX8/6nylnrwgl515N9U9qinO5S6yI+c9YLm2h3eOm0VApNx3upd4OSZCuEnItZ nY9g== X-Gm-Message-State: AGRZ1gJis9dGWdegbc0J7FiBt7gcrr7fyhsAqrhPLpFA0tSqo2QU9jXc 9KagzFf32xZx07iv2KASYG/nwQKA X-Google-Smtp-Source: AJdET5dt0nXYpaM0HYP3RTUK0ZAdrJ6xBxnvWUKWR5a8E+iJXJ2shjHT2O/EZ6ydAb6S4LcTfzkXUw== X-Received: by 2002:a1c:a4c5:: with SMTP id n188-v6mr3738159wme.149.1541750913460; Fri, 09 Nov 2018 00:08:33 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:32 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 03/16] sequencer: refactor transform_todos() to work on a todo_list Date: Fri, 9 Nov 2018 09:07:52 +0100 Message-Id: <20181109080805.6350-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 v2. builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 4 +-- sequencer.c | 46 +++++++++++++++++++++++------------ sequencer.h | 3 ++- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index a2ab68ed06..abdf6126df 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -252,7 +252,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) } case SHORTEN_OIDS: case EXPAND_OIDS: - ret = transform_todos(flags); + ret = transform_todo_file(flags); break; case CHECK_TODO_LIST: ret = check_todo_list(); diff --git a/rebase-interactive.c b/rebase-interactive.c index 78f3263fc1..4cd487a450 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -69,7 +69,7 @@ int edit_todo_list(unsigned flags) strbuf_release(&buf); - transform_todos(flags | TODO_LIST_SHORTEN_IDS); + transform_todo_file(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(unsigned flags) if (launch_sequence_editor(todo_file, NULL, NULL)) return -1; - transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)); + transform_todo_file(flags & ~(TODO_LIST_SHORTEN_IDS)); return 0; } diff --git a/sequencer.c b/sequencer.c index 7adbeaa27d..e1097660ed 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4454,23 +4454,13 @@ int sequencer_add_exec_commands(const char *commands) return i; } -int transform_todos(unsigned flags) +void todo_list_transform(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(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, item->arg); @@ -4506,9 +4496,33 @@ int transform_todos(unsigned flags) strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg); } - 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(todo_list->buf.buf, todo_list)) + BUG("unusable todo list"); +} + +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(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_transform(&todo_list, flags); + + res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); todo_list_release(&todo_list); - return i; + return res; } enum missing_commit_check_level get_missing_commit_check_level(void) @@ -4769,7 +4783,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, return error(_("could not copy '%s' to '%s'."), todo_file, rebase_path_todo_backup()); - if (transform_todos(flags | TODO_LIST_SHORTEN_IDS)) + if (transform_todo_file(flags | TODO_LIST_SHORTEN_IDS)) return error(_("could not transform the todo list")); strbuf_reset(buf); @@ -4798,7 +4812,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, return -1; } - if (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS))) + if (transform_todo_file(flags & ~(TODO_LIST_SHORTEN_IDS))) return error(_("could not transform the todo list")); if (opts->allow_ff && skip_unnecessary_picks(&oid)) diff --git a/sequencer.h b/sequencer.h index 84f813305f..708d042f0e 100644 --- a/sequencer.h +++ b/sequencer.h @@ -119,6 +119,7 @@ struct todo_list { #define TODO_LIST_INIT { STRBUF_INIT } int todo_list_parse_insn_buffer(char *buf, struct todo_list *todo_list); +void todo_list_transform(struct todo_list *todo_list, unsigned flags); void todo_list_release(struct todo_list *todo_list); /* Call this to setup defaults before parsing command line options */ @@ -142,7 +143,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, unsigned flags); int sequencer_add_exec_commands(const char *command); -int transform_todos(unsigned flags); +int transform_todo_file(unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(void); int complete_action(struct replay_opts *opts, unsigned flags, From patchwork Fri Nov 9 08:07:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675467 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 539DB14D6 for ; Fri, 9 Nov 2018 08:08:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44DBF2DDDF for ; Fri, 9 Nov 2018 08:08:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38C5A2DDE2; Fri, 9 Nov 2018 08:08:40 +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 A30AA2DDE7 for ; Fri, 9 Nov 2018 08:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbeKIRsD (ORCPT ); Fri, 9 Nov 2018 12:48:03 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43830 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728149AbeKIRsC (ORCPT ); Fri, 9 Nov 2018 12:48:02 -0500 Received: by mail-wr1-f68.google.com with SMTP id y3-v6so863270wrh.10 for ; Fri, 09 Nov 2018 00:08:35 -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=2ku71qVJ4yxIlk/6G/410hieRxMM2wBBBShfL/msCgo=; b=Gjh1o68RJnmZ433gjJCCVt0d+0hsCOPRuQ2FluJCIoXDbY/MSO56+N8DPctTNjdOyh 6v90gQz3RlgRJogsMaPyB0ULGxibCKs3xdif1nzVTStazUFEPKqQFCxs7hv+rnTnFF11 XDhcZEaJxdzScpxZHi7jyTYeNLNs1tK+mIupSkbOZSVq2qVO36CTcF0P2oh1eRqPVlq1 /OQJBV7putdwnqUKDf2ntdkZ0KW6vkvtXmMCBHFKKVK79uixVkssWrXykxrR5Rf34Edw rFRSBbhs0VLioP8dP5uIbkeIl+rdyiuF3cchcb1QUAd6X1Yk3lvSURv7GrHoNt9iXHKT oYxg== 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=2ku71qVJ4yxIlk/6G/410hieRxMM2wBBBShfL/msCgo=; b=jwgtsMuzJVJrxOHpsP+oEZTOeA+EP7V46PyvS7cPWX5r+1xEPKCsYlRbxl6/HdJ0K2 quccjJ3CyN/FKzLrlUMAcO2qyYTrYFxO8ARAzybDKUqzl1zI28Q44qc3dJry0qbPb7VB qGnVFmDwrxlcAPbBIpDMoRZgUv86vPLQIZ8rx2jd2CfPIWVjMZIH/dbPB82uPFa0poZd 4n8s6pH1TqLrLf7akKkQfc8NgAH2hd7HmZx4pCByGi6S2/U8/tyy73l37mpwEZ9MziU/ yBZ9BppiOSxWOGbj7pCokhy3q4mwc2W4hp/jYgLakC97BlWpKt8r1/qHm26mZmuwoI3K RomQ== X-Gm-Message-State: AGRZ1gJc2j0APUbMSbAAgl3FB+7e6Rs9gl/hDmeSlu87K4CPuRF19lY8 lk1BQ76dW+bNNkKwFa0hluwYRHys X-Google-Smtp-Source: AJdET5c34VFPgvpv7BPPfPk11HvZLBilRq8NLRtpaDsTwUkDoPgsXdLVjo6dCsaM6TraZpebh+YT4Q== X-Received: by 2002:a5d:4dc2:: with SMTP id f2-v6mr7463460wru.45.1541750914784; Fri, 09 Nov 2018 00:08:34 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:34 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 04/16] sequencer: introduce todo_list_write_to_file() Date: Fri, 9 Nov 2018 09:07:53 +0100 Message-Id: <20181109080805.6350-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 can already be found in todo_list_transform(), but it is specifically made to replace the buffer of a todo list, which is not the desired behaviour. Thus, the part of todo_list_transform() that actually creates the buffer is moved to a new function, todo_list_to_strbuf(). The rest is unused, and so is dropped. 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 --- sequencer.c | 60 ++++++++++++++++++++++++++++++++++++----------------- sequencer.h | 6 +++++- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/sequencer.c b/sequencer.c index e1097660ed..19f24825d4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4454,24 +4454,27 @@ int sequencer_add_exec_commands(const char *commands) return i; } -void todo_list_transform(struct todo_list *todo_list, unsigned flags) +static void todo_list_to_strbuf(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, item->arg); + strbuf_addf(buf, "%.*s\n", item->arg_len, item->arg); 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) { @@ -4481,27 +4484,47 @@ void todo_list_transform(struct todo_list *todo_list, unsigned flags) 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, item->arg); + strbuf_addf(buf, " %.*s\n", item->arg_len, item->arg); } +} - strbuf_reset(&todo_list->buf); - strbuf_add(&todo_list->buf, buf.buf, buf.len); +int todo_list_write_to_file(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(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(todo_list->buf.buf, todo_list)) - BUG("unusable todo list"); + return res; } int transform_todo_file(unsigned flags) @@ -4518,9 +4541,8 @@ int transform_todo_file(unsigned flags) return error(_("unusable todo list: '%s'"), todo_file); } - todo_list_transform(&todo_list, flags); - - res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); + res = todo_list_write_to_file(&todo_list, todo_file, + NULL, NULL, -1, flags); todo_list_release(&todo_list); return res; } diff --git a/sequencer.h b/sequencer.h index 708d042f0e..e69357c95b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -119,7 +119,9 @@ struct todo_list { #define TODO_LIST_INIT { STRBUF_INIT } int todo_list_parse_insn_buffer(char *buf, struct todo_list *todo_list); -void todo_list_transform(struct todo_list *todo_list, unsigned flags); +int todo_list_write_to_file(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); /* Call this to setup defaults before parsing command line options */ @@ -139,6 +141,8 @@ 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) +#define TODO_LIST_APPEND_TODO_HELP (1U << 5) + int sequencer_make_script(FILE *out, int argc, const char **argv, unsigned flags); From patchwork Fri Nov 9 08:07:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675469 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 809B914D6 for ; Fri, 9 Nov 2018 08:08:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72CB32DDDF for ; Fri, 9 Nov 2018 08:08:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66B9C2DDE7; Fri, 9 Nov 2018 08:08:41 +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 6249C2DDDF for ; Fri, 9 Nov 2018 08:08:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728437AbeKIRsE (ORCPT ); Fri, 9 Nov 2018 12:48:04 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39399 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsE (ORCPT ); Fri, 9 Nov 2018 12:48:04 -0500 Received: by mail-wr1-f65.google.com with SMTP id b13so853767wrx.6 for ; Fri, 09 Nov 2018 00:08:37 -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=u3VYcESaxXgHqrsaUyBUzqqRB3MjMQeJV2FA45RMPgQ=; b=k8ut6kLUXT40LhZxsyqLG5zBOx2dKfLZyP5e2yvs6x5JielpdXJrwHCd4dU3pFKGCD DTlVPH2r1KpV+sGYoDkP99dHMLm2/GJ06J5+h7FhPwRDGCFuykdt/Bqg84RC0Gl0qphw yPGb902FBNuAg5yczB7s35F5/EO8TmJETqJt6D+ZSZTdjKzB32tf4loQ/PQTvVIKTF4k ErzoGq7fvxXfIQVjyi4BcnIgkNgmExon6vhqGynQJV9CiPP/Et7A0EhrW2007KwIiwSQ N0NJT/+q0Xk7ROUVtV1enGhjyTFALZ/cG5i8fWtozboVSfahVxomPFjaEJySD9/kJILR NZsA== 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=u3VYcESaxXgHqrsaUyBUzqqRB3MjMQeJV2FA45RMPgQ=; b=WFdvik3N/WnrvRetR8RVtt+llFxcKRSkiQ8pXnt0gaE3WhX4rkbQJkgBaVa4QDHT8W n68aJOWoLymaAVSVxSWchy2o4NbeeSItEXEwaK7FZLxQwcdUQw2NGhAkEU2VEnKFS7ry P0muh/3uMvFTnV+l7QTZc4/rFU2CkYfSYJZnlwICtUipCqh6DBPOyHfYuO1ud7RXouob HVKZnWpG1zq/5DxuYr1JILo1YlyvDHBX/+ayPv+fTTTd8bB40qCq/wBsXv/JQipo7qEG kVnT/rTa+3MaKe41kIKNVtE4FeR+C1PCWRopkjgNrY0l/j8T95bUKHtllO5VT3V/fHs3 MhAA== X-Gm-Message-State: AGRZ1gK8beiupvnqo1UMbGMefwA9TrBYOv75R6+q+gjvgbOyu/QQOoYb 0UwY2PCW6p6WDjTUVV5J4n1ANDDO X-Google-Smtp-Source: AJdET5d82sGB7+R+zIb+eGh3mtAuVkK3P1xG4QsKuDHv+B0W19nWDD1KSa4sUEdNq/FceTktZ8br0w== X-Received: by 2002:adf:ded1:: with SMTP id i17-v6mr7104621wrn.307.1541750916433; Fri, 09 Nov 2018 00:08:36 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:35 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 05/16] sequencer: refactor check_todo_list() to work on a todo_list Date: Fri, 9 Nov 2018 09:07:54 +0100 Message-Id: <20181109080805.6350-6-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 v2. builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 90 ++++++++++++++++++++++++- rebase-interactive.h | 1 + sequencer.c | 120 +++++++--------------------------- sequencer.h | 9 +-- 5 files changed, 115 insertions(+), 107 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index abdf6126df..c1d87c0fe6 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -255,7 +255,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = transform_todo_file(flags); break; case CHECK_TODO_LIST: - ret = check_todo_list(); + ret = check_todo_list_from_file(); break; case REARRANGE_SQUASH: ret = rearrange_squash(); diff --git a/rebase-interactive.c b/rebase-interactive.c index 4cd487a450..3adcf39e07 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,67 @@ int edit_todo_list(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, item->arg); + *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 971da03776..6bc7bc315d 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -4,5 +4,6 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty, struct strbuf *buf); int edit_todo_list(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 19f24825d4..900899ef20 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4547,111 +4547,37 @@ int transform_todo_file(unsigned flags) return res; } -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(void) +int check_todo_list_from_file(void) { - 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(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(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, item->arg); - *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(old_todo.buf.buf, &old_todo); + if (!res) + res = todo_list_parse_insn_buffer(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; } @@ -4829,7 +4755,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, todo_list_release(&todo_list); - if (check_todo_list()) { + if (check_todo_list_from_file()) { checkout_onto(opts, onto_name, onto, orig_head); return -1; } diff --git a/sequencer.h b/sequencer.h index e69357c95b..c78f00aadd 100644 --- a/sequencer.h +++ b/sequencer.h @@ -63,12 +63,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); @@ -148,8 +142,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, int sequencer_add_exec_commands(const char *command); int transform_todo_file(unsigned flags); -enum missing_commit_check_level get_missing_commit_check_level(void); -int check_todo_list(void); +int check_todo_list_from_file(void); int complete_action(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 Fri Nov 9 08:07:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675471 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 B1C2E14BD for ; Fri, 9 Nov 2018 08:08:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A39802DDDF for ; Fri, 9 Nov 2018 08:08:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 977D12DDE7; Fri, 9 Nov 2018 08:08:42 +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 D3D462DDDF for ; Fri, 9 Nov 2018 08:08:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728444AbeKIRsF (ORCPT ); Fri, 9 Nov 2018 12:48:05 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42902 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728149AbeKIRsF (ORCPT ); Fri, 9 Nov 2018 12:48:05 -0500 Received: by mail-wr1-f67.google.com with SMTP id y15-v6so865162wru.9 for ; Fri, 09 Nov 2018 00:08:38 -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=nb4AJRXGh2qNyydiwDl3R1Gk3/8v2N+Z3YmaNoiVVOU=; b=KbwmpThbfFmauYhzjdUABe4S2JQd1WJOKAJ6s6mpRUNB6bkQXQ50FFs5EoCuQxJxUW hOcdJ8kuqDaa5n6DjXG+OslFrbQ7NxM1mL8XMfCq8PjoZ+dXZEFR8a28YwZxq/SgtyiN BKpxIR8Go6/VqNdMW3TZR510CZnqiMTu2j037Xc0wxFJXyml8kkpW1rrgCMCJDMFAK2o RBN4ETYg+5g3BXm7BzodiUi5S1SKdL/j//UFCN0wNFEQ5qVp29jogJQn+5mo3uagpOhD LHOeJ+j4d2IxCnzw8oxtTnTFw5CX0H61fgdmLN0Oiz6K3rcMSOCnjMxXsZN/MdXf0IK3 4A4g== 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=nb4AJRXGh2qNyydiwDl3R1Gk3/8v2N+Z3YmaNoiVVOU=; b=lxJ+RXLLCYTo/X9jVSzfrZk9frPRjend4hGOfeT2jrtl8i/9aGKieF4WNSZbh9JOvx a1VKusR0rgVTp2QcSrQJtLCKutqMYZffqUQwFmoTANbaqECdP5BJjEyjd4M+AZK6qqSJ QQfN8yYvqEtgQvav+INTUFfpibCti+2kF54tqdNODfQXOj/Hm+JPid2Mgatc8imsK7Xe hLT/t96PRhZ1NyCZHQMNWpk0UNz7RHxbb9kyC3CZV1tRITEBfFAsnMT83oY35zfZCfDY Gsdk9eNdKP6TSQf4poW4jQ+c2vg2+9WUfEFdYe4CW7nPsjRZ91SWJ5bOkL4uQ5RAUPgo MdEA== X-Gm-Message-State: AGRZ1gJ6E9HfFuab9ZBifVGoOYTUuApwQH/SuzAXoURvJQJnhb64qUBG Jkan3XCv6++WIy5itkUJbtuJgEB9 X-Google-Smtp-Source: AJdET5fFYRjHvi3rVK+nVHkwdhXR2OCuWX9ostU9ohclYLfBXJvAYm6vzmZ8DS9Sy4bhLlH8SweA2w== X-Received: by 2002:a5d:4682:: with SMTP id u2-v6mr6816430wrq.39.1541750917615; Fri, 09 Nov 2018 00:08:37 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:37 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 06/16] sequencer: refactor sequencer_add_exec_commands() to work on a todo_list Date: Fri, 9 Nov 2018 09:07:55 +0100 Message-Id: <20181109080805.6350-7-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 just inserting the `exec' command between the other commands, and re-parsing the buffer at the end the exec command is 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 | 111 +++++++++++++++++++++------------- sequencer.h | 4 +- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index c1d87c0fe6..1fb5a43c0d 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; @@ -115,7 +115,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, else { discard_cache(); ret = complete_action(opts, flags, shortrevisions, onto_name, onto, - head_hash, cmd, autosquash); + head_hash, commands, autosquash); } free(revisions); @@ -138,6 +138,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, @@ -220,6 +221,12 @@ 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); + if (strlen(commands.items[commands.nr - 1].string) == 0) + --commands.nr; + } + switch (command) { case NONE: if (!onto && !upstream) @@ -227,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; @@ -261,7 +268,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = rearrange_squash(); break; case ADD_EXEC: - ret = sequencer_add_exec_commands(cmd); + ret = sequencer_add_exec_commands(&commands); break; default: BUG("invalid command '%d'", command); diff --git a/sequencer.c b/sequencer.c index 900899ef20..11692d0b98 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4394,24 +4394,29 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, return 0; } -/* - * Add commands after pick and (series of) squash/fixup commands - * in the todo list. - */ -int sequencer_add_exec_commands(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; + const char *old_buf = buf->buf; + size_t base_length = 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); + for (i = 0; i < commands->nr; ++i) { + strbuf_addstr(buf, commands->items[i].string); + strbuf_addch(buf, '\n'); + } - if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%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) - strlen("exec "); + + base_items[i].command = TODO_EXEC; + base_items[i].offset_in_buf = base_length + strlen("exec "); + base_items[i].arg = buf->buf + base_items[i].offset_in_buf; + base_items[i].arg_len = command_len; + base_length = base_items[i].offset_in_buf + base_items[i].arg_len + 1; } /* @@ -4420,38 +4425,62 @@ int sequencer_add_exec_commands(const char *commands) * 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; + for (i = 0; i < todo_list->nr; i++) { + enum todo_command command = todo_list->items[i].command; + if (todo_list->items[i].arg) + todo_list->items[i].arg = todo_list->items[i].arg - old_buf + buf->buf; + + if (insert >= 0 && command != TODO_COMMENT && !is_fixup(command)) { + ALLOC_GROW(items, nr + commands->nr, alloc); + COPY_ARRAY(items + nr, base_items, commands->nr); + nr += commands->nr; insert = -1; } - if (command == TODO_PICK || command == TODO_MERGE) + ALLOC_GROW(items, nr + 1, alloc); + items[nr++] = todo_list->items[i]; + + if (command == TODO_PICK || command == TODO_MERGE || is_fixup(command)) insert = i + 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 >= 0 || 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; +} + +/* + * Add commands after pick and (series of) squash/fixup commands + * in the todo list. + */ +int sequencer_add_exec_commands(struct string_list *commands) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; - i = write_message(buf->buf, buf->len, todo_file, 0); + 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(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(&todo_list, todo_file, NULL, NULL, -1, 0); todo_list_release(&todo_list); - return i; + + return res; } static void todo_list_to_strbuf(struct todo_list *todo_list, struct strbuf *buf, @@ -4677,7 +4706,7 @@ static int skip_unnecessary_picks(struct object_id *output_oid) int complete_action(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(); @@ -4696,8 +4725,8 @@ int complete_action(struct replay_opts *opts, unsigned flags, if (autosquash && rearrange_squash()) return -1; - if (cmd && *cmd) - sequencer_add_exec_commands(cmd); + if (commands->nr) + sequencer_add_exec_commands(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 c78f00aadd..d7b52044bd 100644 --- a/sequencer.h +++ b/sequencer.h @@ -140,12 +140,12 @@ int sequencer_remove_state(struct replay_opts *opts); int sequencer_make_script(FILE *out, int argc, const char **argv, unsigned flags); -int sequencer_add_exec_commands(const char *command); +int sequencer_add_exec_commands(struct string_list *commands); int transform_todo_file(unsigned flags); int check_todo_list_from_file(void); int complete_action(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(void); From patchwork Fri Nov 9 08:07:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675473 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 A713714D6 for ; Fri, 9 Nov 2018 08:08:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 998B12DDE2 for ; Fri, 9 Nov 2018 08:08:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DEC92DDF5; Fri, 9 Nov 2018 08:08:44 +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 E7B492DDE2 for ; Fri, 9 Nov 2018 08:08:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728452AbeKIRsH (ORCPT ); Fri, 9 Nov 2018 12:48:07 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39589 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsH (ORCPT ); Fri, 9 Nov 2018 12:48:07 -0500 Received: by mail-wm1-f67.google.com with SMTP id u13-v6so1076421wmc.4 for ; Fri, 09 Nov 2018 00:08:39 -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=3tfZ307nRgyEqbmBve6NkVsC8BXVcagI217eUrJjje0=; b=uQJs2jIdi8iUlQHEvU/9wMmtfomZHtUT7YJWl3/MJ1cX+N4uzw7N4OIzxQwouW0Clr +ZdkLMn0zO341F54QFc9PSvQN3umYaCkRlQJNHsnm6+jyYmlV3h0jRaKuz2PJkLxD8SM GTABn/8PqKuqNqmEaDbDhJnS5yxJ14AQz42G5RyEcW/Emnop3VtZz/pLbysDL4DGFu84 ivG86kS8zUNf/Se2bgpZxxOsCS06qv0+z4nD9QPCqPuoZCqEbf07TVrxBCR8h0/jd6Vk SMtA6/lvi4/ZOxqSzeQNZIWBspug8xJCtiyV5s4fDs/3lqV/l/9c7rFoM3eExR4tusX5 abLg== 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=3tfZ307nRgyEqbmBve6NkVsC8BXVcagI217eUrJjje0=; b=Xv2apq7YCmnwQQycFCv4bkKaoB7+reUh0U7Z5nmMQ715k67gGHIYEFLhiy0Z5zdVBv c8d3T4dN4qR9wfAk6gsF0zfNa5haYOH0t/tRLorkhGwS0wlFl/CnrzgyRApHbvK1kOX+ 4V4ESGhEQqD73J0r7Jh7toPRit3fBzzWliA9+8Za0d303BB6nimTV4U57GTcs6lk5rc3 m0dv7JufnX4oUmBDH81Uc7S+fGqj9nafr/BNR7/9MEepaEC3IlO3VJFoFA2Zrrd5kSTd 0qPOvp6N1CboqUY1Xoi2xCO078OScJ+NGVVhAauqxL1HDkIO7fcc2wvePjQDmkbuxblt +Nsg== X-Gm-Message-State: AGRZ1gJiwmuxAXE/C4Sx/0CF6DWUHb0PPkOcHcVwk7v+vDXqfCWq2rWf JebtshZPSSckUC1weQZ0YdmDnvhT X-Google-Smtp-Source: AJdET5du5NKvC7marS6Bbdp7A/Um70PZBarSXgA7tUA5ZuwkssMlilhZsZlz50UhITSQ9V6gprCf4g== X-Received: by 2002:a1c:3491:: with SMTP id b139-v6mr3468006wma.99.1541750918638; Fri, 09 Nov 2018 00:08:38 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:38 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 07/16] sequencer: refactor rearrange_squash() to work on a todo_list Date: Fri, 9 Nov 2018 09:07:56 +0100 Message-Id: <20181109080805.6350-8-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 memcpying 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 --- builtin/rebase--interactive.c | 2 +- sequencer.c | 87 +++++++++++++++++------------------ sequencer.h | 2 +- 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 1fb5a43c0d..a6d83a684e 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(); break; case REARRANGE_SQUASH: - ret = rearrange_squash(); + ret = rearrange_squash_in_todo_file(); break; case ADD_EXEC: ret = sequencer_add_exec_commands(&commands); diff --git a/sequencer.c b/sequencer.c index 11692d0b98..fce97e5f11 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4722,7 +4722,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, write_message("noop\n", 5, todo_file, 0)) return -1; - if (autosquash && rearrange_squash()) + if (autosquash && rearrange_squash_in_todo_file()) return -1; if (commands->nr) @@ -4828,21 +4828,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(void) +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(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); /* @@ -4855,13 +4847,13 @@ int rearrange_squash(void) * 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; @@ -4874,7 +4866,6 @@ int rearrange_squash(void) } if (is_fixup(item->command)) { - todo_list_release(&todo_list); clear_commit_todo_item(&commit_todo); return error(_("the script was already rearranged.")); } @@ -4909,7 +4900,7 @@ int rearrange_squash(void) *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++) @@ -4922,7 +4913,7 @@ int rearrange_squash(void) } 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) @@ -4940,10 +4931,8 @@ int rearrange_squash(void) } 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; /* @@ -4954,37 +4943,47 @@ int rearrange_squash(void) 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 0; +} + +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_or_whine(&todo_list.buf, todo_file) < 0) + return -1; + if (todo_list_parse_insn_buffer(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(&todo_list, todo_file, NULL, NULL, -1, 0); + + todo_list_release(&todo_list); return res; } diff --git a/sequencer.h b/sequencer.h index d7b52044bd..1cd9d7f1e2 100644 --- a/sequencer.h +++ b/sequencer.h @@ -147,7 +147,7 @@ int complete_action(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); -int rearrange_squash(void); +int rearrange_squash_in_todo_file(void); extern const char sign_off_header[]; From patchwork Fri Nov 9 08:07:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675475 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 28171175A for ; Fri, 9 Nov 2018 08:08:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19A852DDE2 for ; Fri, 9 Nov 2018 08:08:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E31D2DDE8; Fri, 9 Nov 2018 08:08:45 +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 715DF2DDE7 for ; Fri, 9 Nov 2018 08:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728455AbeKIRsI (ORCPT ); Fri, 9 Nov 2018 12:48:08 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44410 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728149AbeKIRsI (ORCPT ); Fri, 9 Nov 2018 12:48:08 -0500 Received: by mail-wr1-f67.google.com with SMTP id j17-v6so857618wrq.11 for ; Fri, 09 Nov 2018 00:08:40 -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=rGA0Voc/LBpFxSlce1ASno+oE0vRB2vj5XiQGb1FR/0=; b=occzwVl0pI20SW1XIpS7bU5msrAuZu6/ltE1GGTVKjyFFh6Z1iDvBY+PQBf4rlneg7 dPEp7o49AeuxsDvr5opfsxZ/NffWTsn0wpD7+GhmHw4OgMILjV+qD5hzUOnMoJf2fqFx ijVS2BhUsg3VQQzXSjOHb3r1dnsHFRR+2DdskyshRt0WS9al/YiAHRKAxZYywW+caQ+5 Tk/lFSHOclnrg1Y655Ssgk+cnyYYU2kSJEIGZLcvTG9M77ejgz4MHPhsp9rbyCwZ0fqY 7cooCjXoe4t0P7Hhihu4oJeFSeYjjoYuLbUhsoho1YQChX4PooBlkpc+QngCyM3O/3ua 0fzQ== 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=rGA0Voc/LBpFxSlce1ASno+oE0vRB2vj5XiQGb1FR/0=; b=Q+zWgF/6hua/HbdqffbtXftGmxtE35xAmrkuHDFtkrDKpXnrLHloUZ1MinLh6CC51+ C9H3iKY9IaxSvStp458+GBsmxGh5Ry3KPtIO715+KvH3GB3ovj5HrFXHmSjK1j/TipnK 03RSJZIWUyO7JceBQbSa8HR0liOk9H7d4Yq33Hsc4p/EMZuzRSC/TFy8iG7YfCHLeQ16 yWWglIYPkeCPUODHWMTCD+/UXodY+J2hrmLzvPqomUN6vYh9ppNFc6dnphbQhuXf4NRq k0l/xeT5AYwz171rMWImkQN5jTlt34nxpRu6vyxSpErA2QvVNre+b/qtvxVfZ0H/XW4J 4zRw== X-Gm-Message-State: AGRZ1gL9XPbl+fhLOowxiGw/mMvuX6ROo4YrgmCTEYQtga3yk5/YTHnM cu7YnreXqW526vYkvKIO+40DkzLr X-Google-Smtp-Source: AJdET5feMjaWmNUBLLj0hm77R03DQPlDdtzEzyCWTjiJSf6u29Ad3WgcLXUpzWTaiji72tv8Y2453A== X-Received: by 2002:adf:f342:: with SMTP id e2-v6mr1822272wrp.219.1541750920051; Fri, 09 Nov 2018 00:08:40 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:39 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 08/16] sequencer: make sequencer_make_script() write its script to a strbuf Date: Fri, 9 Nov 2018 09:07:57 +0100 Message-Id: <20181109080805.6350-9-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 --- builtin/rebase--interactive.c | 13 +++++++----- sequencer.c | 38 ++++++++++++++++------------------- sequencer.h | 2 +- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index a6d83a684e..c740a7dd5d 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(todo_list, + ret = sequencer_make_script(&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")); @@ -120,6 +122,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 fce97e5f11..3389a753b6 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4109,7 +4109,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; @@ -4254,7 +4254,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; @@ -4264,9 +4264,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)) { @@ -4279,8 +4279,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; @@ -4293,12 +4293,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); } } @@ -4307,11 +4307,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); } @@ -4333,12 +4333,11 @@ static int make_script_with_merges(struct pretty_print_context *pp, return 0; } -int sequencer_make_script(FILE *out, int argc, const char **argv, +int sequencer_make_script(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; @@ -4381,16 +4380,13 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, 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 1cd9d7f1e2..fcde6e739d 100644 --- a/sequencer.h +++ b/sequencer.h @@ -137,7 +137,7 @@ 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(FILE *out, int argc, const char **argv, +int sequencer_make_script(struct strbuf *out, int argc, const char **argv, unsigned flags); int sequencer_add_exec_commands(struct string_list *commands); From patchwork Fri Nov 9 08:07:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675477 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 6103A14BD for ; Fri, 9 Nov 2018 08:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 533F92DDDF for ; Fri, 9 Nov 2018 08:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4761C2DDE7; Fri, 9 Nov 2018 08:08:47 +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 A29A72DDDF for ; Fri, 9 Nov 2018 08:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728468AbeKIRsK (ORCPT ); Fri, 9 Nov 2018 12:48:10 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36196 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728440AbeKIRsJ (ORCPT ); Fri, 9 Nov 2018 12:48:09 -0500 Received: by mail-wr1-f67.google.com with SMTP id z13-v6so889934wrs.3 for ; Fri, 09 Nov 2018 00:08:42 -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=Z2gpFFx98S2SapLFkQQ8lIlj24ULmaT6RDgX84ynb14=; b=sitYi2uMYcBW5hIOp9aEgDLTaiYSNF3MXtCA/u39fdINULnsTmY1HhCGN4FDy44cTF HIemnOiT5X3kc6DhhklaaKl5vPIiOJx4u0zWhoGzOQ6D63t9P4dJ2jHsy1x3iqAkU7Rb jRzd4BOoy0aTE65DEHgFmmCjM+E6oxuYjpbWMB0PjavrgzMOEfM7NGcehuO5wPxs0NN1 cTAmjWYPZ4XPLCQql6poB6QPG4srQOJwq6On2fc5eCrR0udnbJdjuzih0cA4kfOncgRd Y14dN5P/OpKDWl4NE5Y2XKG9DiRPOYFw63UCajt4KtjF7Oc2SmcKqAy7Zs61Mf/h8mKP I26w== 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=Z2gpFFx98S2SapLFkQQ8lIlj24ULmaT6RDgX84ynb14=; b=n2tyY3wIl8H6HNFJNtzg5aEyTbXSJyS2yJgbuSIM3gnqQe69KAVDf/K89RaSwzuKfk i2yLjS+vqn9MF5hqggdUmmlAgvhScQUmQ2lTpzeWgM1XMiGDhWdSaboOZZgp0p3mt17S aeNITg1+AqIjHfXRx1B2eZUPjxy5mi0FulQZUd+ds6e8kHPpEWLqpmOZB67QWhCD3PHl Qsw5qCZYdYpECLa8F72juAqFbDzhRRlkHHwQzrXXtE9yAxxK8tYhcp8KGVuTnNOiXf3p JiaRJy1YNkiuW5L+7XzvEpXVIWw1q4BPWoasKCJw/mYaSnnCWuCatTOtAb8ITi3qR+ow JCew== X-Gm-Message-State: AGRZ1gJ2eUtYrvRcBrYOBIb394c+DoA0vzTLnMJkm9TPbWAlS3p9VaPL U5JtS/j5SFPinnlfiT/SWEJnmQZH X-Google-Smtp-Source: AJdET5fje7s/sc/EYQtaICN19vWlWKjfGsqEv3bzn8+OUUq4EVsrIbXARewrFJ7JUJS6JAjTztPiTw== X-Received: by 2002:adf:8521:: with SMTP id 30-v6mr6754799wrh.284.1541750921220; Fri, 09 Nov 2018 00:08:41 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:40 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 09/16] sequencer: change complete_action() to use the refactored functions Date: Fri, 9 Nov 2018 09:07:58 +0100 Message-Id: <20181109080805.6350-10-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 to the buffer. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 16 ++----- sequencer.c | 80 +++++++++++++++-------------------- sequencer.h | 2 +- 3 files changed, 40 insertions(+), 58 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index c740a7dd5d..99cbd1e8e3 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,15 +100,16 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, ret = sequencer_make_script(&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(); + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) + BUG("unusable todo list"); + ret = complete_action(opts, flags, shortrevisions, onto_name, onto, - head_hash, commands, autosquash); + head_hash, commands, autosquash, &todo_list); } free(revisions); diff --git a/sequencer.c b/sequencer.c index 3389a753b6..64a99ab84f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4700,93 +4700,83 @@ static int skip_unnecessary_picks(struct object_id *output_oid) return 0; } +static int todo_list_rearrange_squash(struct todo_list *todo_list); + int complete_action(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 = NULL; + item->arg_len = item->flags = item->offset_in_buf = 0; + } - if (autosquash && rearrange_squash_in_todo_file()) + if (autosquash && todo_list_rearrange_squash(todo_list)) return -1; if (commands->nr) - sequencer_add_exec_commands(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(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); - 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(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(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()) { + if (todo_list_parse_insn_buffer(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(flags & ~(TODO_LIST_SHORTEN_IDS))) - return error(_("could not transform the todo list")); + if (todo_list_write_to_file(&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(&oid)) return error(_("could not skip unnecessary pick commands")); diff --git a/sequencer.h b/sequencer.h index fcde6e739d..996e8ea2a6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -146,7 +146,7 @@ int check_todo_list_from_file(void); int complete_action(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(void); extern const char sign_off_header[]; From patchwork Fri Nov 9 08:07:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675491 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 403B414BD for ; Fri, 9 Nov 2018 08:08:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 324CE2DDDF for ; Fri, 9 Nov 2018 08:08:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 266972DDE7; Fri, 9 Nov 2018 08:08:55 +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 86BD22DDDF for ; Fri, 9 Nov 2018 08:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728459AbeKIRsK (ORCPT ); Fri, 9 Nov 2018 12:48:10 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40884 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsK (ORCPT ); Fri, 9 Nov 2018 12:48:10 -0500 Received: by mail-wr1-f65.google.com with SMTP id i17-v6so872595wre.7 for ; Fri, 09 Nov 2018 00:08:43 -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=kmDoMDylQvZalnCewT2X78OkOkPs00VUGa8xphHnbnA=; b=lMn24cfMlt2wZiGeEz+2svaffBFtljDywCJ6jQDEAO/xfwg7har9+O9vfS0aXeQcmz P4ljma6h8Hlyk5lpsUb57ASIXfK8Qck9UjHt8LNy3Qfuhx6rb3EEBLonDqZfMpjUCDwk 1QVzhBG1JAPwbYTja8HO2LiJMiSZJUINJmIpjvI0ZsnuWcaD+ecG+bdwZZzdSxeEt3bP XBQA0OhaGAbFL02kSWFVDe203krMzM/lR2HC8KNy6buNfekJhU0HNj2uccTePFVD7T4G WmD6qtJSbx1dVWgjMyFmZTyoymzQMhb0TW9b0bTqoEFuy+RD8ME5Q+lDUUSUfpE5LvGe wDEw== 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=kmDoMDylQvZalnCewT2X78OkOkPs00VUGa8xphHnbnA=; b=nHzQWlHeFNwIN1BJh+TVvHZK/d/UGuqgMFBYtSLLhViqmOP6tRi2kKOj1z/ZrlIO3F KrExHTOV/6otqAtKUawNnpf8Ri68Iv6Hz0T4pP8+Cghuacj5nv9P3PfNUPrGKtWjU38I hSJ8JY/lIIgVToakNYPxYeGJIGqloGetcYmHx5oAgCPHUz0RUigfTazGAJXAoy6+o8C9 S3q/bTX4RUVtO+t84OSOlj0ubQC/QDQwhgE0brgLRwT/XIPX8aVQbm79v6iA0pv89zqz LbfER7Slkb75JRaMvitUh4PHvUSf5rTKhU+VLET52nUDyBoCtnzduXLLr+9SBEqVqimI s3hw== X-Gm-Message-State: AGRZ1gJLVNkLPXR7EhPRgjRAqbYZij649GrauWOyvxAwDBDMXtyFboO2 vyavJqk3N9HqwJuBaAICF6LNIFfo X-Google-Smtp-Source: AJdET5fl6qUIUW8jR3fbJPqQN8S0jesx8WUFkjrwPxCB9nCo6rApHcB2Cp42Q/kCeQon1FVldPGX/g== X-Received: by 2002:a5d:51cb:: with SMTP id n11-v6mr6855143wrv.121.1541750922316; Fri, 09 Nov 2018 00:08:42 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:41 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 10/16] sequencer: refactor skip_unnecessary_picks() to work on a todo_list Date: Fri, 9 Nov 2018 09:07:59 +0100 Message-Id: <20181109080805.6350-11-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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. The file-handling logic is completely dropped here, as its only usage is made by complete_action(). 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 | 79 ++++++++++++----------------------------------------- 1 file changed, 17 insertions(+), 62 deletions(-) diff --git a/sequencer.c b/sequencer.c index 64a99ab84f..1c405763c3 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4607,52 +4607,21 @@ int check_todo_list_from_file(void) 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 object_id *output_oid) +static int skip_unnecessary_picks(struct todo_list *todo_list, + struct object_id *output_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(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)); } @@ -4666,37 +4635,21 @@ static int skip_unnecessary_picks(struct object_id *output_oid) oidcpy(output_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(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(output_oid, peek_command(todo_list, 0)); } - todo_list_release(&todo_list); - return 0; } @@ -4770,6 +4723,11 @@ int complete_action(struct replay_opts *opts, unsigned flags, return -1; } + if (opts->allow_ff && skip_unnecessary_picks(&new_todo, &oid)) { + todo_list_release(&new_todo); + return error(_("could not skip unnecessary pick commands")); + } + if (todo_list_write_to_file(&new_todo, todo_file, NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) { todo_list_release(&new_todo); @@ -4778,12 +4736,9 @@ int complete_action(struct replay_opts *opts, unsigned flags, todo_list_release(&new_todo); - if (opts->allow_ff && skip_unnecessary_picks(&oid)) - return error(_("could not skip unnecessary pick commands")); - if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head)) return -1; -; + if (require_clean_work_tree("rebase", "", 1, 1)) return -1; From patchwork Fri Nov 9 08:08:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675481 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 37A8714D6 for ; Fri, 9 Nov 2018 08:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B3E32DDDF for ; Fri, 9 Nov 2018 08:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F9562DDE7; Fri, 9 Nov 2018 08:08:49 +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 B65C92DDDF for ; Fri, 9 Nov 2018 08:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728466AbeKIRsK (ORCPT ); Fri, 9 Nov 2018 12:48:10 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42909 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728149AbeKIRsK (ORCPT ); Fri, 9 Nov 2018 12:48:10 -0500 Received: by mail-wr1-f67.google.com with SMTP id y15-v6so865397wru.9 for ; Fri, 09 Nov 2018 00:08:44 -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=oDz+erBAWeThbjjOrX4A8cTDjGlt7i774tix1Ggg0WQ=; b=rR0drcbtmNMI6ApidU99ZdUjbIoka7Wu3Hnm5vs10Y8SGUJSXvrJcDx3h95jc+kTcW aMykYFpmx21GgSkJnt1qpGTgOtuE5aXGGgyM85M7MMmAk9iawswpL2qW9gJ7/tmJHXjp I+QXZ6Phn3ycnimCDoM4JDngTmmygoGpukp45n6XUwO+XlBeEzRbZzaJa7N6BLqly46M NKGOBGHlOPlbtnvT7PApifBljY0aWSJzIgtjNQG7Nby44PS3D0Lxi8OeXnk3GdlZlZY5 UeJu6YTZrQ5fFCvq1RGczT1BTKa9X1+EYIbXQbQc2irAtuYSiYnjbe06X9mvcT6keUfw RvZg== 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=oDz+erBAWeThbjjOrX4A8cTDjGlt7i774tix1Ggg0WQ=; b=Y5HimCXF89sr8HA4IVqnjo6/6GPPuT5c+6f9ZW4Vb0+YvMUK9cTR2U7g8Kw/ctGR8Q AN/A6iuk1W7hFR+LDL6+II1KoCvVQ1oXzhXKnDlQ4cIUZ3NbrHzqq98+wj20EFX0wXUV 3wHLM1DNmZ5hSEZF39CoXhkKFTl9JHFDNmVSy+bZp0cPvNjfB3GJhKRgzOTkiHZlIND3 LYcYQziC+BwDJgrZng45SjVI80VUMiXgF3YqkL1ngpqqdFGpGl6aKxhh+6KXpttKGEQl r+W2ZOi4Hw9q6VC8xAyrsU7bXAs/hcxBYSRJMExbVUbaJZfvpzj6JBfPV3lK8y2T0C8J DMGA== X-Gm-Message-State: AGRZ1gICD5vVmJsWVccSAwRGruMJ9NNNqFUGH8rAtMHZZiMnxJhVb0FA xAU/VpLN/kjrOs/uxBGMo/MSyJ1A X-Google-Smtp-Source: AJdET5eJfOBRXPlG4YzJf1XW3tPGMDUrtfPnl8FWJxOkta0Jz9lUu69SYScQJHwplB0LBq9P0cQMsQ== X-Received: by 2002:a5d:4c4d:: with SMTP id n13-v6mr6900981wrt.298.1541750923452; Fri, 09 Nov 2018 00:08:43 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:42 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 11/16] rebase-interactive: use todo_list_write_to_file() in edit_todo_list() Date: Fri, 9 Nov 2018 09:08:00 +0100 Message-Id: <20181109080805.6350-12-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 --- rebase-interactive.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index 3adcf39e07..23569cfa3c 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(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(todo_list.buf.buf, &todo_list); + if (todo_list_write_to_file(&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(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(todo_list.buf.buf, &todo_list)) + res = todo_list_write_to_file(&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(flags & ~(TODO_LIST_SHORTEN_IDS)); - - return 0; + todo_list_release(&todo_list); + return res; } define_commit_slab(commit_seen, unsigned char); From patchwork Fri Nov 9 08:08:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675479 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 4A88814BD for ; Fri, 9 Nov 2018 08:08:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D48D2DDDF for ; Fri, 9 Nov 2018 08:08:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 316AB2DDE7; Fri, 9 Nov 2018 08:08:48 +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 BDA482DDDF for ; Fri, 9 Nov 2018 08:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728469AbeKIRsL (ORCPT ); Fri, 9 Nov 2018 12:48:11 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33556 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsL (ORCPT ); Fri, 9 Nov 2018 12:48:11 -0500 Received: by mail-wr1-f68.google.com with SMTP id u9-v6so899546wrr.0 for ; Fri, 09 Nov 2018 00:08:45 -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=qRaVCyo1Dkh19GqCzC3J80d5A7eXnemW9OeJp3cmHg8=; b=Qv3sqc+U0LWzcFXjsxUWSjOs/lm+8fQ67JNCkn2il88Emw3aAypzkAJ556sZtkDNae mxfoaKGx5TziOTOxl6uCxG6Cqx4zb6wpHrBuLW2UMlGsCmiFvkRUWEFluaXqKBGecYjz AC92ubmcv/X6D681EQh5bBuKDM4Gy27Yb2VrWaFOIERxYSoBem+hCqB0fkvpr8sWtovv 9E6iDW0CGcn1d9JQ/380cj4RcOZBDlsz83B97fR7M6MCW4Hb/dqfPlmyyVGbf2XCh7Ij lF/0dF323s54bBBHTWsjjRPUQH3MGtWD0Djyk5tK4umJYniDhTVr5tPyQqnx8+vF31Qd f3Ug== 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=qRaVCyo1Dkh19GqCzC3J80d5A7eXnemW9OeJp3cmHg8=; b=dEYMPvmSNEyvPZTwX0lQ1Qxbp9HMpzJZfAdSftkdo7skghR5pFmS62QN3cWy/8wcu8 eR7iFiXZw3LvZau7/YcScHCxzn4xWFA2f4BovmyIYEkMPLInc3BRDX72FaUyf3PHoAdV shxZv7pOSpj8sXO5V+4iVf5sCuKqJU9PI/nyMnv1VysGXyw/5d5JurN7cGrRVXETij5X SU4E/I+LuE81ST5RyQ+HJA+/R4gFa4horpp+JL/CvYcp6C80N7tIrDrdL0tDD2ilxxi7 1rRgDVqfQUz/28BVStzwbLwyq/L5gHlP7x+I3tRv8Qbtub9D9hAHuE2XVRYm+lCnnnIL AeQg== X-Gm-Message-State: AGRZ1gJVy9SPBiz0LxAVnHCli7Fqvc499Na6FnXlOPLZrkSkOkK0DtMG MsPVdGE1cg9whxB6QxyS8BaIiyuv X-Google-Smtp-Source: AJdET5c6mj2dRPTsRZb9yECMQ4sIVxNca1M2rPIG78dTnPUPs77BzmxrLAI6TTRfdvXFDZq+bKzbIg== X-Received: by 2002:adf:e3c2:: with SMTP id k2-v6mr7477543wrm.156.1541750924553; Fri, 09 Nov 2018 00:08:44 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:44 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 12/16] rebase-interactive: append_todo_help() changes Date: Fri, 9 Nov 2018 09:08:01 +0100 Message-Id: <20181109080805.6350-13-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 complete_action() 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(). edit_todo_list() and complete_action() are modified to fit these changes. Signed-off-by: Alban Gruin --- 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 23569cfa3c..3b7b5e3382 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 6bc7bc315d..61858f3a02 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -1,7 +1,8 @@ #ifndef REBASE_INTERACTIVE_H #define REBASE_INTERACTIVE_H -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(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 1c405763c3..cf6f69c93e 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4529,22 +4529,13 @@ int todo_list_write_to_file(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(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 Fri Nov 9 08:08:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675485 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 E315F14BD for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D69432DDDF for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB0222DDE7; Fri, 9 Nov 2018 08:08:50 +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 488F52DDE2 for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728473AbeKIRsN (ORCPT ); Fri, 9 Nov 2018 12:48:13 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38694 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsN (ORCPT ); Fri, 9 Nov 2018 12:48:13 -0500 Received: by mail-wr1-f65.google.com with SMTP id e3-v6so882687wrs.5 for ; Fri, 09 Nov 2018 00:08:46 -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=WWNvQR+TlZqPo1plbUE80Sb49glXDC5sRo9oaSiI9+I=; b=L46jE0n+grvTGBNOBSnokxv3uPK9BRhXUn9bKKUK7ka+Ji2NY5SDmaB/Dwhd1P5Ew3 sobgt1dXQJQ6E7wOz1tCFksu8Vrw4FGHO3sdiwq/7TgqUbLU5cSHWTZCKZVFFCWWvHk1 koAgg+p9Bx9JnksT/Y+IyMY0ZV7CkaSEYpW6mMh+nZLcfw/HSEU3kC1aK0iQRsj1Q0bd hnVc4dY/3vBbgfSIPfR89e0YLtUePSDusDzOI51nITiQrl8aXjl2LMsU6nnnx+Sl/Q5Q LmF1ZptW/rAbtlbcOv4ete19aUtPp0cQGNYt9uMFWE6fbPDXi1lBsRCoxUIX/2/37JAN S7Vw== 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=WWNvQR+TlZqPo1plbUE80Sb49glXDC5sRo9oaSiI9+I=; b=Ypzdfe1AlEvcOcgRs4mkmt++yIFDNSuRrvW//IAIT9qNOqdthw8sR8+IIl3UqCBPxz +iKF8zA2uGe6fv66xDLk6g5zYM6Z8thKat0McqGqwEVi+bqZ4xjiGyJhHCfvV571+yJ0 tSp8QnsR6PDmMwDYJuw+VY4VrGSWcVY2Np/b7hlbMJ4JKhvIG786G8l6dxDoQoUa9uwa UGVHx0TLsbOg1vBBX/Nm8FiBTC5kl7Mw9KJsW8r+ZPMabu2HXIuSugv11EHgvoRdpBL6 AGK3tIe+04dl+ZzKfg6PJ8F1ODbfoxtPY8iH1wUp9Fsk75kW1jm9ijLCf5NScgVH8V3C hJZA== X-Gm-Message-State: AGRZ1gI1auqrPrl8oVe9hGx30rMqIpMXlySdd6wia8RwV+Jb2cOGBkgM i7GTbXstpI65Ud7UTcvzoP27PsWF X-Google-Smtp-Source: AJdET5cMHQfHcArsqEeBU8H8nhUzolFKmt8J7rK0TXiZG4A3ls3ZmUUodew5sL+y8lEcUaNd05x9gQ== X-Received: by 2002:adf:ded1:: with SMTP id i17-v6mr7105153wrn.307.1541750925782; Fri, 09 Nov 2018 00:08:45 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:45 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 13/16] rebase-interactive: rewrite edit_todo_list() to handle the initial edit Date: Fri, 9 Nov 2018 09:08:02 +0100 Message-Id: <20181109080805.6350-14-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 | 23 ++++++++++++++++- rebase-interactive.c | 48 ++++++++++++++++++----------------- rebase-interactive.h | 4 ++- sequencer.c | 3 +-- sequencer.h | 1 + 5 files changed, 52 insertions(+), 27 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 99cbd1e8e3..6871990544 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -13,6 +13,27 @@ 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; + + 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); + if (!edit_todo_list(&todo_list, &new_todo, NULL, NULL, flags) && + todo_list_write_to_file(&new_todo, todo_file, NULL, NULL, -1, + flags & ~(TODO_LIST_SHORTEN_IDS)) < 0) + return error_errno(_("could not write '%s'"), todo_file); + + todo_list_release(&todo_list); + todo_list_release(&new_todo); + + return 0; +} + static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, char **revisions, char **shortrevisions) @@ -241,7 +262,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) break; } case EDIT_TODO: - ret = edit_todo_list(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 3b7b5e3382..e0fa88b90e 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -87,35 +87,37 @@ void append_todo_help(unsigned keep_empty, int command_count, } } -int edit_todo_list(unsigned flags) +int edit_todo_list(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(todo_list.buf.buf, &todo_list); - if (todo_list_write_to_file(&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; + + if (initial) { + todo_list_write_to_file(todo_list, todo_file, shortrevisions, shortonto, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP); + + if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) + return error(_("could not copy '%s' to '%s'."), todo_file, + rebase_path_todo_backup()); + } else { + todo_list_parse_insn_buffer(todo_list->buf.buf, todo_list); + todo_list_write_to_file(todo_list, todo_file, NULL, NULL, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP); } - strbuf_reset(&todo_list.buf); - if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { - todo_list_release(&todo_list); - return -1; - } + if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) + return -2; - if (!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) - res = todo_list_write_to_file(&todo_list, todo_file, NULL, NULL, -1, - flags & ~(TODO_LIST_SHORTEN_IDS)); + strbuf_stripspace(&new_todo->buf, 1); + if (initial && new_todo->buf.len == 0) + return -3; - todo_list_release(&todo_list); - return res; + if (!initial) + todo_list_parse_insn_buffer(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 61858f3a02..8d5c04521e 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -4,7 +4,9 @@ void append_todo_help(unsigned keep_empty, int command_count, const char *shortrevisions, const char *shortonto, struct strbuf *buf); -int edit_todo_list(unsigned flags); +int edit_todo_list(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 cf6f69c93e..f04b002e37 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 996e8ea2a6..f6751d53b9 100644 --- a/sequencer.h +++ b/sequencer.h @@ -9,6 +9,7 @@ struct commit; 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 Fri Nov 9 08:08:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675483 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 7FCA314D6 for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 730B32DDDF for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 677E62DDE8; Fri, 9 Nov 2018 08:08:50 +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 0F5252DDDF for ; Fri, 9 Nov 2018 08:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728478AbeKIRsO (ORCPT ); Fri, 9 Nov 2018 12:48:14 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43846 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728470AbeKIRsO (ORCPT ); Fri, 9 Nov 2018 12:48:14 -0500 Received: by mail-wr1-f68.google.com with SMTP id y3-v6so863897wrh.10 for ; Fri, 09 Nov 2018 00:08:47 -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=Ko+JIfODrwOH6Y3rguKFF557JlHaXRaiipOgQrkwZ2k=; b=XDnkvvnH7v73fKiWo0Or0B0U1ht2/oalBSaKIeDFZzb0zecS8BeRNXdzFpwUXQ1pQW 6jW9iX0kEuBDZeUYOlt+mhtwHkOo1V5mSZ76GZqYhtajSatY72RfmQdI8R9SufXomn1e lZ6VdG8vxBhd7H2MkYLMQBx63c+VDZDDTLarQZKWaF8IfpRqRLosjgIb3N5S2/1ph7rP 4zIBRoKF3F7JDieHfYpNsw/YdsusmgC/311s6ZV39WK0fSYfkT2wdU1tLXsACaHfOEOI OFVa4EiH4+w9P4taDYAGBOMKLXnsKeS7NKD/4MZ4F8MyZXGrRFDF/ME9nL8WRCCKfhua R07g== 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=Ko+JIfODrwOH6Y3rguKFF557JlHaXRaiipOgQrkwZ2k=; b=VFMYo7nbyxoAnubT8WVz1vwtfIakochSoHmTzm/jchHwipocGt4wo2YbPGAR1Qla4H Hbyxt3Z1z2eeyXIIi2hYY/eRHlgxW9UWE902gEmXTZqO8U97WX5rpCAnbXkVRznpDuRu 14pKfn0SHnrzdld/q65McAy4635dlXGlLvNZpYUCLsjBmjyCFx5HhYDqq5cv9esUzGUX tj/KpmXmoPbucDMTmPfz8yTr/loe4XlWFa4phC15lDAepQ7wvHrpz1q0nrK1h4owXTir d8ZVeqqVeTSoenRYcPnj/rm7DG3pqTr7pWaf/xWpfW0MN3q/yu29ESIeeIoQ9u8T6LyD U80w== X-Gm-Message-State: AGRZ1gJ2mrAeDOVjMe1HN/XuUb4wOQ5AqiZIrb1hGzKeL6ouJ+qPk50e llkt3jNXUOG1R4m9wxqU7Eqyh2R+ X-Google-Smtp-Source: AJdET5fohzQ8U8oOiIGMZDQVtHt14HTESn+lpJbtMSGbRwwHlOutEN2lQiqzTzpLrBRmE1iFstEGtA== X-Received: by 2002:a05:6000:151:: with SMTP id r17mr6639927wrx.53.1541750926804; Fri, 09 Nov 2018 00:08:46 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:46 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 14/16] sequencer: use edit_todo_list() in complete_action() Date: Fri, 9 Nov 2018 09:08:03 +0100 Message-Id: <20181109080805.6350-15-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 --- sequencer.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/sequencer.c b/sequencer.c index f04b002e37..02afd2f5cd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4654,6 +4654,7 @@ int complete_action(struct replay_opts *opts, unsigned flags, 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); @@ -4679,24 +4680,15 @@ int complete_action(struct replay_opts *opts, unsigned flags, return error(_("nothing to do")); } - if (todo_list_write_to_file(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(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 Fri Nov 9 08:08:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675487 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 E1DA914D6 for ; Fri, 9 Nov 2018 08:08:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D56C22DDDF for ; Fri, 9 Nov 2018 08:08:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9EBC2DDE7; Fri, 9 Nov 2018 08:08:51 +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 7888A2DDDF for ; Fri, 9 Nov 2018 08:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728480AbeKIRsP (ORCPT ); Fri, 9 Nov 2018 12:48:15 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:45344 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728222AbeKIRsO (ORCPT ); Fri, 9 Nov 2018 12:48:14 -0500 Received: by mail-wr1-f65.google.com with SMTP id k15-v6so856037wre.12 for ; Fri, 09 Nov 2018 00:08:48 -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=ubnYXsEm/3EoussvQPLFrHRPodUXdckn5TZhTTJOqjY=; b=KOQYpjRneuPtpYOi3whjXu2jMr3Bym9M0qb987ksOOaQOdCLptuLFdxfm4pWgefeTQ cIyPcmeIuWKW4lMiTUn4C1Z2i4Pc/HzJj1kfgzF+HXfrWhSUmdUEjTnODM2mECm7FAYe i24T6/b8E39nL2fKWgC183kP0pjTybWIQcP7uK1/Mteawc6XHmAMSg2Bpvrsx/2bUmOf TlGy3i1dt8SqkDfTthpxuDAQ1zr6NBBXjmEIKBIdgnOR6Z7adH+0JPaq6tSB1NJlGwNH kdjUnp/NmnxNa6ZI9dBf38RxJTq8ktM2+ZQ2iNYKY1d+PtyNqokF9IenzWkQTJXPADhX BhSA== 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=ubnYXsEm/3EoussvQPLFrHRPodUXdckn5TZhTTJOqjY=; b=cM+39AiZvfYxpBezBuedqDiQuej7DkUezXDqQGr+9nejTaGnCnFoY/8QBog9+cSAfX HmgglSk22yY1OoHclrBhR1vK/FvS7qhApOMpCI8uD5ouaydi8xkmdG/pWZvQappjfytC 0wcSpggQJjnz9OGwbfwItvb52gr6aHBiEuWLPNT4ZGOk7rriNjxEgJv1r9keB1Jj+KN4 AKg7NorvOioru46rBN3AZUDPhkpzZvs9gAiuSjwX9bvwDhvJhtK3z7yx6iYvFOlVvSAC zdtapYwFGM62tPyMO3zbbn5GIS+iJYK+/PyVt9bWk/qDUt5N0ZB1r5YMVIR8BR4N0Jje NMRw== X-Gm-Message-State: AGRZ1gKLLrLw/DDJ1maDXMu1WA3/AaSyYaXnGwUOD/4UyhZo1z3LwYhv XEVnpVuAnIdQUUR2X0j2V6NfJXGD X-Google-Smtp-Source: AJdET5dhm2RkvvuK6E4AuIASq7y8anWc2ArlWGpiNpowAa/G43eURVfQyVQWcM6GtDEJVV4NSmCeog== X-Received: by 2002:a5d:4c4d:: with SMTP id n13-v6mr6901229wrt.298.1541750928069; Fri, 09 Nov 2018 00:08:48 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:47 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 15/16] sequencer: fix a call to error() in transform_todo_file() Date: Fri, 9 Nov 2018 09:08:04 +0100 Message-Id: <20181109080805.6350-16-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 replaces a call to error() by a call to error_errno() after writing the content of the todo list to the disk in transform_todo_file(). Signed-off-by: Alban Gruin --- No changes since v2. sequencer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 02afd2f5cd..a55df3526f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4464,7 +4464,7 @@ int sequencer_add_exec_commands(struct string_list *commands) int res; if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); + return error_errno(_("could not read '%s'."), todo_file); if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); From patchwork Fri Nov 9 08:08:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10675489 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 B0CC414D6 for ; Fri, 9 Nov 2018 08:08:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A39512DDDF for ; Fri, 9 Nov 2018 08:08:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97DB92DDE7; Fri, 9 Nov 2018 08:08:53 +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 31B792DDDF for ; Fri, 9 Nov 2018 08:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbeKIRsR (ORCPT ); Fri, 9 Nov 2018 12:48:17 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37788 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728375AbeKIRsQ (ORCPT ); Fri, 9 Nov 2018 12:48:16 -0500 Received: by mail-wr1-f65.google.com with SMTP id o15-v6so881370wrv.4 for ; Fri, 09 Nov 2018 00:08:49 -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=d35r7NzY7xQi55HPfborvunr3CqvrJqDvpnt9k6KlIE=; b=sNXGEt+tBzp5mi1AnFuVlxZ4oJvY4jvz5ePEcZTGlOHQ2fxqio09klQIdg+oFSQYip xx57Z+OyRYQjOynyn30ukgsJP7kCQnmDObD9aelyhSdc4GSpJ2tPr4vag9SQTF29Pp0K Y4lRKN9pceXetPIL2wtb8/+gmqNi+tckMtS9ozQRihppWdgq224Le3qocFqnfTOmkP7A ghbyPKd6lJ4NVD7mzlrD4WwVu5x/li0Fp/+cylft5jjBVl6wUFScEevCJqL0JJe8ATIM oEjpuIzQHAnn/sJ6+NwcjbAOStgrvSNaiAs1MF44aA11Gfjr0/I/iZ/dMn9vdGHc3iUW Qvmw== 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=d35r7NzY7xQi55HPfborvunr3CqvrJqDvpnt9k6KlIE=; b=USS7yw1aSHRUaHlqEE5L8xXRtAJNW9C9EE5IfzR437UDswBXmu6tb8aImQDAvi4YGH GXoK3ZntD9GzsDKPQ3aZduOdoc1JZ1It+E2BfHat4qThrD4Q7ujCyVR4Ygm+Aoc640XY 8CvYxpPiPXCfk+Z9q0PuJUriO/V8yTUAc8Vyx4tPuOJogtfAUB8M3zX+/TE6Fuv17BFG 9EtmAQwCvB0DlxYatCxIn4eJ4UFTAe4SCGkAupgy2ZjuFm63ElpEgjgxHzB+M+ArIa58 mtM3X81a7g4iMl6Z8O5aDTW5+uj+xVlz+kiLVl/pGAntkN0LoGPAoQva9wVIZoRhYCmt 2K7w== X-Gm-Message-State: AGRZ1gL5Pc32LmaRJ+jRBQ/1VA/vbC2ILHBiKifZ46bbXEXc8s2GeW3O ObZd7zecuSx0526cMoaKYm/EcdDO X-Google-Smtp-Source: AJdET5fu4TtCKxpOBm4zqqWnB7m6o3W9PyeyxeTj7r5GxTw6gU7sCDi/MrNcFdtzjxLMVzZcDL3+WA== X-Received: by 2002:adf:9403:: with SMTP id 3-v6mr6952115wrq.54.1541750929039; Fri, 09 Nov 2018 00:08:49 -0800 (PST) Received: from andromeda.lan (atoulouse-658-1-60-221.w92-136.abo.wanadoo.fr. [92.136.157.221]) by smtp.googlemail.com with ESMTPSA id x194-v6sm3003973wmd.41.2018.11.09.00.08.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 00:08:48 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v3 16/16] rebase--interactive: move transform_todo_file() to rebase--interactive.c Date: Fri, 9 Nov 2018 09:08:05 +0100 Message-Id: <20181109080805.6350-17-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181109080805.6350-1-alban.gruin@gmail.com> References: <20181027212930.9303-1-alban.gruin@gmail.com> <20181109080805.6350-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 transform_todo_file() is only needed inside of rebase--interactive.c, it is moved there from sequencer.c. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 20 ++++++++++++++++++++ sequencer.c | 20 -------------------- sequencer.h | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 6871990544..580c6a3822 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -34,6 +34,26 @@ static int edit_todo_file(unsigned flags) 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(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(&todo_list, todo_file, + NULL, NULL, -1, flags); + todo_list_release(&todo_list); + return res; +} + static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, char **revisions, char **shortrevisions) diff --git a/sequencer.c b/sequencer.c index a55df3526f..896dd04150 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4542,26 +4542,6 @@ int todo_list_write_to_file(struct todo_list *todo_list, const char *file, return res; } -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(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(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(&todo_list, todo_file, - NULL, NULL, -1, flags); - todo_list_release(&todo_list); - return res; -} - static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' " "and then run 'git rebase --continue'.\n" diff --git a/sequencer.h b/sequencer.h index f6751d53b9..ee59233344 100644 --- a/sequencer.h +++ b/sequencer.h @@ -142,7 +142,6 @@ int sequencer_make_script(struct strbuf *out, int argc, const char **argv, unsigned flags); int sequencer_add_exec_commands(struct string_list *commands); -int transform_todo_file(unsigned flags); int check_todo_list_from_file(void); int complete_action(struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name,