From patchwork Sat Oct 27 21:29:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658457 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 D5E541751 for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C25A12A87A for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B67F02A87E; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A9B82A87C for ; Sat, 27 Oct 2018 21:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728572AbeJ1GMN (ORCPT ); Sun, 28 Oct 2018 02:12:13 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53790 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbeJ1GMM (ORCPT ); Sun, 28 Oct 2018 02:12:12 -0400 Received: by mail-wm1-f68.google.com with SMTP id l26-v6so4576168wmh.3 for ; Sat, 27 Oct 2018 14:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2/ssTr4aLgYbH7jRP5liAXvKE89eNqNceAM1hSSFoEw=; b=DpSyRQpKtIxCW1SIcfMx+Xe+69UK/V2cCWf2AJGQFzrNM0WIMmyhYyKjP2rc7YX6Th eR5fgUMI+d5M+6VK/PHwD6tgDY4M3h7SjLoNZm//KBNCB+ypd8gVf4G5HeC4sVO5F2RZ AuUtpMUDMltbkM/rCeDfotioEqGBQzb9I2yjR6VkK0Dk4gysNhqx1D7L8ndi64BItC9/ w2qRe4BWToNimmKRR72A1G5MueeaksD/qn73xPGSPUSKxBoxSoELniJI9skdbLtfU8nL jE5+X6BWrux48XlYP2/Sle2NduNoPdTqxt9h/YSj4VXeFEQGYvuKxMsAlD9+d8tnBlom 86NA== 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=2/ssTr4aLgYbH7jRP5liAXvKE89eNqNceAM1hSSFoEw=; b=athW/VRx6KMNufSxagwy3S4Bih+d9xl2bYCwmcsrWhjhV1RYeqKFbkoLpkeL9S2aHy /59fE6GgDp//eN6Xgs3VIgj4z5zk2YXCx4jEdosGxqdgjm6SXuSPqql9cREB1u18vLtq NK1hBGj4nFVQM8C9sr4YuWD5zyGWZc00YN6/yiTWsgNIW72ib9caII9tHpYasLJchc4Y g9QJNyREbWV/c7QwwiWsfXP1ESG7zwgDT8PIXly2052MGVc2taFl9N1CRGSDP9F7qGqR 3mLJ+ISfE3F8/6OnZJts5wuIOqvowZrVlZRktg/QbAuVP5SVyOazXBLDv2+wKyreOlJQ WIcQ== X-Gm-Message-State: AGRZ1gJDZ82w+yziruoAnI8XgFwX1GWwQd7XQeuGU5NumKKXc8apZthv TtK5dA+xUmPDMElCOaewey06PYOf X-Google-Smtp-Source: AJdET5c4HCwLIks0e0liAvyUQAxyxLeB7UWZRlgK4tmSg79Q8gVcxS+9CRaeBEiXjMntnBRgp3QiXA== X-Received: by 2002:a1c:5a86:: with SMTP id o128-v6mr9094715wmb.138.1540675791866; Sat, 27 Oct 2018 14:29:51 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:51 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 01/16] sequencer: changes in parse_insn_buffer() Date: Sat, 27 Oct 2018 23:29:15 +0200 Message-Id: <20181027212930.9303-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 --- sequencer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 8dd6db5a01..9c8bd3f632 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2023,6 +2023,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'); @@ -2036,7 +2038,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 Sat Oct 27 21:29:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658433 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 B542C180E for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3FA22A87E for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97E352A8C8; Sat, 27 Oct 2018 21:30:13 +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 A1C302A87E for ; Sat, 27 Oct 2018 21:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728602AbeJ1GMP (ORCPT ); Sun, 28 Oct 2018 02:12:15 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36868 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbeJ1GMP (ORCPT ); Sun, 28 Oct 2018 02:12:15 -0400 Received: by mail-wr1-f67.google.com with SMTP id g9-v6so4667272wrq.4 for ; Sat, 27 Oct 2018 14:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jNzQCnH/U1d1VuAl6d4fUv8+LipC2Bp9wwBpHyXrkuQ=; b=hudwuN1FUVfjnVgtHjAhKgyfKlCvY6iXZUCiVqV/PVabGB9MbeszPwOcktSuvLtLhe 0sgPE10RfCf2Evp9ayflkGf++QbyJviGyTCrPbfSLN3TkskfJwb3ygLoYqjiSwKn80ry 7/EwnqZe0o1/xb03GU64BqMxyMDEwFQW2wIYPSB5b1oqwNlgROJLKPmLiMvDhW01DDG2 v+r8hr5o/OfiZHsgiHW2dy/H67Wl37h02iY+Fi2laQZ7b7f52k0PxmXf5M5cf17p3Z65 BxQG7ixZduEwROzQgKCrjbSl+oKrks96IIUaL5pt6IKulNXcMUxRi5Pdu1Ujv1SzBloF qz/g== 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=jNzQCnH/U1d1VuAl6d4fUv8+LipC2Bp9wwBpHyXrkuQ=; b=h6vYJ1p9V6B3EtUmpXUSP2muDn6rcsSo/d/eqIwmgdr3yVNEmLkig+W5AW4OqP5F7D trmydaLprE/l2hKP6aTR142jwEGjNkbWQPuhDZrEaVyGvVTM/nMP5SRE5YHuTLMbSYQt GTGY6AitFXqtDvqtqdQfAv4k0hsOKIzRKTaiJNVGD/veFMnE9QMe1lOGTjqdHxvbj3BI We7lvNAnq4br4L4zfG93u5DNledgMMK0I3zZut5KlUiL9Fx0uWoIRdUFaHTLokO3V+LQ 1g6VvPOLzGIADFs+nfM0fz7TYAQOvoeWEfk/3WZ8t5MV/znuGf6K58Sxjt1+9nAV/IZc IpCA== X-Gm-Message-State: AGRZ1gJ5T2N5jzagOoA8pgY/Y/1O2vp5fu+q8QJtcGqOepcEAkDOS6Km ucgokH8BdJPBUPhsrsdzrZVevQau X-Google-Smtp-Source: AJdET5eq9urSIHYD+GiXK5lI5ygGrItDqBxpaaaM80fKGjvdIvSr+t5IC0re/7CeckBncOQv6mB74g== X-Received: by 2002:adf:efcb:: with SMTP id i11-v6mr9267303wrp.204.1540675793913; Sat, 27 Oct 2018 14:29:53 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:53 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 02/16] sequencer: make the todo_list structure public Date: Sat, 27 Oct 2018 23:29:16 +0200 Message-Id: <20181027212930.9303-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes the structures todo_list and todo_item, and the functions todo_list_release() and parse_insn_buffer(), accessible outside of sequencer.c. Signed-off-by: Alban Gruin --- No changes since v1. sequencer.c | 66 +++++++++-------------------------------------------- sequencer.h | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/sequencer.c b/sequencer.c index 9c8bd3f632..f791729271 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1401,31 +1401,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_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; @@ -1897,26 +1872,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); @@ -2017,7 +1973,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; @@ -2115,7 +2071,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 " @@ -2146,7 +2102,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; @@ -4276,7 +4232,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); } @@ -4311,7 +4267,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); } @@ -4397,7 +4353,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; @@ -4416,7 +4372,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--) { @@ -4498,7 +4454,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; } @@ -4586,7 +4542,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); } @@ -4694,7 +4650,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 aab280f276..cc69473bc2 100644 --- a/sequencer.h +++ b/sequencer.h @@ -67,6 +67,54 @@ 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_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 Sat Oct 27 21:29:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658443 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 AC9F61751 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 988FA2A87A for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86E1E2A892; Sat, 27 Oct 2018 21:30:14 +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 C28BD2A882 for ; Sat, 27 Oct 2018 21:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728625AbeJ1GMP (ORCPT ); Sun, 28 Oct 2018 02:12:15 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36579 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GMP (ORCPT ); Sun, 28 Oct 2018 02:12:15 -0400 Received: by mail-wr1-f67.google.com with SMTP id y16so4666251wrw.3 for ; Sat, 27 Oct 2018 14:29:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gr3jhWiAq88YQJ2uHIyUDQyAA9zf1KQSGgZLd7WwOtE=; b=cD74CYMJbGPpyPO6zVtQNxezfjhPFjt2oAwGzNjp80hk1g9fQ+B9u4vuOFr4xKN/Uh J//uLOvtQU2OMj7b53bZgreQRxbeGqP2eW3B+5DKecKfADjt3GhkT+EJXkB8DcgVQ7RK 1DHWAxAKnlDHEZKudZqIBqFttPBARXC2FEPIzWpmc/gTE+iTj3294eGiBJhlVd6GCphS d4IdLAh1m7rTALVZXOOMT2OuJ+zR4kknZt8fe4VYNJ55E4q2Of7KhFHfKTeVFaCqmC6u xv4AUT5LsZkE9d87buKqN+QSqK7l2gHDdjyD2/cOy+QEeYV1dDUSeliThCnsfjMDSaCT GqKA== 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=gr3jhWiAq88YQJ2uHIyUDQyAA9zf1KQSGgZLd7WwOtE=; b=iHCneeTRrRcLYkiyRFNN7hQ2+JZO+IO6JH40N+2tmizVq9JL5ifOacrghgOoFqc8Sn SpneYE5MhyQEsmjYGbYjznr4z3nWItIwqgy3//0LoiI8y6UkBTi8v6qKszlndmC2IJVR sbl8SErpLzwmYJUIy+yHPpKxWwuiYuw6+XyuXhu3Y103y6yMn3Ln0tIh7dLU6PGCifSJ 89OubQYI4MaQS+ajGpOXa/wfece8P0E6BNGiH0PyCh4y5pgBK6SJncNhqQf2UNaHeNO+ JmQCtlKSg4QgxEFnnnDqppd69CU4DMk7IF+6Shhj4+aHlq1wLhAs9rG7ewO9VcEJlMY4 WLXw== X-Gm-Message-State: AGRZ1gJb33hH0GHX+crz1IiET787pe3bVkosVmVScTbI9AFtb+yu615f pJn6tW2xfpQSHNM3f41Tu4gDCUT7 X-Google-Smtp-Source: AJdET5c7btVWO5U6B4gpxyf04+fnm4VBnQiwsJJHIG4fjNxv3/EgxMJdvviS5d73BHhE3L/U0UXPuA== X-Received: by 2002:adf:e403:: with SMTP id g3-v6mr9284687wrm.96.1540675795255; Sat, 27 Oct 2018 14:29:55 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:54 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 03/16] sequencer: refactor transform_todos() to work on a todo_list Date: Sat, 27 Oct 2018 23:29:17 +0200 Message-Id: <20181027212930.9303-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 --- 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 0f4119cbae..49f2f549e1 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -68,7 +68,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); @@ -84,7 +84,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 f791729271..07296f1f57 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4256,23 +4256,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); @@ -4308,9 +4298,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) @@ -4571,7 +4585,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); @@ -4600,7 +4614,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 cc69473bc2..029d842ac5 100644 --- a/sequencer.h +++ b/sequencer.h @@ -113,6 +113,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 */ @@ -136,7 +137,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 Sat Oct 27 21:29:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658435 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 E8C411751 for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D877F2A87E for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD0CC2A892; Sat, 27 Oct 2018 21:30:13 +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 E35D62A88A for ; Sat, 27 Oct 2018 21:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728647AbeJ1GMR (ORCPT ); Sun, 28 Oct 2018 02:12:17 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36871 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GMR (ORCPT ); Sun, 28 Oct 2018 02:12:17 -0400 Received: by mail-wr1-f67.google.com with SMTP id g9-v6so4667373wrq.4 for ; Sat, 27 Oct 2018 14:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eBV2JpiHvaPR+5ZOnotFn6Wzr0I12rKofRwIPiIKid0=; b=b8g26mrjDaxmXYCGF/wR9InIRF1eXQAjXBU+TH/eTbCr1EPYoDzVw/wyNRj5jQSrO7 ce3O8u5WnMZ+yQDoMdGo1eGKTy6PnbP0SATTfqfW7FVN64hKXjQVUJ5HbbTqa4VlkkSQ W3zcmF2ht/TdwM7OsJOR6dp6D5NV7s3nuWKPOMGbFywX7l2tXXeAwiZxb4AFTZr584jC tjMih42CZ2VY+03hcd/CgWRmTW/eCdoz763X4AmzyWnoFoIFM6G/f8ke1YSoMuREL9M6 AtdFsQJ7gm403C2MBUZwpVW7V6np43CCPzDTGUQhbVDiHpi/QZZYjmQt/DNNbD+985Oa cI6A== 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=eBV2JpiHvaPR+5ZOnotFn6Wzr0I12rKofRwIPiIKid0=; b=IbARATdV5mSge/3sMp+/jzyL70kpZyMFl8CpnHhW5vOt1OKoL8896+oVVV9HO267Pz 5dq235KVYmK/wY76NtFLYLrP3PnZL5tWdtLDG+Z1SgBeGBw/gU1exJ+VWi42of5ibb9e b+oRQT6P4G63G5BaP1s4kWQwIRY0jHKQLQlzEObSHqrhxz960iHzfVd5E2bb4TYfyyTQ sSSZMe3cyfSs2K6LPglWbHEAKxQ2M0ZblJKw7T59LAPvPuRrz1hG80DhRj8C3BzgWkmZ AV51DHN+d+m78eLSw7+NFLEQNF7X4Wc8pUw2jYPQsgrKLjjwzkhHYbbmb1+SuwPejX7u zKeg== X-Gm-Message-State: AGRZ1gLfikJVbuKfzv+0dooz52w+EkNdyqIbkh5YNs9MB7EpSMnWfHm/ U7MaaqUqsbpMJ/1825Sq/IJDZTKr X-Google-Smtp-Source: AJdET5dJnSprCR/u05SmSPi3X9aHMflOvj0LoqhfmcciZ4OFzQ5fjb2u42QlGK9rN5202XSleFv9ew== X-Received: by 2002:adf:ae41:: with SMTP id u1-v6mr9328986wrd.43.1540675796746; Sat, 27 Oct 2018 14:29:56 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:56 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 04/16] sequencer: introduce todo_list_write_to_file() Date: Sat, 27 Oct 2018 23:29:18 +0200 Message-Id: <20181027212930.9303-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 introduce a new function to recreate the text of a todo list from its commands, and then to write it to the disk. This will be useful in the future, the buffer of a todo list won’t be treated as a strict mirror of the todo file by some of its functions once they will be refactored. This functionnality 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 to append the help text to the buffer before writing it to the disk, or to write only the first n items of the list. Signed-off-by: Alban Gruin --- sequencer.c | 59 ++++++++++++++++++++++++++++++++++++----------------- sequencer.h | 4 +++- 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/sequencer.c b/sequencer.c index 07296f1f57..0dd45677b1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4256,24 +4256,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) { @@ -4283,27 +4286,46 @@ 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 command_count, int append_help, 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 (append_help) { + 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) @@ -4320,9 +4342,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, 0, 0, -1, flags); todo_list_release(&todo_list); return res; } diff --git a/sequencer.h b/sequencer.h index 029d842ac5..a299c977fe 100644 --- a/sequencer.h +++ b/sequencer.h @@ -113,7 +113,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 command_count, int append_help, int num, unsigned flags); void todo_list_release(struct todo_list *todo_list); /* Call this to setup defaults before parsing command line options */ From patchwork Sat Oct 27 21:29:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658451 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 3091613A9 for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B40D2A87A for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FB9E2A87E; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12F912A88C for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728693AbeJ1GMU (ORCPT ); Sun, 28 Oct 2018 02:12:20 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41798 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbeJ1GMT (ORCPT ); Sun, 28 Oct 2018 02:12:19 -0400 Received: by mail-wr1-f68.google.com with SMTP id x12-v6so4646617wrw.8 for ; Sat, 27 Oct 2018 14:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dpCEBmK/vtJhcpSg2p1p4J3ZzwXdF7m3I1TR0EnfO6Q=; b=c1WilE5nrP+zTDTkASDYeBX8grcLKJWT5UytmqDPEOWdKtK6qQIaRWUv1ZZF7RmHnD i7l1HzG3NiT4mJOXprxKcLmG5bhlxVSGBbJSjvnCSOcLu92gj+niyDx1gzAchjKGxOi4 89dA2gSRkS+3hejdBz7lv8I3YnIAKyezK9dKiRXX0rFuK/tMfQCslxF37OdIpY+R/yim Ut2M3KgOoVPQf/1ZEBJk8YV+glUtbPCKt+SIBGVpdpq6GOXKwhjIERFE+kzYG2CHXLho RFmC5EDcereRGDq1GGWzmFS6nMe8wMByhf3w1U7QaXduFbCqTA5rB8mPdk4YW1jMK38I 5d1A== 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=dpCEBmK/vtJhcpSg2p1p4J3ZzwXdF7m3I1TR0EnfO6Q=; b=XrsJAOPCsixxhss2pV3fbALQxGr9Y+Ctk+CAz0GJgcjQpTSA57D5dxjN0InEt1JVJZ +rpeaS5uE5S8z9Kl8bZMDtstP+9AamnZK6+nB6NC1xw/htpqBFrE5XtJHPuPrNt5TruI WlXqZtqJdlga6+jOQYm/0ojQI3dY6gRKHSNvApvtb6gHbGR9G1meqQ8Eh2kR7kTqLFdn Cfj3EZ4YqVsaNYAYabmtqO5aD0+FCMfUFoLjSWki3fd9dRa5LCJ14sQyOWNqYDEtUYDQ eJzGRUDCdjegxB5krM+O/NmH4RC/U9QBckp4hm2pbcnOLyrFCAlWR1gOANsew6Ai7z6o Qcag== X-Gm-Message-State: AGRZ1gK4swhlVnr224xSapHDEnST56ysjXwBjigwduBxXNGpwf1JSIHm XOMBKMYGrb6W3qTlQpfwIUkwXimo X-Google-Smtp-Source: AJdET5c9uIs8UdmOk+DEtaRiHTz+m6MoUasw75etH0XD9+SaPHebAkVs2NMEbVJgWqWqHbuMrHCPpA== X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr1460875wrw.136.1540675798256; Sat, 27 Oct 2018 14:29:58 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:57 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 05/16] sequencer: refactor check_todo_list() to work on a todo_list Date: Sat, 27 Oct 2018 23:29:19 +0200 Message-Id: <20181027212930.9303-6-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 --- 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 49f2f549e1..9e81ecfe9f 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) @@ -88,3 +112,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 0dd45677b1..e12860c047 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4348,111 +4348,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; } @@ -4630,7 +4556,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 a299c977fe..e203930084 100644 --- a/sequencer.h +++ b/sequencer.h @@ -58,12 +58,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); @@ -140,8 +134,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 Sat Oct 27 21:29:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658429 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 3EB8013A9 for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2FC3B2A892 for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 241EA2A8C6; Sat, 27 Oct 2018 21:30:13 +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 39E632A892 for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728707AbeJ1GMV (ORCPT ); Sun, 28 Oct 2018 02:12:21 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40445 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GMU (ORCPT ); Sun, 28 Oct 2018 02:12:20 -0400 Received: by mail-wr1-f67.google.com with SMTP id i17-v6so4606963wre.7 for ; Sat, 27 Oct 2018 14:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YJEHAKvAxNWxnFfAtDxhScuhxeMydUZOlP+8nhHGWX0=; b=bhDKOBmrba+XF7ZYVEEykTOgJ3iIy9Ri9I17wSabL0jckj/4MazdNVfEsTanmR3WPH H8VxXPJKQo+OGUKPUUoNZMpI25VMQm1vpZLHFHZsIjbwhdx++ziUKuvG04+nyoHmd1Eb 2ZA5loKV79521YYJvyYhBH1aGhHGZgDbcaU/Fv57XnuIJOff63kgu7K9ak0q47CYHkIa wd9BlTEGY/YmBco7vZyzzPqDPz8i1CdytmF7R4ibVxbJrCx8ZjPkp0VJxJaiwPPJ/qG9 W2+tKp1cZ4cKE83I10Q28XuK10zcaAnjjHkZaLOy4vODNtXYYr4Yh9qL7f+xCa2G1mWw KbLw== 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=YJEHAKvAxNWxnFfAtDxhScuhxeMydUZOlP+8nhHGWX0=; b=neEL6PRf75Mq5g1rJfCW5xmj1fDJM7mFj4YS17ROuvg4oK/D+/lkB6qDOk3QGOkGiU STgs1r/wasSDlFYvnmHx5TCwU71ytdVTvJuf8aY5u0WoWqQrAKJKhLQLUiYqRY245i6l 5mR5ihqL93bSfFoQP2HV1Pz7eRf6Aw2tL5CKRz7KqFYUHAJXYIs//PJTVgWpRRYMohG+ cH/7rNkjkDKXz+R/XPpDV2Ec2s3s/hsGyigi9srhAqAplafflcyLTmOdV4HK+OEpZsf+ jQKgOZoJYjjTbMgrR4KfKYiL64uYKdau1vHxstKoGh8PE8/kXxfZS2CCX1a/GnEBAJZf OotQ== X-Gm-Message-State: AGRZ1gLkHVEv6U19Qwzhd5mr3JOptKqKJ7PYhVEzW394hhfqG72D8E59 Wk6rprh6zoHgBo/fsYZx/I+LK6GE X-Google-Smtp-Source: AJdET5eVLyB9zinb0nsPtMKszllG8aW3RnJ+gXXt9wteGSb4ijtg4ZL+/mWqpLlZ9OsG3YFwMj78nw== X-Received: by 2002:adf:e34d:: with SMTP id n13-v6mr2579870wrj.158.1540675799672; Sat, 27 Oct 2018 14:29:59 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:29:59 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 06/16] sequencer: refactor sequencer_add_exec_commands() to work on a todo_list Date: Sat, 27 Oct 2018 23:29:20 +0200 Message-Id: <20181027212930.9303-7-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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. An obvious way to do this would be to insert the `exec' command between the other commands, and reparse it once this is done. This is not what is done here. Instead, the command is appended to the buffer once, and a new list of items is created. Items from the old list are copied to it, and new `exec' items are appended when necessary. This eliminates the need to reparse the todo list, but this also means its buffer cannot be directly written to the disk, hence todo_list_write_to_disk(). sequencer_add_exec_commands() still reads the todo list from the disk, as it is needed by rebase -p. todo_list_add_exec_commands() works on a todo_list structure, and reparses it at the end. complete_action() still uses sequencer_add_exec_commands() for now. This will be changed in a future commit. Signed-off-by: Alban Gruin --- sequencer.c | 69 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/sequencer.c b/sequencer.c index e12860c047..12a3efeca8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4216,6 +4216,50 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, return 0; } +static void todo_list_add_exec_commands(struct todo_list *todo_list, + const char *commands) +{ + struct strbuf *buf = &todo_list->buf; + const char *old_buf = buf->buf; + size_t commands_len = strlen(commands + strlen("exec ")) - 1; + int i, first = 1, nr = 0, alloc = 0; + struct todo_item *items = NULL, + base_item = {TODO_EXEC, NULL, 0, 0, commands_len, 0}; + + strbuf_addstr(buf, commands); + base_item.offset_in_buf = buf->len - commands_len - 1; + base_item.arg = buf->buf + base_item.offset_in_buf; + + /* + * Insert after every pick. Here, fixup/squash chains + * are considered part of the pick, so we insert the commands *after* + * those chains if there are any. + */ + 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 (command == TODO_PICK && !first) { + ALLOC_GROW(items, nr + 1, alloc); + memcpy(items + nr++, &base_item, sizeof(struct todo_item)); + } + + ALLOC_GROW(items, nr + 1, alloc); + memcpy(items + nr++, todo_list->items + i, sizeof(struct todo_item)); + first = 0; + } + + /* insert or append final */ + ALLOC_GROW(items, nr + 1, alloc); + memcpy(items + nr++, &base_item, sizeof(struct todo_item)); + + 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. @@ -4224,10 +4268,7 @@ int sequencer_add_exec_commands(const char *commands) { const char *todo_file = rebase_path_todo(); struct todo_list todo_list = TODO_LIST_INIT; - struct todo_item *item; - struct strbuf *buf = &todo_list.buf; - size_t offset = 0, commands_len = strlen(commands); - int i, first; + int res; if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); @@ -4237,23 +4278,11 @@ int sequencer_add_exec_commands(const char *commands) return error(_("unusable todo list: '%s'"), todo_file); } - first = 1; - /* insert before every pick except the first one */ - for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) { - if (item->command == TODO_PICK && !first) { - strbuf_insert(buf, item->offset_in_buf + offset, - commands, commands_len); - offset += commands_len; - } - first = 0; - } - - /* append final */ - strbuf_add(buf, commands, commands_len); - - i = write_message(buf->buf, buf->len, todo_file, 0); + todo_list_add_exec_commands(&todo_list, commands); + res = todo_list_write_to_file(&todo_list, todo_file, NULL, NULL, 0, 0, -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, From patchwork Sat Oct 27 21:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658447 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 C35A31869 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B07232A87A for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2C9D2A8BD; Sat, 27 Oct 2018 21:30:14 +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 5C7282A893 for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728744AbeJ1GMW (ORCPT ); Sun, 28 Oct 2018 02:12:22 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45329 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbeJ1GMW (ORCPT ); Sun, 28 Oct 2018 02:12:22 -0400 Received: by mail-wr1-f66.google.com with SMTP id n5-v6so4624650wrw.12 for ; Sat, 27 Oct 2018 14:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B4R3hhpNf5tIvJN89OINaBT1z/TklK5zIjw3VyVjsuk=; b=G6zSDYdZE2K6CwHViDBa4wLmoEYgU/Rvw2DfSNPqqIlbTKX8i5W0ngKVsBijOtUn/J HK/+jBiNRCzWhykQjsQrv5dCJoLw5rEYrBJ3Pr3g+18LdOqmOn+4EQlkzFskchWK3ez+ Mwbt0L+Bsu6HS1cVO14GP7SDvgscbZKLVYy4P4iNaei9/af5JEA5ZXpKlon+OVAZRN7O lx0FIwIjCvP6vGBrrKLPsm+wFEwEuWZaYmb3mmoyyOmnLtXJCKtMM7QrOdK1y1yvUe2m aSzkEItRMdxN8jCyJK/FM3N8uGacz3Tu1w8sW9toFtfaTMHoxy+BYI4n3xio9HDVINd8 PAfQ== 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=B4R3hhpNf5tIvJN89OINaBT1z/TklK5zIjw3VyVjsuk=; b=EDcyBwH+uBSzPXGFO2Su5UVyWm51J5BRlPoUR41yluDI7fMqEUP64odjv0eKfOJdmE nlR57TURb+3M4GJX07+n6LklP9iXlOuMi0wLDg/BhYinEak5w/MhknYc3/GnjHySyTi1 +t3rqv4Rnn2fLY1xrPSO6VbC9OQsMaVB9TFeL8V0OiCzwtRbsMXxgW5S2aJqFDvssdd/ NDxLjxpp7HxW0ImHgsCY+lSeKYoz6yYjBrvhz6/kjbtaD3cArrMEvZPiixXGkhvn2TPh 6CARkuV4k66tH9QvohBrl3dEnwcSMbai9Vo24fLYZ/jw2nmG8UDB2ztZ2rNXd+4tEnzP Qm5Q== X-Gm-Message-State: AGRZ1gJmeM8snWzBZjdhZYskOXIXyBnHmp/fJTKLKlOotqgvWKqx7phS BVFoFvlMPlz+hXj6rayN2CDYVuVK X-Google-Smtp-Source: AJdET5ftfg5zqF3Dih0qxtxB3CW5BhjIEi1CC9oE5EnjGtHMpYQtGZY+A8Ig/odxUH69G1t6KHcZCA== X-Received: by 2002:adf:ba06:: with SMTP id o6-v6mr9269325wrg.249.1540675801227; Sat, 27 Oct 2018 14:30:01 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.29.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:00 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 07/16] sequencer: refactor rearrange_squash() to work on a todo_list Date: Sat, 27 Oct 2018 23:29:21 +0200 Message-Id: <20181027212930.9303-8-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 c1d87c0fe6..f827e53f05 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -258,7 +258,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(cmd); diff --git a/sequencer.c b/sequencer.c index 12a3efeca8..09e32f3e5a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4523,7 +4523,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 (cmd && *cmd) @@ -4629,21 +4629,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); /* @@ -4656,13 +4648,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; @@ -4675,7 +4667,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.")); } @@ -4710,7 +4701,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++) @@ -4723,7 +4714,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) @@ -4741,10 +4732,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; /* @@ -4755,37 +4744,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); + memcpy(items + nr++, todo_list->items + cur, sizeof(struct todo_item)); 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, 0, 0, -1, 0); + + todo_list_release(&todo_list); return res; } diff --git a/sequencer.h b/sequencer.h index e203930084..0c8074cab0 100644 --- a/sequencer.h +++ b/sequencer.h @@ -139,7 +139,7 @@ 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, unsigned autosquash); -int rearrange_squash(void); +int rearrange_squash_in_todo_file(void); extern const char sign_off_header[]; From patchwork Sat Oct 27 21:29:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658455 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 9A0A11734 for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89B1F2A87A for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDE72A87E; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 803412A89E for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728764AbeJ1GMY (ORCPT ); Sun, 28 Oct 2018 02:12:24 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:37312 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GMX (ORCPT ); Sun, 28 Oct 2018 02:12:23 -0400 Received: by mail-wm1-f67.google.com with SMTP id p2-v6so4414445wmc.2 for ; Sat, 27 Oct 2018 14:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v1OTV2eGl8iMDhc3lIUYPtqoNqiqHM1e5HY1RQE/RIo=; b=UdX1fPdemtPhry4gynmjZc388I3Jh7tzRJRDipfGXCM3PiHnexLGA6Oqf6r5WguJf8 WsH82ysvFdL+V2LTEnD2Y26jsPIaU/ZinQIORIdt/J3TNlPMe5lm08KM4Wi9/M1V5YOw or1JATvqBvR3RTcPU3G3FEwGx0cw3DPA87sXyD2qIY1sAEwZSOVAnw/iVGjTDC7nN6Du yYrbBfNL+PuXXAlNBDl/jyoinWuidcwAdgxRcuRtWn41VPWV3TXkzS82wBbevnlm21bG AULcGkuJ5U7edqM3rLZ3tPIhuYwGmK4YGAxB+bsGQOTe8dBgiHZWAeIIOspTGN20bnso h1pA== 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=v1OTV2eGl8iMDhc3lIUYPtqoNqiqHM1e5HY1RQE/RIo=; b=YUDFuQoW8o6zNCdHhEGMlo6T99+qm0IqFm7GDLjUglpS7kcp/W+ZF5mjoowE8BW3TL 4cNViP30ubHop1I3tsREs7GDRhB5YvNtJAofrhS9AU7fb4FPQVeQiljWzteyg+vUvcpx b7Qr7PGZHWsqxGdZYlB30EN0loHTx0rXo9W2awqmcnYXz1MRwxQfGEdOdhGad+sTJiP7 rjYG9CeHWWQc9cOI64gPicQWX1GRecwsBrn2mafWAEnPW8dxkBbVMCnYcEZZiPX6Yfsx SNwigma88SJkJKxZlgfsolk/Rzt5t3A1YTUFiDhGw2tWdqZKt6FVK96WSAVhrLNHKdZi N3iQ== X-Gm-Message-State: AGRZ1gIvRwNAdGcGCtLlZjoCuDTMRXR950JwT7rYTEXe3IzkDnd0RM/u 37PHjdIeB9klmkupw1JBVBZpuX6M X-Google-Smtp-Source: AJdET5d3jQDHGosfV7ldyfPdXAw0Nxu7cN6FOMfjp5JDL2dQs1+JXpbED0isklOmKZzegOpVtGHi0g== X-Received: by 2002:a1c:d105:: with SMTP id i5-v6mr8930800wmg.69.1540675802491; Sat, 27 Oct 2018 14:30:02 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:01 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 08/16] sequencer: make sequencer_make_script() write its script to a strbuf Date: Sat, 27 Oct 2018 23:29:22 +0200 Message-Id: <20181027212930.9303-9-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 f827e53f05..eef1ff2e83 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 09e32f3e5a..94167588a2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3927,7 +3927,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; @@ -4076,7 +4076,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; @@ -4086,9 +4086,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# Branch %s\n", 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)) { @@ -4101,8 +4101,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; @@ -4115,12 +4115,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); } } @@ -4129,11 +4129,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); } @@ -4155,12 +4155,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; @@ -4203,16 +4202,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 0c8074cab0..5af96723e6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -129,7 +129,7 @@ int sequencer_remove_state(struct replay_opts *opts); * commits should be rebased onto the new base, this flag needs to be passed. */ #define TODO_LIST_REBASE_COUSINS (1U << 4) -int sequencer_make_script(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(const char *command); From patchwork Sat Oct 27 21:29:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658437 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 395CD1815 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 267A52A8BD for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AC0A2A892; Sat, 27 Oct 2018 21:30:14 +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 A25B92A8BD for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728796AbeJ1GMZ (ORCPT ); Sun, 28 Oct 2018 02:12:25 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33922 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbeJ1GMY (ORCPT ); Sun, 28 Oct 2018 02:12:24 -0400 Received: by mail-wr1-f67.google.com with SMTP id l6-v6so4671236wrt.1 for ; Sat, 27 Oct 2018 14:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xQjWbAa1AqPLBhKMxBHgI1DXTTvMfufvppHI61as7+Y=; b=smkxkcqup5yd+sEF9+joMXvCpO9ZzViAbYaBdRNHaAeu3R9XygGYEx5Yuw12uXHrPx P3na8fP/1LPtmn6ieqtU9w9JNyNlMaV/UO8M6MiUKwdWXdBgdUVP/IzJI6VoAURXEinf bDWTZS3Ywc8pjwVLxfDPl1R1Ibv80VsgloqbswbfJLp0GjnyjvDcG6Z4IEjKWok//uYP /RqGgz5tcUiiqKQ8sZwfA5MGQH5EjioySxS03RsOMZc06/yWTp4lwcRScTTfcRETpDVH 1w6ISmAeWVeioGVyDk24kiOqGGTbBsixZBf7gZOLogPRW6u1bc8JKfhvAceP5hE3+Crp SxJA== 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=xQjWbAa1AqPLBhKMxBHgI1DXTTvMfufvppHI61as7+Y=; b=C3eUG1rVNEjGAKD1HJWjaKXe9muws/I5cwxT5vyPxTpG0jcCTp2BL0nEmAekqe5y0x ygchz1DdIiYYVAoypZwQOlpSDBnxzAnKruxgnY99eDG9BnmkM/zDK8Mce5XId/tBLhlB T/k7BPjv0dyMQiS1/qzZE6rtwMZKiDewpZqI54Wr9svP7UZGSgXZ8MPZUUqYSpBJmEmv ldKYi/Sfz98rjm1ezNHhNU/MqGVt4KUkP+p4CRKNJbTgmkP01xtuthw8OvanS0mtJKsB cpNTAmLItjy1+q/SoOcQhQtfrXGNej0pxMOtYN0IRPx8HuYILGEk+f7v7noleP0qEmwI NbSg== X-Gm-Message-State: AGRZ1gI2um/wX4FrQXRjvYcdjMLPHPnEA20gql/9fNUjzdLUHLM7Wgm8 Y4xU1Oncbu3b7XbDESrZ1nZqByay X-Google-Smtp-Source: AJdET5cC3Fmir0olxnPR5VLVhpfE6ZdE5XloxLWum6F+chmLalhvcdjMUYsG1OyyddSLeWnMmM63Jw== X-Received: by 2002:adf:f00a:: with SMTP id j10-v6mr599722wro.170.1540675803884; Sat, 27 Oct 2018 14:30:03 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:03 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 09/16] sequencer: change complete_action() to use the refactored functions Date: Sat, 27 Oct 2018 23:29:23 +0200 Message-Id: <20181027212930.9303-10-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 | 82 ++++++++++++++++------------------- sequencer.h | 2 +- 3 files changed, 42 insertions(+), 58 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index eef1ff2e83..c07330bdff 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, cmd, autosquash); + head_hash, cmd, autosquash, &todo_list); } free(revisions); diff --git a/sequencer.c b/sequencer.c index 94167588a2..1f7579328b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4501,93 +4501,85 @@ 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, const char *cmd, - 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; + int command_count; 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 (cmd && *cmd) - sequencer_add_exec_commands(cmd); - - 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, cmd); - if (count_commands(&todo_list) == 0) { + command_count = count_commands(todo_list); + if (command_count == 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, command_count, + 1, -1, flags | TODO_LIST_SHORTEN_IDS)) + 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, 0, 0, -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 5af96723e6..4a051e5dc9 100644 --- a/sequencer.h +++ b/sequencer.h @@ -138,7 +138,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, const char *cmd, - unsigned autosquash); + unsigned autosquash, struct todo_list *todo_list); int rearrange_squash_in_todo_file(void); extern const char sign_off_header[]; From patchwork Sat Oct 27 21:29:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658441 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 684B613A9 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 548052A87A for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 404E92A892; Sat, 27 Oct 2018 21:30:14 +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 C72072A8C0 for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728814AbeJ1GM0 (ORCPT ); Sun, 28 Oct 2018 02:12:26 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39789 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GMZ (ORCPT ); Sun, 28 Oct 2018 02:12:25 -0400 Received: by mail-wr1-f66.google.com with SMTP id r10-v6so4654454wrv.6 for ; Sat, 27 Oct 2018 14:30:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aCgVNTzZJiwcvEjaMFRkG/5QvG1A98RiznOWATvKmu8=; b=Rq79OkZb9nmjXQbPs+qdEK2ssg9qyuE3J2zcaEccOgVbq28bgRwpRcgD1wRw7S8lmU EaZ5HfEaQNSflksnSR4WOSwH9ZrPupZqBgbWv+HyaaEc0C8gO2HWL7dMuBK7qM8gTSzJ K+CVCf0mrautqNW8uEGyxXpFAf/Je3tzDqXpRnDPoqr6ogCrR7fQPDAnmFdONl7zyoq/ P4l2rnv2xc1QM2JtTIoh2/01PqxS84o1ONQl9U9adAxKN7rwXm86Q/hUmNDsx31Wm54a qM5I7Yu/4qJkx/eCKKne8AUwyBzMQHC7yWxNbLozenAqx7EfkOv7lZkyKb36VlvFJTJ2 plnA== 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=aCgVNTzZJiwcvEjaMFRkG/5QvG1A98RiznOWATvKmu8=; b=VId1Yvk7YBm2BC/ZQcv8u/5mx20qm11FKJcX/FLbu+1jh1rf6m1LgDplLHkB0H3+1F 1Aodn3IKeKtMBZo+coqqWchXvCtgh4nOm3xotqYPty2xq+WHHjptZ7duXQdNDK4NcHRQ B6Tz1GiSr5FkSpj8ZfKxCGW90hUHbaWP6KH6O4zTDlp1qZ2Wdabt/U3MngdvcbiRGvKV zvaFffhhjzkbAZp8DkFvI1Kic6TAHztwvQahTdR2YliN5wxhR2I5W5SWV1O/KCcfsDpY bIfFE50MJ22My5OagUxovzegAcxqCbw2+Iz40zayjJTpFkc+XGn+iQWITpmDrdFwxCJy 9I1Q== X-Gm-Message-State: AGRZ1gJbfVv2o/21WZDU1TkwWwLxJveuBsuOb1ZPGbbt+MEhI7wv5BDE Rk99NJt6MtHxYHxluXXrnd+0XzF+ X-Google-Smtp-Source: AJdET5dH2ilmtXbYJ1d2jXrOIKRz4mIAcB54K2InP5bjUMVBYtB0jOp3r7QNgyaCOJrY6Rn65WLWIA== X-Received: by 2002:a5d:4807:: with SMTP id l7-v6mr404974wrq.46.1540675805310; Sat, 27 Oct 2018 14:30:05 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:04 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 10/16] sequencer: refactor skip_unnecessary_picks() to work on a todo_list Date: Sat, 27 Oct 2018 23:29:24 +0200 Message-Id: <20181027212930.9303-11-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 | 80 ++++++++++++----------------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) diff --git a/sequencer.c b/sequencer.c index 1f7579328b..7286498572 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4408,52 +4408,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)); } @@ -4467,37 +4436,22 @@ 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, 0, 0, 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; - } + memmove(todo_list->items, todo_list->items + i, + sizeof(struct todo_item) * (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; } @@ -4573,6 +4527,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, 0, 0, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) { todo_list_release(&new_todo); @@ -4581,12 +4540,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 Sat Oct 27 21:29:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658439 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 56AC61734 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 429232A87E for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E6F02A87A; Sat, 27 Oct 2018 21:30:14 +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 E71102A87A for ; Sat, 27 Oct 2018 21:30:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728841AbeJ1GM1 (ORCPT ); Sun, 28 Oct 2018 02:12:27 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54326 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728630AbeJ1GM1 (ORCPT ); Sun, 28 Oct 2018 02:12:27 -0400 Received: by mail-wm1-f68.google.com with SMTP id r63-v6so4574007wma.4 for ; Sat, 27 Oct 2018 14:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PCeDv8G+h2RyEYqlIXfSOiKgULZocdWvCmLrn/VQwb8=; b=oSkHk0JgEHyxQYVbztI4GLau7qvAR3tnQUejYmmAJZ6Ggiokn+B7VCbi0ijWXOWkBy U9+Qf1NRNq/SLWrhuzdPiLNbVHyzxdGW151I82VRrjKZIVX8f9tzTNWvHDoaKeskOurl VMfLZnRFJ3XtnBeruEVxbJFvlhayjbQ8J8OuuXMM2GlcYUqMKaP2dCFvE2FbTW7GDU+c x6g/NgdGs03K9HmiWBcnhXhBiCyUyXxgQh91RZE+d+4azxQ/cDfF1S3sxQOWCDWdXDH5 dmhNYHMpuPyGECXuAcmB3GjqvayJgAIemdN5ZKLo30rOIGZJS4r6jIH22ygaKpkYjL+D ojKQ== 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=PCeDv8G+h2RyEYqlIXfSOiKgULZocdWvCmLrn/VQwb8=; b=RM2uQ7OMsvUVK8ck0Uhkk7X1FpkAzed9rgcFnx1Q6d239Tb3Geg+A9W1HY67V4XK2b Uk9V/m+Hbf7oXodRcLsmj9w92VaHrHC9T7yWWCklXxrCbUO/VPA+9zuhwNc73a5AbjC1 y7Gw6uoiUnWyR/60VC0hNutEmMAD+EJNMLbFXANMdglG93ja8JLP5LWLIcWW11CDkl6u fly2ugEEHTf+Abr4xFwkROBLF7u+Xuf7z4eAv9yhuvNCTUbI2UEIDFLun2FuEbWwSci4 373l3GpfqFaTMZWnbJF63XEjeWPtEwL6bJQFBNtxHF5PFJqN2JLm+MvCQ75/+Np/onGi UfPg== X-Gm-Message-State: AGRZ1gJDTqOLJ1nCWWPI0+qfrMedWa8N/3LWeejtr6MsebLAHD2uaKMO l2rw96OzTwRpwfvXNBN5JOMkLMhH X-Google-Smtp-Source: AJdET5cbRoA+xUaoimm9K15Z07X3KJVEzepL2EwtHxWRmn/ESTFFu2/sIadnAeGBPsxrJdmHZaZKtQ== X-Received: by 2002:a1c:f53:: with SMTP id 80-v6mr8961789wmp.58.1540675806430; Sat, 27 Oct 2018 14:30:06 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:05 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 11/16] rebase-interactive: use todo_list_write_to_file() in edit_todo_list() Date: Sat, 27 Oct 2018 23:29:25 +0200 Message-Id: <20181027212930.9303-12-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 9e81ecfe9f..b2be99a900 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -78,39 +78,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, 0, 1, -1, + flags | TODO_LIST_SHORTEN_IDS)) { + 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, 0, 0, -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 Sat Oct 27 21:29:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658461 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 3D3EB13A9 for ; Sat, 27 Oct 2018 21:30:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DA692A87A for ; Sat, 27 Oct 2018 21:30:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 225132A87C; Sat, 27 Oct 2018 21:30:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23D7C2A8C5 for ; Sat, 27 Oct 2018 21:30:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728866AbeJ1GM2 (ORCPT ); Sun, 28 Oct 2018 02:12:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33927 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GM1 (ORCPT ); Sun, 28 Oct 2018 02:12:27 -0400 Received: by mail-wr1-f66.google.com with SMTP id l6-v6so4671346wrt.1 for ; Sat, 27 Oct 2018 14:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ze02cil/vNrIRx8iSri4WwyS2toGFJdwfz1K92pmNis=; b=vb1IAbxNxlpgzNKZiWZOhrzbs+A9Pojw7PcCU5d4Ha0ZZzcx090Rki4rR4ACAQlNig v5n75pZku4oyVUiuk7Szy6xI7HkTdLgyY+9FgZoDT/dzvs2nedgpiSw1Qw1snqymmjxM hUad7iWNLv9UqhAztq+sXHm6DC85JZRl3e0tYS6kcdD8S5ygkrip7OCESAK5RphTD6RR UyHFxEwirDjgj9dkPRNfLACoc5ZmTBvYTlwqQmxkEP0Aiwb2bPfd6xs/FWRul+hiZh4J 5xhGqL7+3LBJu5Wm20WrdR8hyV+o5Viynkftke6JQt3fMg6L2536pAgfooNvBw8jRSYw vQwA== 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=ze02cil/vNrIRx8iSri4WwyS2toGFJdwfz1K92pmNis=; b=a5SyOYPOQC3mT5AU2dBH0TEua7FafpAbFRVhjXrZPSNZP+KVIV19zDirK2xBo2D0qi 4Lgs/nimwAWJmPMyZIgqj0rqO4oFOd6qJ4JCTMCepNwusREZDIyw4Yqkh2nkl9RfGuN5 6Vbi9DxptMChyWEGcw3pT4q0wJYi+h0dbdOGeHD1tmZsVRHxI0rjwxciT6Ms6fsSlXpx BX4xH0X2yd7k0lYfGX2VnOEknLU4KIfWMpr0SpUQDbT8D0gtrsF+dZAekTq/lxQ/XZBz TewSeGM2tRbEJCyvJPxHubofbMzf8ks0SD4vAqJWp+NcbCkO88HhY4ldxGdqq0dURmSS qdxg== X-Gm-Message-State: AGRZ1gJpO6SG3OEWTyTOatLzqmPeyZxKbE2I8lAqTWvWMU8l1HMfhfvQ zo2D8k3/J87rmX8ZBLII3hj2XEbc X-Google-Smtp-Source: AJdET5cJ8Rtgl+eZsEmy2/9jtHU8bzrRH6aWleNu74OZZEPehhC4ys6EhZhishniQJpjWskxeummkA== X-Received: by 2002:adf:b211:: with SMTP id u17-v6mr9244324wra.52.1540675807731; Sat, 27 Oct 2018 14:30:07 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:07 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 12/16] rebase-interactive: append_todo_help() changes Date: Sat, 27 Oct 2018 23:29:26 +0200 Message-Id: <20181027212930.9303-13-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 | 16 ++++------------ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index b2be99a900..0643d54b1b 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" @@ -47,6 +48,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 7286498572..4c664d6388 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4331,21 +4331,13 @@ int todo_list_write_to_file(struct todo_list *todo_list, const char *file, const char *shortrevisions, const char *shortonto, int command_count, int append_help, 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 (append_help) { - 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 (append_help) + append_todo_help(flags & TODO_LIST_KEEP_EMPTY, command_count, + shortrevisions, shortonto, &buf); res = write_message(buf.buf, buf.len, file, 0); strbuf_release(&buf); From patchwork Sat Oct 27 21:29:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658445 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 CCF45180E for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC4162A892 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA7BC2A893; Sat, 27 Oct 2018 21:30:14 +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 2B7372A8D4 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728901AbeJ1GMa (ORCPT ); Sun, 28 Oct 2018 02:12:30 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37320 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728578AbeJ1GM3 (ORCPT ); Sun, 28 Oct 2018 02:12:29 -0400 Received: by mail-wm1-f68.google.com with SMTP id p2-v6so4414600wmc.2 for ; Sat, 27 Oct 2018 14:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fiTVaqhHfnTlT931VePo4pnccI7cy+hFNPddHioYj/I=; b=j/ybay8pAMT3HW2xTrUWlPW7T+Mh4kTH4bSEl3taJ6fnrsv2Cs+MtydMCuZVUM+CMO wg+Jw5tKagcR5wG8HtYqDXbOL7kVesUT5P/2WUuoGYNCMnZyxVOVeURs1nGwBReX827L gFMFbKNcauujgQ67mf6yY/ifrG9D3lY0a3PKetQ1GlfsdKYeUVMyzPoczG1CDTkWHzEN 6Vizv/1AafhbtBpHTVfU36Yq+PEOkI6uqv6C/4kjZ6cpSrixJ7CR+79+iFz/ipSmuztm pMnGbn9eteEmR9RSYKFoyBvSdHjcuPzLGMOIrNAQrjWMm78FIAW4MKUBK+0Phlt4uWTz pBzA== 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=fiTVaqhHfnTlT931VePo4pnccI7cy+hFNPddHioYj/I=; b=udveatjJN4cCKhyyZGfaNtljyHuoyuNF6nLcPIZdqvD4yXUP4+Hw4BhUzUy/hSvvx8 HUPAjlTHQSf3s+fb8s/78/JuwB8WmgSnmk/HOl8oGq51VAAQbpgFuDDQOihahpNzSTp1 XRY/VTI40SiB+yGVULUoBihq5oLoYt6908rZoJa57yuyicdEpvCrfntByFLRtXZvVXyt xClqv8g80n/XCH5AMCCL7naNrtGQ0JSuH503sE1JoCC3GSaZ+4/0FrKSMALEdED6ucs5 OOQJHCkhI4MupC5JzZcR5ktBZ9vRm6z7OZpQU+H7SOrpxu3W8Gh4fy/OkDGJBEU8n8CQ LYnA== X-Gm-Message-State: AGRZ1gIR+A4NeoBFWE9/ekG7JCINyey1eIa0Ixj7rCaAN5Aml8K64iTJ tYANdBH/o6tt7jIGxJtKsZ7HFEJh X-Google-Smtp-Source: AJdET5cPpJnyROn5BnTbdA4/kCKtXAr82APT1bHKoxeKTEsjVAFRF3Jazoyiu9dmR8vEghIiYyaaSQ== X-Received: by 2002:a1c:f313:: with SMTP id q19-v6mr9035569wmq.87.1540675809046; Sat, 27 Oct 2018 14:30:09 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:08 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 13/16] rebase-interactive: rewrite edit_todo_list() to handle the initial edit Date: Sat, 27 Oct 2018 23:29:27 +0200 Message-Id: <20181027212930.9303-14-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 c07330bdff..0f83422aa0 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, flags, 0, NULL, NULL) && + todo_list_write_to_file(&new_todo, todo_file, NULL, NULL, 0, 0, -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) @@ -234,7 +255,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 0643d54b1b..d7a0818ac9 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -86,35 +86,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, + unsigned flags, int command_count, + const char *shortrevisions, const char *shortonto) { 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, 0, 1, -1, - flags | TODO_LIST_SHORTEN_IDS)) { - todo_list_release(&todo_list); - return -1; + unsigned initial = shortrevisions && shortonto; + + if (initial) { + todo_list_write_to_file(todo_list, todo_file, shortrevisions, shortonto, + 0, 1, -1, flags | TODO_LIST_SHORTEN_IDS); + + 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, 0, 1, -1, + flags | TODO_LIST_SHORTEN_IDS); } - 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, 0, 0, -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..83cde455e6 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, + unsigned flags, int command_count, + const char *shortrevisions, const char *shortonto); int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); #endif diff --git a/sequencer.c b/sequencer.c index 4c664d6388..a03505f582 100644 --- a/sequencer.c +++ b/sequencer.c @@ -54,8 +54,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 4a051e5dc9..6a1a23541f 100644 --- a/sequencer.h +++ b/sequencer.h @@ -4,6 +4,7 @@ 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 Sat Oct 27 21:29:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658449 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 04A33679F for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8CB72A87A for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC9032A892; Sat, 27 Oct 2018 21:30:14 +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 8692C2A87E for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728924AbeJ1GMb (ORCPT ); Sun, 28 Oct 2018 02:12:31 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36881 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728869AbeJ1GMa (ORCPT ); Sun, 28 Oct 2018 02:12:30 -0400 Received: by mail-wr1-f68.google.com with SMTP id g9-v6so4667650wrq.4 for ; Sat, 27 Oct 2018 14:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hkLQIlxbYOmzOXiqw2TYR990BYzjLe+X1gdiMoGGy0g=; b=BozxwVFsYugijPldUEyIP3aWIHqHUnNOqhWO/dIhdC09QLfiTzV6mrMfEQXVyCUrL2 1aJ/p7GP5AQ/A4BIEz8BBC5TQZovs2+yYRPq7mP3Lyo6QFVppXUn9S/oajkZXJW6ykFu geujmE2/Z1UiW59BYA+6QR3YEre1tfkYn6hSuvO99qXZcOxefpFFMhwy7upPfVgqZAMZ KE4tmHi0QReiD0NAcH0vJMVKWTupOKJG05Mhjv8O8bWO3wt7QWMtcocgmCEsmDB1vhti QFhVEDwSiUM6RDEp836T0FH4hIfhtv2NG9TmIG3ZhV8l6tbCCc7BoFMqfP9Q7L4cZldZ VaFQ== 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=hkLQIlxbYOmzOXiqw2TYR990BYzjLe+X1gdiMoGGy0g=; b=UD85BBdRlkC4BRmfq876be/vFJWgUVrK1P67T8yX+hIBu848x10HGLd2Zv8B8DFCWH Wn49+5ChlfimdLzsZS/lkZiv6IyDF+gV8rm2gI40y0E0+zFGJe1g8Vxk0shOQZABISfn 1WiTVPFg9p1FAeUQcDg/mB/eglgPAk1OMwR1xTz13qkhTFZKElFCM5oQg2s3gpCKlPKa gb2ODuvgHcQg9UDLC1PF6zxHNNi9p3WSvtnAVG4oDk5ODGYyLtmFc3z19wJAC4ZHFruO sSlPWW3W5uLWQX68kGQbD0Vzdgw1tf40teyGfNmqkMt6/pNly2IH8CWOv6GzTWn5RYOf ZBrQ== X-Gm-Message-State: AGRZ1gJR8Zekwii549eQ8hzDXqCBW2TQs8wiH50HL9NhCK1kenG5SCa9 HMpwrrK1BVI5wPJlCLsPOAb9Xs6R X-Google-Smtp-Source: AJdET5e3cePGK/mURbqrr/3N+CvC2NvMzIaceC7OOVYwp9sgkR7r1DybtqxLU7wqNbPMZ3QbXDhrPQ== X-Received: by 2002:adf:db0f:: with SMTP id s15-v6mr9402591wri.129.1540675810062; Sat, 27 Oct 2018 14:30:10 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:09 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 14/16] sequencer: use edit_todo_list() in complete_action() Date: Sat, 27 Oct 2018 23:29:28 +0200 Message-Id: <20181027212930.9303-15-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/sequencer.c b/sequencer.c index a03505f582..0763eeae25 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4457,7 +4457,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 command_count; + int command_count, res; get_oid(onto, &oid); shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); @@ -4484,24 +4484,16 @@ 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, command_count, - 1, -1, flags | TODO_LIST_SHORTEN_IDS)) - 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, flags, + command_count, shortrevisions, shortonto); + 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 Sat Oct 27 21:29:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658453 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 484C61815 for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 372C52A87A for ; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B6CF2A893; Sat, 27 Oct 2018 21:30:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC4682A882 for ; Sat, 27 Oct 2018 21:30:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729045AbeJ1GMc (ORCPT ); Sun, 28 Oct 2018 02:12:32 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46552 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728872AbeJ1GMb (ORCPT ); Sun, 28 Oct 2018 02:12:31 -0400 Received: by mail-wr1-f67.google.com with SMTP id i4-v6so4622210wrr.13 for ; Sat, 27 Oct 2018 14:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RHGdcqnr9zOxdtn3J0UauDXk0QNZ8e1z6SbkxzukjKk=; b=kFGh2wYMz516j/orrmcfoJfEYk3MnOnOConiifZhI/A7iKg7Kd6mZTUoGAbNDbsSj9 4MPGrlOmy1KF2rC9sjohKkrB9yjeteyi6pIC/u/w+RQMf2J13A4ZT8eFb1R7fIbD/DQL zfvMa5b0Ey8Bya0nwqxqtOuHLAjgSNhUG06uS2Jr2UmG5pEdWxGIXRFogng6/+RzBI+Y qlXxzSB5CsdWjqlgfcMFdOSxNyQtSj4KyZP+RcClCeJwQ3OND2aJNz6yx7S6ds7ya8y3 jYp/HK1swHWgYQow0g1n6Qgy1Fk3vlQXhgKbMmCilZUyqn7Uf39Q0sN3vANfSex35ew2 Jgfg== 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=RHGdcqnr9zOxdtn3J0UauDXk0QNZ8e1z6SbkxzukjKk=; b=HUQE4qt5ulDS3EFdbuvS6MeLYMfOdegsw13TbO+Ahd/LK7VPx/ynivKTYwNr+xXTK1 R+3cAI/444gw7IvHjNVod5wyXTXtLVk/TrFrFd0Yy3FSO1wCgxn3/2+TSgZ81aEmqmC9 QE6uY/N+Ya5dn4MtQTHkAtIUj4j6P7kBtQgzarw7qMvBRfTFhtjBZDmpMnowlW0nbyBt Vwu3bGNPM/VkqH/whgdOOmH4AQ4G2uD+7+tB05krH92+Ukvjgnm9v9oOYF8FyC12mjR1 NcpfBS+YpyV8TTKyd34yL9J+i55F5Rql5J2NdDUFN71yB9nwYDleoRRjtLM+8x6VWzca xYfQ== X-Gm-Message-State: AGRZ1gIqyLdAfrajNDVXj1peSGLy+8DT0HZIa5326ZSCSHMCkHurntpA DqJdBgowQGM2hJna5TeIhM81zidg X-Google-Smtp-Source: AJdET5cuAukef9KPgdS8r8DwFiuetMZGbsZuLdOlywh9zr76mrHkB9uEf5KjsFyw0fbRkyZWqajelg== X-Received: by 2002:a5d:6b0f:: with SMTP id v15-v6mr9228973wrw.53.1540675811179; Sat, 27 Oct 2018 14:30:11 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:10 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 15/16] sequencer: fix a call to error() in transform_todo_file() Date: Sat, 27 Oct 2018 23:29:29 +0200 Message-Id: <20181027212930.9303-16-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 v1, was commit 14/15. sequencer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 0763eeae25..3069d4c6a2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4351,7 +4351,7 @@ int transform_todo_file(unsigned flags) 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 Sat Oct 27 21:29:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10658459 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 2E16C1734 for ; Sat, 27 Oct 2018 21:30:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D8D02A87A for ; Sat, 27 Oct 2018 21:30:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11B502A87E; Sat, 27 Oct 2018 21:30:17 +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 81E212A87A for ; Sat, 27 Oct 2018 21:30:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729053AbeJ1GMd (ORCPT ); Sun, 28 Oct 2018 02:12:33 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46552 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728869AbeJ1GMd (ORCPT ); Sun, 28 Oct 2018 02:12:33 -0400 Received: by mail-wr1-f66.google.com with SMTP id i4-v6so4622231wrr.13 for ; Sat, 27 Oct 2018 14:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KVVoEirU5fqtOAMsVePQdF5wwdY5YpHK6TeQ8d0FceA=; b=jkQ19oEYMm6WffdtD5hqTdFrsF3B93RxkxP1Yn++TBPwXxdKRWxzsfzGvlmrN65Xj1 jc7HgR+M86m4okmgQRWDT7b/rObj9fDF8GZr3MJUfmlKZJMX3aNMTa7RzbzmuyA/BEQv yxXxeO3cMGt4wRRM71tRrPQvtKWmHRjWct7mUfSMfD4ErSZCdH3a0vmt7zK7nuHhxumY DTh44458Zre6ut8lEWyZEmwmqR5sWH8h7xEprHzdD0K0oiu6Ujm5nOWLroXYMSuC9FTB 4wtybYI6Anq/eGn2PJ2GfKvu5qr4z1yHxLxnF/P7Ty0oXgBLPOKsQPgdkYcpcGPr8oHb N3hA== 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=KVVoEirU5fqtOAMsVePQdF5wwdY5YpHK6TeQ8d0FceA=; b=anPSdROLA1o2zna3N0L1jYb29VB0YGLB68P3om+7xFx7ekfVEWQpM6gQVHdnKDX8Op kX21FJuPR3R3PxI57ak6pMl+3ZnYbbPe5baVq/6oSdnXlgYDeOyZoIhMpCNTs8ewNIeS uq7vWkMcp6rpTBFdNAFLCg04ovaLce53v0ngYjv7RKy6zWfxlWUfwZ6DIAgmLLgbOLq1 XbcCqQlQ4jzl1YhduucRK3XzNuvWUx22ovX3h5bxa4graAn9g2zRrQ3Qjj6X3XHNFEff Wps3+LRyN0iMHF0Mh44CL3xcsWxU64uTwlCiTuQtxaXhfx2AERLBOm9MvK/LUJjY3XVe fuBg== X-Gm-Message-State: AGRZ1gJmtwIz64tyWWAV2FRXmocFwc/0c8vjNWKmhl0smwz8PPoVACYu mvhL7xaj9Ufop6U+OfkgSpLVLRC6 X-Google-Smtp-Source: AJdET5dsKIt8g3XThybyjMokihXlud+l8I8VaovKTCUNjxylSPlBF/CmbCm557hj0qXJ0qu3tMN+1A== X-Received: by 2002:adf:e68d:: with SMTP id r13-v6mr861471wrm.239.1540675812279; Sat, 27 Oct 2018 14:30:12 -0700 (PDT) Received: from localhost.localdomain (atoulouse-658-1-19-179.w86-222.abo.wanadoo.fr. [86.222.18.179]) by smtp.googlemail.com with ESMTPSA id t198-v6sm9842514wmd.9.2018.10.27.14.30.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 14:30:11 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v2 16/16] rebase--interactive: move transform_todo_file() to rebase--interactive.c Date: Sat, 27 Oct 2018 23:29:30 +0200 Message-Id: <20181027212930.9303-17-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181027212930.9303-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> <20181027212930.9303-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 0f83422aa0..28e6947ecb 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, 0, 0, -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 3069d4c6a2..a1b81bd544 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4344,26 +4344,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_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, 0, 0, -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 6a1a23541f..d35ca61d5d 100644 --- a/sequencer.h +++ b/sequencer.h @@ -134,7 +134,6 @@ int sequencer_make_script(struct strbuf *out, int argc, const char **argv, unsigned flags); int sequencer_add_exec_commands(const char *command); -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,