From patchwork Sun Oct 7 19:54:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629705 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 08F1214D6 for ; Sun, 7 Oct 2018 20:00:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F003B28BA9 for ; Sun, 7 Oct 2018 20:00:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E40FB28DDB; Sun, 7 Oct 2018 20:00: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 9E17228BA9 for ; Sun, 7 Oct 2018 20:00:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727284AbeJHDIe (ORCPT ); Sun, 7 Oct 2018 23:08:34 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55450 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJHDId (ORCPT ); Sun, 7 Oct 2018 23:08:33 -0400 Received: by mail-wm1-f65.google.com with SMTP id 206-v6so6177612wmb.5 for ; Sun, 07 Oct 2018 13:00:09 -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=ueQh8l6flc0d1rx8nbhvfEB2UyugOrf5hpX173h/J1A=; b=H1q/ZFIjv0E5KiDY6UOtpZU3uxaTDl0U5CntRLSmBVqVf/hHw4LhcIH81ffbQx8FG8 286XK1duOHgyfn5ADXj/FuGpapsgUpQnspGSGwWp2VpulrKIDvGkQ+4smFws63Yxnlhh WUDklvECakYbEcNW5haBtILBMqb7flwzuS7zlurXCXphQGP2eRXreelg561PK+N1Fry1 T5C964BtCqjD+uR+nVCcin7tOlI4II9ssLfaPxqiYYpbNz3uySeO9ZMFm84h9gMXDUWK PMPSA3hXh9kHL7+NJ5U6VA3vwReEdeMOci8HUyW+8qUt7LlC+FRkmwj4+K7lvnaDqosH r3cQ== 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=ueQh8l6flc0d1rx8nbhvfEB2UyugOrf5hpX173h/J1A=; b=FZm8AmE3WG+Pgbp0t7gp30sbRNlH5O8CE+bhR/ooNrVEcnCugiUmCqFo7VH5uqX/b2 nSXFUFcuDr0sl2FeqoP/WAzWWH6arp10JVEfYhEne9mtnb41FZcWjQUbiSSJ7FwU2qFc ac9g/aytj2MQ8VrBfTxtZBcDr/3hMDItrEt+QYic+anDsVOyeMB7j3QvHwZwruqEuOFe lTcMn1ADm3761vxs2l7DS7rJFeHfUOqsVO5Y3ceYH7DujJUTELAGVfkbcCzZe7fArySJ KNdOGWIVc8fhL36oGSkNKniaoUl+J0uc9qluUqXovNHoDhFGSgIWvTrRrNTC7NIYybEm BpOg== X-Gm-Message-State: ABuFfoglCWwdj4R+qpqyOuWoMTtJnjjPazSGK1H9HkLGT6o1rR4IEiWS wZZFXE0lHfllSPK2UHOFFqqjJAAv X-Google-Smtp-Source: ACcGV62MYGlDtYRJ1tTZjl/yq/drwVSg2dY3jhLqFMlcEsjDpdx+gJMDKUPjrvtTibdD3/rfRpCimQ== X-Received: by 2002:a1c:8601:: with SMTP id i1-v6mr12865496wmd.148.1538942408290; Sun, 07 Oct 2018 13:00:08 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:07 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 01/15] sequencer: clear the number of items of a todo_list before parsing Date: Sun, 7 Oct 2018 21:54:04 +0200 Message-Id: <20181007195418.25752-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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. Signed-off-by: Alban Gruin --- sequencer.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sequencer.c b/sequencer.c index 0a3292d5c4..ed798b95d1 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2063,6 +2063,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'); From patchwork Sun Oct 7 19:54:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629707 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 57CB814D6 for ; Sun, 7 Oct 2018 20:00:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AAF728BA9 for ; Sun, 7 Oct 2018 20:00:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F0D028DD3; Sun, 7 Oct 2018 20:00: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 05C6628DF0 for ; Sun, 7 Oct 2018 20:00:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727658AbeJHDIf (ORCPT ); Sun, 7 Oct 2018 23:08:35 -0400 Received: from mail-wr1-f42.google.com ([209.85.221.42]:44270 "EHLO mail-wr1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbeJHDIe (ORCPT ); Sun, 7 Oct 2018 23:08:34 -0400 Received: by mail-wr1-f42.google.com with SMTP id 63-v6so18541123wra.11 for ; Sun, 07 Oct 2018 13:00: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=HLjRGmA5Nr28hviHtC8+wS6925KBgEIBRfTCYqrlMx8=; b=QQ9M3vYwp/MJgS9ot999IOuikcAYiL6BKgiLhnQoGTBFpH74EYgzavxQEK/Uha7ouY 7w/c8ODHaFRspYtnEF2UoegWPAB9Eagxx5xq7SRLQMPFpKO/rG8UtheK6Z28gaI/0rLC voNC2DxCW1Jmm+5+CWgk5JeWKSu1B2KarYjGIsbmbnvD2V6YI6W5An2lI+rz4tM1lkHB 9K8ahKhxzsp9apfloERARPILjsEwuP0kBpkQ7bY58S9dddCtvQ02WKFTJE534ZNPh9e8 4dCUu5Zgt0eZubTyQqvjBjuloR71TeY/EVg8XYSm6g1RMPa+HEfyQGgsjylIIADUk0eJ 4GUQ== 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=HLjRGmA5Nr28hviHtC8+wS6925KBgEIBRfTCYqrlMx8=; b=H4v3z5tlRwQBO0r65V/cweeR8q8q9jVilUlhgDbsyB+jUpAvnx7176Df1TaCNaguBf 9+RABewGZQVNGZ17FFz56gjkSOjLvCGcnFBxHcQzQNW731H/Yp72lRTJO0F4z0cRd/k9 d9ZGg9C/2N9mAuKzu4YM6/gG9M+60C1zWFqtWSMvwq5rJpdTjqfczE0a7SaNgS7sW165 +oGbhrfsvtOuiPEpnyNef10Zc6ijmBT+GgpaTFIeGEDKnb8q7fXMxk/qX0TQQO2SWACu EvcIVw8ubGJmiD6qt3tpsTm8OSgHmDeLd6ZY0zH360UN1xTzw3jdo9A8rN0s4kNHQ1If zLUw== X-Gm-Message-State: ABuFfog0NNX2Yrd55vV1LkiSRPQKY52Un4FBx9sm5cxiTGPGMPQH5t51 rg7RTT7DZ2Za2ZJ2QmoMjMlijIt6 X-Google-Smtp-Source: ACcGV63LmlzqA1yJ3GxUTx5ku4fdbjpm9lQCvyJ+utUm0ITwUA1KlLlhWasMzYr34x2JW5rwCO6eNg== X-Received: by 2002:adf:9f0f:: with SMTP id l15-v6mr14390007wrf.206.1538942409500; Sun, 07 Oct 2018 13:00:09 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:09 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 02/15] sequencer: make the todo_list structure public Date: Sun, 7 Oct 2018 21:54:05 +0200 Message-Id: <20181007195418.25752-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes the structures todo_list and todo_item, and the functions todo_list_release() and parse_insn_buffer(), accessible outside of sequencer.c. Signed-off-by: Alban Gruin --- sequencer.c | 66 +++++++++-------------------------------------------- sequencer.h | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/sequencer.c b/sequencer.c index ed798b95d1..bb8ca2477f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1443,31 +1443,6 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit) return 1; } -/* - * Note that ordering matters in this enum. Not only must it match the mapping - * below, it is also divided into several sections that matter. When adding - * new commands, make sure you add it in the right section. - */ -enum todo_command { - /* commands that handle commits */ - TODO_PICK = 0, - TODO_REVERT, - TODO_EDIT, - TODO_REWORD, - TODO_FIXUP, - TODO_SQUASH, - /* commands that do something else than handling a single commit */ - TODO_EXEC, - TODO_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; @@ -1937,26 +1912,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); @@ -2057,7 +2013,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; @@ -2152,7 +2108,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 " @@ -2183,7 +2139,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; @@ -4429,7 +4385,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); } @@ -4485,7 +4441,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); } @@ -4571,7 +4527,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; @@ -4590,7 +4546,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--) { @@ -4672,7 +4628,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; } @@ -4760,7 +4716,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); } @@ -4868,7 +4824,7 @@ int rearrange_squash(void) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } diff --git a/sequencer.h b/sequencer.h index 660cff5050..c786dee543 100644 --- a/sequencer.h +++ b/sequencer.h @@ -72,6 +72,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 Sun Oct 7 19:54:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629709 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 4A21B14DB for ; Sun, 7 Oct 2018 20:00:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3CCDA28BA9 for ; Sun, 7 Oct 2018 20:00:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30EB228DDB; Sun, 7 Oct 2018 20:00:16 +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 65AED28BA9 for ; Sun, 7 Oct 2018 20:00:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbeJHDIg (ORCPT ); Sun, 7 Oct 2018 23:08:36 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40847 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJHDIf (ORCPT ); Sun, 7 Oct 2018 23:08:35 -0400 Received: by mail-wr1-f65.google.com with SMTP id d2-v6so14124551wro.7 for ; Sun, 07 Oct 2018 13:00: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=B6XZDcYGXwLLw3RNVaebrTL5STZRjY5PFBNzt7FntZs=; b=ih5QoRq00GvZ71lzZjMz0NxD63VCB3hRVbsqeB5M0y+Yi+CfdS7WAIzmYLSIBESWdX k1kECIm3qKb/Dt9zQ5b7tQONS7NObkhoNBm4BM0iCLeErtH4AfSEhhsyqAreWx49i6k8 JPoUbiDU8xCK09fERqS35P/uNOPZ8WSqlgSQ5UYaenfrqbHn9A0GstZIlviNJvM5jv6h rOqF+YXbvSig5NdZIISKkV8J+ieyUNyzucLqJ2mpOgkVP8kjg7ZLa1Yduct3njXqVvZY x1cqylludPXYdrz6q71Reyg5o7rwRzMoXZEdryTXYfDByNEN35Vno5tXAicx9hQcJytt lvSw== 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=B6XZDcYGXwLLw3RNVaebrTL5STZRjY5PFBNzt7FntZs=; b=OCOgIn1Mmvke0fsP478lBzrJROtdS024e5pI5OzSSuqewen1jDuGyFvhnZXeRcJ3eC Mug6owojlp2lirRyuquPkeOsD/5YqwXedW9jAW2zfQGMX8Yrg71HB8cJr8zBGq9YUptt 9OZDXtu290EUB0Rmo6LO4fdaLpXjADrtvGeEj7R8qIPTiIqkKuWpKBKVI4BKJEo7sqJX aDuOjKnhnzyRWkcRkBDnGeH+lbZEj2jebh/sYdD7/Jyi9ta5ctgKzh9SlcJ2VkJcZwc8 dyrwFKZG9BUCeY8ckQocztJvWeAz/GiMIfG8Ku+sWUSlpdXQunTJJbmodFkTat14kxSQ TDEA== X-Gm-Message-State: ABuFfoiqpDWa9glW0UB6lCsi3Kbt0XGmcfOpYtF+qmCN0V5HAomAnxeb BM7qEdbkA44nF2mc7K8e1a1TAjL4 X-Google-Smtp-Source: ACcGV60120lC2sGETsWwJZl+ekttRD/1hEEDYSGyHOCEwumQN1c+FaswMB9jgHlnL3xyp20LzRConw== X-Received: by 2002:adf:db8e:: with SMTP id u14-v6mr14721998wri.217.1538942410620; Sun, 07 Oct 2018 13:00:10 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:10 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 03/15] sequencer: refactor check_todo_list() to work on a todo_list Date: Sun, 7 Oct 2018 21:54:06 +0200 Message-Id: <20181007195418.25752-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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(). 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 | 106 ++++++++++++++++++++++++++++++++- rebase-interactive.h | 1 + sequencer.c | 109 ++++------------------------------ sequencer.h | 9 +-- 5 files changed, 120 insertions(+), 107 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index a2ab68ed06..ea1f93ccb6 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_todos(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 0f4119cbae..ef8540245d 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,83 @@ 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 advise_to_edit_todo = 0, res = 0, i; + struct commit_seen commit_seen; + + init_commit_seen(&commit_seen); + + 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) { + advise_to_edit_todo = res; + goto leave_check; + } + + 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) + 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); + + 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")); + + 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 bb8ca2477f..8dda61927c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4487,111 +4487,26 @@ int transform_todos(unsigned flags) return i; } -enum missing_commit_check_level get_missing_commit_check_level(void) +int check_todo_list_from_file(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; -} - -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) -{ - 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; + res = todo_list_check(&old_todo, &new_todo); - 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")); +out: + todo_list_release(&old_todo); + todo_list_release(&new_todo); return res; } @@ -4769,7 +4684,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 c786dee543..fb8b85bf9e 100644 --- a/sequencer.h +++ b/sequencer.h @@ -63,12 +63,6 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } -enum missing_commit_check_level { - MISSING_COMMIT_CHECK_IGNORE = 0, - MISSING_COMMIT_CHECK_WARN, - MISSING_COMMIT_CHECK_ERROR -}; - int write_message(const void *buf, size_t len, const char *filename, int append_eol); @@ -142,8 +136,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, int sequencer_add_exec_commands(const char *command); int transform_todos(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 Sun Oct 7 19:54:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629711 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 2C95714DB for ; Sun, 7 Oct 2018 20:00:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F41728BA9 for ; Sun, 7 Oct 2018 20:00:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 136F928DDB; Sun, 7 Oct 2018 20:00: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 9508128BA9 for ; Sun, 7 Oct 2018 20:00:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728114AbeJHDIh (ORCPT ); Sun, 7 Oct 2018 23:08:37 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53356 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbeJHDIh (ORCPT ); Sun, 7 Oct 2018 23:08:37 -0400 Received: by mail-wm1-f65.google.com with SMTP id y11-v6so3213296wma.3 for ; Sun, 07 Oct 2018 13:00: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=Z52qn2XW4l4R0Et9jJAQuBrEcJQUH2VRy/azWvb8+iE=; b=pSgDR9rdadWzNVaOZyPFLwSEPSQ2gowix3WHiKSYmDe4VpLOK+F5QygH1ytr3c5EiT ITLzPbH04G1O5HCUCFXgEjwRmEJX/9x43sp5afDM9VmFD82eiQFg4IEUmJE5ZjOwJS21 fLRZtOv3r7rwmoBTleRv98uhFECgMEJzlI0xf1SeggY5wSSY7o25GrWQ+COXDzB1kSSj /pGEZcCrMSl4Lhx4k6dtMM2hFHyGtttoBcWWJwXxRlkucRjrDT1jyVFzP3tnq3d2AlYC z8thIVbT+SC965m2u9xx0OUabGMOtEybFCy2oEseFsATp4Zc8pK32S1UQdM+OsAvjUPQ KFwQ== 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=Z52qn2XW4l4R0Et9jJAQuBrEcJQUH2VRy/azWvb8+iE=; b=Eudxm0FxylRzHjVRe39fxlUoCvzbgKMRUlaMJSfIclSk7dqlFlx9M6NN+qSEnUGTyg Pl4WN6aL+ENAAfXFep4Zq2+d1cWyOAw64jJumwV5QDSFAjF05Mn3OGf6sSCFR8+Bk2Iu Ya+IF1ChYKFmNgfTXmKtQsGfSDimCY4K5NLAi6SlRFxAfdGHMIBmp8LUpGjGIXQJU/X9 PIrmVPv60z2p+JGjnRZEU3BbPoYLzX3pM908NyV+Wl4U/56+FBkQrT5pbroDoYQAMoDs ZyJ+ofjUkR4Alucb2AUBkWFQhSx+m3cuPQLtaPGtlF/BKiToq/TObE5OF3IYisQkUWRp nmgQ== X-Gm-Message-State: ABuFfogXb8z5qCNBJQk1MVBqUU35mSgi4XKQGDGgg+J8y8vsIPTwPtmB npf4FEwvEDCPsk+JXPVNs8qHqcsO X-Google-Smtp-Source: ACcGV6367S29xmw3TOW3t2TJeIWieVZslAftB2nwG4+UXOyurF0vWEPWO/mNQvV6DEwzSsKPjFxPUQ== X-Received: by 2002:a1c:af07:: with SMTP id y7-v6mr13840068wme.33.1538942412205; Sun, 07 Oct 2018 13:00:12 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:11 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 04/15] sequencer: refactor sequencer_add_exec_commands() to work on a todo_list Date: Sun, 7 Oct 2018 21:54:07 +0200 Message-Id: <20181007195418.25752-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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. 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. Signed-off-by: Alban Gruin --- sequencer.c | 56 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8dda61927c..6d998f21a4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4370,34 +4370,21 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, return 0; } -/* - * Add commands after pick and (series of) squash/fixup commands - * in the todo list. - */ -int sequencer_add_exec_commands(const char *commands) +static void todo_list_add_exec_commands(struct todo_list *todo_list, + const char *commands) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf *buf = &todo_list.buf; + struct strbuf *buf = &todo_list->buf; size_t offset = 0, commands_len = strlen(commands); int i, insert; - 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); - } - /* * 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. */ insert = -1; - 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; if (insert >= 0) { /* skip fixup/squash chains */ @@ -4408,7 +4395,7 @@ int sequencer_add_exec_commands(const char *commands) continue; } strbuf_insert(buf, - todo_list.items[insert].offset_in_buf + + todo_list->items[insert].offset_in_buf + offset, commands, commands_len); offset += commands_len; insert = -1; @@ -4419,15 +4406,38 @@ int sequencer_add_exec_commands(const char *commands) } /* insert or append final */ - if (insert >= 0 && insert < todo_list.nr) - strbuf_insert(buf, todo_list.items[insert].offset_in_buf + + if (insert >= 0 && insert < todo_list->nr) + strbuf_insert(buf, todo_list->items[insert].offset_in_buf + offset, commands, commands_len); else if (insert >= 0 || !offset) strbuf_add(buf, commands, commands_len); - i = write_message(buf->buf, buf->len, todo_file, 0); + if (todo_list_parse_insn_buffer(buf->buf, todo_list)) + BUG("unusable todo list");} + +/* + * Add commands after pick and (series of) squash/fixup commands + * in the todo list. + */ +int sequencer_add_exec_commands(const char *commands) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_add_exec_commands(&todo_list, commands); + res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); todo_list_release(&todo_list); - return i; + + return res; } int transform_todos(unsigned flags) From patchwork Sun Oct 7 19:54:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629733 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 6C12A14DB for ; Sun, 7 Oct 2018 20:00:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF1228BA9 for ; Sun, 7 Oct 2018 20:00:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5488228DDB; Sun, 7 Oct 2018 20:00:37 +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 B0F6328BA9 for ; Sun, 7 Oct 2018 20:00:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728238AbeJHDIj (ORCPT ); Sun, 7 Oct 2018 23:08:39 -0400 Received: from mail-wr1-f54.google.com ([209.85.221.54]:33343 "EHLO mail-wr1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbeJHDIh (ORCPT ); Sun, 7 Oct 2018 23:08:37 -0400 Received: by mail-wr1-f54.google.com with SMTP id e4-v6so18606113wrs.0 for ; Sun, 07 Oct 2018 13:00:14 -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=CoMAJ3h9dibVxw8fTunbxyleFNwCcDRBf3d2CWRekrk=; b=hoqM8pN6Klmjk6rEoKjliQhpFrtr0i3mhwu2rS2vSQShAr/jDNEaXq46fICyyH4SdY kubuzOZ+fCJhIQDlUwlmyWoU3k+lR3OriL+UU2HscZJRX3ukqCkYfJ9E3s6+HGLE1Ckw Onr8ScNFJjcF33jq1knQSW+amp1wkjF8tITA0sFHQiCHtwhH9tGm1ml9SynRc45U7rIJ /Ueq4OYSbTkig8/JCeyDNi9/NfFYTIE7j9vtPh0/QiuNJQoBhbSL8POkJ5n1rAVT5tDk KZKaE09UPwhwOgFs7V02WrAXbGHyBaTScBFnLBKRk6j3KSuRKruMv+uiiSboe1MUfqZ1 sg6g== 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=CoMAJ3h9dibVxw8fTunbxyleFNwCcDRBf3d2CWRekrk=; b=laB8tq4Li8D2cQ3mhd7spGe0Ka5lIYvdMXgbOa+gKNHVbHPjG4iHbA/AfAB8W63U5Q 8Jm+ctWi+Tin/uxSIEDSI07fR8ogp5QyiAcrn9ZsHGFQZn1AuY3OrT8fiRSXhV2NkSX2 hLzBwuf02b5tBqSENX8ePOR57WJ8CsL7XBTV5zNENQiTOoTf7JaLQU7oNrYya/SCZdki ayHUnXpwDK+LDNlGXQc77j87+023Njn6QONi3D8bX+yccBu+Rd7yxeoh+oDYbwXBLSnh 2rcrqH+UDwzOdNQ3j44xJUPiwpOdyX9yA/om8R6CZDsT8qJDtCchCUFtes4dlF6h4QFl tRUA== X-Gm-Message-State: ABuFfog5dZagFYsFWRe4yKK5FUzuYpjSeQR/Vm9lLFRPNyzQGY8wq6Nu uWHkjBcq4ixbL5q+ajUFAC3IbP6H X-Google-Smtp-Source: ACcGV62DQATcUBiZckm1AwbRUiMEF505P4Ki1AJFb0xevxz0HkAO+jtxS71Dugq/vBLvk/VPJXfNew== X-Received: by 2002:adf:94c2:: with SMTP id 60-v6mr13887546wrr.247.1538942413344; Sun, 07 Oct 2018 13:00:13 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:12 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 05/15] sequencer: refactor rearrange_squash() to work on a todo_list Date: Sun, 7 Oct 2018 21:54:08 +0200 Message-Id: <20181007195418.25752-6-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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(). As rebase -p still need to check the todo list from the disk, a new function is introduced, rearrange_squash_in_todo_file(). Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 2 +- sequencer.c | 73 +++++++++++++++++++++-------------- sequencer.h | 2 +- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index ea1f93ccb6..8deef126d1 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 6d998f21a4..8a6176b3d0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4632,7 +4632,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) @@ -4738,22 +4738,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; 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; - } - init_commit_todo_item(&commit_todo); /* * The hashmap maps onelines to the respective todo list index. @@ -4765,13 +4756,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; @@ -4784,7 +4775,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.")); } @@ -4819,7 +4809,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++) @@ -4832,7 +4822,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) @@ -4852,8 +4842,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; /* @@ -4865,12 +4855,12 @@ int rearrange_squash(void) while (cur >= 0) { const char *bol = - get_item_line(&todo_list, cur); + get_item_line(todo_list, cur); const char *eol = - get_item_line(&todo_list, cur + 1); + get_item_line(todo_list, cur + 1); /* replace 'pick', by 'fixup' or 'squash' */ - command = todo_list.items[cur].command; + command = todo_list->items[cur].command; if (is_fixup(command)) { strbuf_addstr(&buf, todo_command_info[command].str); @@ -4883,18 +4873,43 @@ int rearrange_squash(void) } } - res = rewrite_file(todo_file, buf.buf, buf.len); + strbuf_reset(&todo_list->buf); + strbuf_add(&todo_list->buf, buf.buf, buf.len); strbuf_release(&buf); } 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); + + if (todo_list_parse_insn_buffer(todo_list->buf.buf, todo_list)) + BUG("unusable todo list"); + + 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 = rewrite_file(todo_file, todo_list.buf.buf, todo_list.buf.len); + + todo_list_release(&todo_list); return res; } diff --git a/sequencer.h b/sequencer.h index fb8b85bf9e..7f5668500f 100644 --- a/sequencer.h +++ b/sequencer.h @@ -141,7 +141,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 Sun Oct 7 19:54:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629731 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 1B20214DB for ; Sun, 7 Oct 2018 20:00:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EEA128BA9 for ; Sun, 7 Oct 2018 20:00:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 033E128DDB; Sun, 7 Oct 2018 20:00:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B02328BA9 for ; Sun, 7 Oct 2018 20:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728416AbeJHDIj (ORCPT ); Sun, 7 Oct 2018 23:08:39 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39040 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728017AbeJHDIj (ORCPT ); Sun, 7 Oct 2018 23:08:39 -0400 Received: by mail-wm1-f67.google.com with SMTP id y144-v6so1848218wmd.4 for ; Sun, 07 Oct 2018 13:00:15 -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=OawRcaVEt+HB/RITtSmrsE6bDe9yb4eTQWkMwXEuTSk=; b=JK9qPiiEbALU/6ERbX8ZaOB7PxwD6r1Np7M/wBhQXBC7u0AWCNQDez55xxdT/5w7RU SnxrTvJWOYCEO5qcIHxtr7Zq5aJ6aGMnPqbdLbhi4RHyXMwenK/dGG5ZUkV9FnfrpOvn AdkpY5mRn8GYP9aYlroz4E+b2NRnnKVIllmIwHt+uvJQekBC8S+b0WGmJ/Z5lXiddpL1 wAN+vuBLZYvK1nOKSTOTxz0FKuitiQWfQ8MOIVrrK/1St1movVNpP4pVqCbAV0Ju6tfv vHyL19NUSsWAxOBFTVy9jC/kPU0nS23SOXHSgyA955IZ6O7InqJ7dsbKRUxKmxpypGwO Cj4A== 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=OawRcaVEt+HB/RITtSmrsE6bDe9yb4eTQWkMwXEuTSk=; b=bJW0pdYHUptw8cWII3z6/YSaSbw22Rkx4l5VydIzRkPMbr9uBnetrG17i+pqO9zw3c A+NQuv1J9V9fJ0OLNAbC3/hGDvILJtaMUpmYA1pTwXgNTcJ6mgzIlm/IS+CtIOg91CFr ukynAB3UH5mEAdDI2nXYCeHcGYnnTh74ejKUqTk/6pSID32MI2CFAbX0Ka1OpUmqwS6e og94kZ7KztQD18QW6gNpnlSu1XjDvQFhPtq4UoXOJhSWJpjaulvkJl6ZcpxojDMXyFhb MA67/nbVhwKcmoN/SbeJsmKbcw/Jy8Pu3EpSMRwWrPFyCoss7/bFNOAQ68UJ+7f+ZSlM lu7A== X-Gm-Message-State: ABuFfojfiYaXmcfloeES26RmaxKodyQCotNUbJupd9YJRRSOwq/GMb3m nULwUGVXLJ6JTrajP7TcTtP/7Wvz X-Google-Smtp-Source: ACcGV60CI3HjDabq+W4Bd0JyFupksJIeZm4EYjIjbRiLl1A1tAfemA0v43ZSdvF//WtDH4e6qYkjbQ== X-Received: by 2002:a1c:a851:: with SMTP id r78-v6mr13168973wme.97.1538942414366; Sun, 07 Oct 2018 13:00:14 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:13 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 06/15] sequencer: refactor transform_todos() to work on a todo_list Date: Sun, 7 Oct 2018 21:54:09 +0200 Message-Id: <20181007195418.25752-7-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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(). 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 8deef126d1..f827e53f05 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_from_file(); diff --git a/rebase-interactive.c b/rebase-interactive.c index ef8540245d..7c7f720a3d 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -92,7 +92,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); @@ -108,7 +108,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 8a6176b3d0..30a7fe3958 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4440,23 +4440,13 @@ int sequencer_add_exec_commands(const char *commands) return res; } -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); @@ -4492,9 +4482,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; } int check_todo_list_from_file(void) @@ -4670,7 +4684,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); @@ -4699,7 +4713,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 7f5668500f..e1faca7884 100644 --- a/sequencer.h +++ b/sequencer.h @@ -112,6 +112,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 */ @@ -135,7 +136,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); int check_todo_list_from_file(void); int complete_action(struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, From patchwork Sun Oct 7 19:54:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629727 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 9653A14D6 for ; Sun, 7 Oct 2018 20:00:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A28B28BA9 for ; Sun, 7 Oct 2018 20:00:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E5AD28DDB; Sun, 7 Oct 2018 20:00:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1F0628BA9 for ; Sun, 7 Oct 2018 20:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbeJHDIn (ORCPT ); Sun, 7 Oct 2018 23:08:43 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50364 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726697AbeJHDIl (ORCPT ); Sun, 7 Oct 2018 23:08:41 -0400 Received: by mail-wm1-f66.google.com with SMTP id i8-v6so90088wmg.0 for ; Sun, 07 Oct 2018 13:00:16 -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=fg8hFe5D0PpfQ5EH9S+T2B9xTIhaSrfcK9nR88k4+8w=; b=VFilXSUdlnioeezY3H1LT6VNsp6IZU7Qzdq45KrqEF5dq/DR6779pmQuFkA6AKSWez 5jsNi0fIdZIP59Y5UVp8p1GgI/phXBPjhPCWN50YbTm+0OVDwey3ABbujxEpZA53ehRN fdvKRnvUox5RRGQQzjX9Fsh2frUcf7AceBot/W1yT25DNHSalbTVlPXdYtyPnagxej/N LZrC1w1Wzg5KQljbtI+gnAsw4IqqrU2atVjhYqn5pK6lbGdWIUU4fnqjE83/UM8WNH75 wXRPbxBvdfzE1pKfwZZRTs1wjwrvFrp1dFonJiXOV/zBFHOtXFwQt4WCC6954aXCk0FK mbWQ== 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=fg8hFe5D0PpfQ5EH9S+T2B9xTIhaSrfcK9nR88k4+8w=; b=RfdQBSFsFfJO4PpHDCnJBqt6BUe4/CHit3cc61kBHHz64alsA8mi8CLi7EDkg7tIjF m3KzFOIcf1divbXZ44dDSSvXyjl+SWybc2J6G1Xrr7/+Di4G/wR6Zux+x8G21JsWZsl5 bVvKgZCAnUKjijP078qFh8ZLB1231fzOUmVGZBe4RUpUCKYVi+nUp5bHdnCILzIUy3Aj LGbNC9Yz/1AoeIIFle/+KAEskU+snoFW1DFolWgjslQklw90xnFo5Nurrq/QngO8cfsZ 7tIbpx7UEra9gqtG1St2y5+xUuRACsL61SkD3d+Lj7Gym0KqHltbKLyFkeLVc/TwCXea FPLQ== X-Gm-Message-State: ABuFfogKnGy9jGQRzhDIyxfk1U9ALFu7MaKLjEgFCFPfqCJJfpy6cnvl mGzT1YO5nsS+nCrmCQwQb8kaKDh3 X-Google-Smtp-Source: ACcGV61WeR1wAcoIUyJOncdRz6q3Q5P9w3IcSYpPlozFRjXkFsrWrmPiSXhte76xYgnrt5dq3ddScg== X-Received: by 2002:a1c:1dc8:: with SMTP id d191-v6mr13012683wmd.27.1538942415776; Sun, 07 Oct 2018 13:00:15 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:15 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 07/15] sequencer: make sequencer_make_script() write its script to a strbuf Date: Sun, 7 Oct 2018 21:54:10 +0200 Message-Id: <20181007195418.25752-8-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 30a7fe3958..dfb8d1c974 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4083,7 +4083,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; @@ -4230,7 +4230,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; @@ -4240,9 +4240,9 @@ static int make_script_with_merges(struct pretty_print_context *pp, entry = oidmap_get(&state.commit2label, &commit->object.oid); if (entry) - fprintf(out, "\n%c Branch %s\n", comment_line_char, entry->string); + strbuf_addf(out, "\n%c Branch %s\n", comment_line_char, entry->string); else - fprintf(out, "\n"); + strbuf_addf(out, "\n"); while (oidset_contains(&interesting, &commit->object.oid) && !oidset_contains(&shown, &commit->object.oid)) { @@ -4255,8 +4255,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; @@ -4269,12 +4269,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); } } @@ -4283,11 +4283,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); } @@ -4309,12 +4309,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; @@ -4357,16 +4356,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 e1faca7884..21d9ba09ab 100644 --- a/sequencer.h +++ b/sequencer.h @@ -132,7 +132,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 Sun Oct 7 19:54:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629713 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 3754414D6 for ; Sun, 7 Oct 2018 20:00:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB5A28BA9 for ; Sun, 7 Oct 2018 20:00:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D31A28DDB; Sun, 7 Oct 2018 20:00:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FCCE28BA9 for ; Sun, 7 Oct 2018 20:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728449AbeJHDIn (ORCPT ); Sun, 7 Oct 2018 23:08:43 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:33434 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbeJHDIl (ORCPT ); Sun, 7 Oct 2018 23:08:41 -0400 Received: by mail-wm1-f65.google.com with SMTP id y140-v6so7344042wmd.0 for ; Sun, 07 Oct 2018 13:00:17 -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=su4j9BpU35uDX5M9u2HTZI+yAps3s1ON2fSVjY7XbmY=; b=CHQUDh8wr77Dt3S3jkgpNw32qtWQptrBv5FPWS47JvG+81Y0rANsVnT+26G9GRqSww wrfG6iwNS8lc5VsJRJ0qfeRZL+1z96FUbW2Bp3g7TwCpSYppDo5FH6e5NF4qmeGLNfTo tMobSzVLn0x8/5gb6xOhC0eh9t/QCMPrU9w+f0CV6k2nPVALOs/E+fLS2aSsDdo4GSzR AEzBTQYILMmT3El9B65U+y2iw82F1E3t9FD3yGKscpDqsHKso5DhjJflHZQ3RtNhpqAk Ry9jUx52IhiqnzQzeSBagOPYgY9AoY/a1xgxJxFIL6uEHxFhUjHPxCVejoV0XRf8Qvac c8yQ== 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=su4j9BpU35uDX5M9u2HTZI+yAps3s1ON2fSVjY7XbmY=; b=LK2quZmVWvgrDJr5JtijPx0RwwvlA7Yg32Z/6eCUYgLQ25FaFtt044RpYiX1g5NeFv kcikf61rDJhHHiGjQ4tbQILyNnBmk5Ew+/oybPfpb4cXex6yLjaXcAbL6o+sHBg5CBHJ TJCUj0rQxJ/+MkbZwGhXDx5QoJuZAIr1dJ1SKeUGIMYYxpVJ/D4aYMk/e42artn5+Cij oCGDRbA9dDVLVMxNbupQ1mJiSndMeYZM2/CZ3UZWIiwjtGXRptXpnmwJYZ0UBKrHYoJ9 S7agAc+2m7W8kfNWJaqDNc+iPwaq3bixEQRNVZzWuw5aUHCcGw7HiN1opLhtneXJ5t8p 8kWg== X-Gm-Message-State: ABuFfogrb51OG5e3EXudhypWzXYhaQd6jhT4UT4N/jgZqCs5tye1vgbS l68Desj+/m7t2F04LPHwatDLFZKc X-Google-Smtp-Source: ACcGV60/TAIpRmrkNt2CNCK7QV7xFWaEqJ1boCFVfDkglWN4wzwWUPcOaCq0dEM4szoiihUEnXqvrA== X-Received: by 2002:a1c:cc8:: with SMTP id 191-v6mr12983499wmm.55.1538942416800; Sun, 07 Oct 2018 13:00:16 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:16 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 08/15] sequencer: change complete_action() to use the refactored functions Date: Sun, 7 Oct 2018 21:54:11 +0200 Message-Id: <20181007195418.25752-9-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 13 +----- sequencer.c | 76 +++++++++++++++++------------------ sequencer.h | 2 +- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index eef1ff2e83..0700339f90 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,13 @@ 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(); 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 dfb8d1c974..b37935e5ab 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4624,93 +4624,89 @@ 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) + strbuf_add(buf, "noop\n", 5); + + if (todo_list_parse_insn_buffer(buf->buf, todo_list)) + BUG("unusable todo list"); - 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); + todo_list_add_exec_commands(todo_list, 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); - } - - 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")); } + todo_list_transform(todo_list, flags | TODO_LIST_SHORTEN_IDS); + 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)); + command_count), + shortrevisions, shortonto, command_count); 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 (write_message(buf->buf, buf->len, todo_file, 0)) + 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_check(todo_list, &new_todo)) { 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")); + todo_list_transform(&new_todo, flags & ~(TODO_LIST_SHORTEN_IDS)); + + if (rewrite_file(todo_file, new_todo.buf.buf, new_todo.buf.len) < 0) { + 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 21d9ba09ab..5bd3b79282 100644 --- a/sequencer.h +++ b/sequencer.h @@ -141,7 +141,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 Sun Oct 7 19:54:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629729 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 04CA314D6 for ; Sun, 7 Oct 2018 20:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECD7A28BA9 for ; Sun, 7 Oct 2018 20:00:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E12E028DDB; Sun, 7 Oct 2018 20:00:32 +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 7301128BA9 for ; Sun, 7 Oct 2018 20:00:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728514AbeJHDIx (ORCPT ); Sun, 7 Oct 2018 23:08:53 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34260 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728140AbeJHDIm (ORCPT ); Sun, 7 Oct 2018 23:08:42 -0400 Received: by mail-wm1-f68.google.com with SMTP id z25-v6so7337811wmf.1 for ; Sun, 07 Oct 2018 13:00:19 -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=fK0kS4M9zCqeOQRATMV7NdTbQ0OaSTne9/Z0cJRvP/8=; b=p96KfojYV0Pph0/Afk+Ta6vqbxmzUvblQlI9FR89XZGZKC68rLznoNrVV2YAR2jyw0 cyFw8TrXCweWEPIKVMT6Ulm9yfFWqZuRq2QebWsdBM+loRPa/XJ+9/dfVFPXHQQm6i2D 5JAVaI41RVixXvk10pE/1we5sqv1YdEB43KhTjWm9UkWD/QO1L38pxEOJmKjaGrRCsBa wMAFEaRxpq1UKjDzkuM0ZlVAFm8NuROOLxCy2R9Qdcewdv0bRpj0tzwfs9VBsRJ5v8f2 OmLsspeTVFdVPsBPkRIZ6RFSxw9BYqqkmgsjX+nAzn4hVh7hTiBVu2YSH/E61q3//j/B 9+Tg== 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=fK0kS4M9zCqeOQRATMV7NdTbQ0OaSTne9/Z0cJRvP/8=; b=TPIfuYmkNSw6WbM1+D39x2UHorPGmnOikNF/1ii1SMYAreUodpOP4Hd25hPDLUb/zN cyAeqK9OamDemg+U2E3++ejhVwJMs+UeUUdV1NqxJbya+puLw6DfpFCV+rk+YD7vXwiJ HAUA4T1nd6KbVeOw8nExeHJ1WWklou+fyVPiWfu25Mf3NdYQIL4fQ5NzWIZ7bFx9Sg/6 YAQ5afKrM4uCUms+ZONybmO8M0N+dc1QsElHPpKSlnkSyH5QVhg4DfP7RTIOr0AcSOJD icG/WbUuRjds8DZoCCMYcUke50+vRdywhfIhmkJxBrE1+CDzcOebhaTsMNMtQkmxZR/8 47jA== X-Gm-Message-State: ABuFfohXz5Zba6txNPgSHow7AE5cENeFBYcIJYv07gA6Qp3ELFzMr0vY 7JmmTeZnI9nFPgAXS8XzV0TTx5fK X-Google-Smtp-Source: ACcGV63ZJrMY/CC7Tx4p6x0EMlxqziFaAGXra96QLrkX+HfDKD7rHw/5yFLZLgMVIAA2t+1t+7cWlQ== X-Received: by 2002:a1c:84cd:: with SMTP id g196-v6mr13417483wmd.38.1538942417967; Sun, 07 Oct 2018 13:00:17 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:17 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 09/15] sequencer: refactor skip_unnecessary_picks() to work on a todo_list Date: Sun, 7 Oct 2018 21:54:12 +0200 Message-Id: <20181007195418.25752-10-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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(). Signed-off-by: Alban Gruin --- sequencer.c | 56 +++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/sequencer.c b/sequencer.c index b37935e5ab..a432b64048 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4545,38 +4545,20 @@ static int rewrite_file(const char *path, const char *buf, size_t len) } /* 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; - } - - 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)); } @@ -4590,37 +4572,29 @@ 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); + 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 (write_in_full(fd, todo_list->buf.buf, offset) < 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; - } + strbuf_splice(&todo_list->buf, 0, offset, NULL, 0); - todo_list.current = i; - if (is_fixup(peek_command(&todo_list, 0))) - record_in_rewritten(output_oid, peek_command(&todo_list, 0)); + todo_list->current = i; + 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; } @@ -4701,6 +4675,11 @@ int complete_action(struct replay_opts *opts, unsigned flags, todo_list_transform(&new_todo, flags & ~(TODO_LIST_SHORTEN_IDS)); + if (opts->allow_ff && skip_unnecessary_picks(&new_todo, &oid)) { + todo_list_release(&new_todo); + return error(_("could not skip unnecessary pick commands")); + } + if (rewrite_file(todo_file, new_todo.buf.buf, new_todo.buf.len) < 0) { todo_list_release(&new_todo); return error_errno(_("could not write '%s'"), todo_file); @@ -4708,12 +4687,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 Sun Oct 7 19:54:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629715 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 2917714D6 for ; Sun, 7 Oct 2018 20:00:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D13328BA9 for ; Sun, 7 Oct 2018 20:00:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 116A628DDB; Sun, 7 Oct 2018 20:00:24 +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 AD72128BA9 for ; Sun, 7 Oct 2018 20:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728479AbeJHDIo (ORCPT ); Sun, 7 Oct 2018 23:08:44 -0400 Received: from mail-wm1-f53.google.com ([209.85.128.53]:52973 "EHLO mail-wm1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728464AbeJHDIo (ORCPT ); Sun, 7 Oct 2018 23:08:44 -0400 Received: by mail-wm1-f53.google.com with SMTP id 189-v6so6183853wmw.2 for ; Sun, 07 Oct 2018 13:00:20 -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=O6wO5pavF9klxU67lYTPbndM9g+hgqKRTQ1/QEALfVM=; b=pAVlPdDbLft4g44opYPt/B03vB1Ow7E8Sx/0vmNsEpQutDOvOkJ3kWM3cv/YGlCf2o 8zumrHyd68GlqGDXAXNHeVh0b98E32bnJbtCH52rtX+FqzXYhGiO9by6293qfnrHont+ YLkBpMSC9wCDCGxOyomorvIIcTKU/c36yftY68oo0lUOFIFLARWSVsAxRExRPTWdRLGF nv1wCkTyA25GKlvpUzAVNP+3JXbGo20M/fe1lrr+1iVI6ixlJXYytTcKHeukLH4MW6Bb pKBH9vVzRGIZwPPHXRNn8cV02XVF1MxI2RcYi+nzY6K35kNTwWpwrhn8P547u9MuW5Lb sfkQ== 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=O6wO5pavF9klxU67lYTPbndM9g+hgqKRTQ1/QEALfVM=; b=tFVkY1DeaCqoSBLsZ1QjeJ6bS7VBrJJUIgZieOZykjzH9ZiTkbdnJnJWBFnZmi9lIU RS+QxtSHhNTX1bcDvpw6vh2JlNVJ+pYTg0iwCkRPm8zsfh9CXAyEd1L1x9GnSJyZDmqw tre3MZOSCpMdSUu07IJfFbGc1jg1W0e/Y+zxXzj4k3xEs8a0krRhtb92+iToHzq3TsHA aka6zRfpHtSkkyO/nkcF/RISwxcQns4hqEbTvfEUdNkWT51g2pSwNNxwh8oYfjHeJxxw 6edCdtnLjgE9otS3uDNBk05Nc6webWQdBF19i7diimw9rEeqQJcHELdVUuhc7A94Ffqv LnPg== X-Gm-Message-State: ABuFfogml3oONeF+xD5AMuAIcm8hum4m2adG4uA6BGoOo469wr34FmD8 QVeVFlro/iu2IKrab84sd7gywy6V X-Google-Smtp-Source: ACcGV62F/es+K03FG+WE/96Es5yxTlsZJGfLzFbF9q4g4ga2Djt23A9/XfNXSqKFthr4QAXLievVuA== X-Received: by 2002:a1c:8942:: with SMTP id l63-v6mr13939346wmd.66.1538942419270; Sun, 07 Oct 2018 13:00:19 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:18 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 10/15] rebase-interactive: use todo_list_transform() in edit_todo_list() Date: Sun, 7 Oct 2018 21:54:13 +0200 Message-Id: <20181007195418.25752-11-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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_transform() instead. Signed-off-by: Alban Gruin --- rebase-interactive.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index 7c7f720a3d..f42d48e192 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -78,39 +78,37 @@ 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); - return -1; - } - - strbuf_release(&buf); + strbuf_stripspace(&todo_list.buf, 1); + if (!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) + todo_list_transform(&todo_list, 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); + append_todo_help(1, 0, &todo_list.buf); - append_todo_help(1, 0, &buf); - if (write_message(buf.buf, buf.len, todo_file, 0)) { - strbuf_release(&buf); + if (write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0)) { + todo_list_release(&todo_list); return -1; } - strbuf_release(&buf); - - if (launch_sequence_editor(todo_file, NULL, NULL)) + strbuf_reset(&todo_list.buf); + if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { + todo_list_release(&todo_list); return -1; + } - transform_todo_file(flags & ~(TODO_LIST_SHORTEN_IDS)); + if (!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { + todo_list_transform(&todo_list, flags & ~(TODO_LIST_SHORTEN_IDS)); + res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); + } - return 0; + todo_list_release(&todo_list); + return res; } define_commit_slab(commit_seen, unsigned char); From patchwork Sun Oct 7 19:54:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629717 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 BBA4017E3 for ; Sun, 7 Oct 2018 20:00:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEDF628BA9 for ; Sun, 7 Oct 2018 20:00:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A36EB28DDB; Sun, 7 Oct 2018 20:00:24 +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 3D6B228BA9 for ; Sun, 7 Oct 2018 20:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728488AbeJHDIp (ORCPT ); Sun, 7 Oct 2018 23:08:45 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54967 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbeJHDIo (ORCPT ); Sun, 7 Oct 2018 23:08:44 -0400 Received: by mail-wm1-f67.google.com with SMTP id r63-v6so6188181wma.4 for ; Sun, 07 Oct 2018 13:00:21 -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=yNHdhBEgEZG8en3WNInKU4noer8hF/Jn1jEms1FDHMI=; b=bU6GzuUcsv74bUmlwdwBn7RzPCmwgSkT/DbbkXync2JXXjt5skJpLCdFQ2uMnHGZp+ eahdvEtefWXH14CUxaGESY7Gx+wLegerDWM3cEBvjhwI+SK+4jCi4WotU0Og7gKHvkWF /5of/nyumMq69213G/6uslnKUfnudRtAt/+3LNgGUWXlZAGFtlKEPndKQDVfBBTzm8AL MUGkAPuWJM9QA9Kini9oru89OPLrqd5SKDcvWWBu4oaJTCd1Ybe9v9Os/6/sED47V8HW w7O35KRpZJz5axHCocGOcz6zWC3JNc/1a6KmhxLWpw71CyPCDfSTypaIBg2C7d4t0ebY aJTg== 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=yNHdhBEgEZG8en3WNInKU4noer8hF/Jn1jEms1FDHMI=; b=YJaEcFX0B6zjBDpBIAACThlaqynFdYBn72mhdv4pcRyaqU+2mOpCxCKO9rwZ24Lj9I Tyk4+Bi9+NfESu5sthjvIANzF0CI47i1EhLtMutILipbNpHx1hSrb1vu9qNRNROWmATW LCdyWRTatv58+Z3gjH6q7AgZBm9gggz9zUV4MlyXJ1MxdzNmNgkTzeWdUVmFzINtZpgm uClWzCIH11/zt8p5l7GEkI+NAHuG3pOHB9TQrw6eb1Rjgi98Yj/tV2lZ+dwFdxp0UebY kHzIh7s7MbyW1DicXDwpr8FUvDGwT2LlIS3NFhvicvemTwOF//a6nZWe62I3H4tRZQ4o IULw== X-Gm-Message-State: ABuFfohH29+aBZF+DHq7ZMB0lIkWb4HtErIK78MhpSB8HJU59UoDjpIq 6ctpjp4Xcr946mc3cqVyNyaUmxEH X-Google-Smtp-Source: ACcGV62MJ53ZgXzZ5rbr4WaTHdrXs7j5qibGWAY+/ai8xws7XXIwTa0i5yXvz8u8bEam2m+SO6G1dA== X-Received: by 2002:a1c:1a52:: with SMTP id a79-v6mr9779536wma.119.1538942420380; Sun, 07 Oct 2018 13:00:20 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:19 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 11/15] rebase-interactive: append_todo_help() changes Date: Sun, 7 Oct 2018 21:54:14 +0200 Message-Id: <20181007195418.25752-12-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 | 14 ++++++++++++-- rebase-interactive.h | 3 ++- sequencer.c | 8 ++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index f42d48e192..7168d56d17 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)); @@ -89,7 +99,7 @@ int edit_todo_list(unsigned flags) if (!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) todo_list_transform(&todo_list, flags | TODO_LIST_SHORTEN_IDS); - append_todo_help(1, 0, &todo_list.buf); + append_todo_help(flags, 0, NULL, NULL, &todo_list.buf); if (write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0)) { todo_list_release(&todo_list); 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 a432b64048..94d3058359 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4636,12 +4636,8 @@ int complete_action(struct replay_opts *opts, unsigned flags, todo_list_transform(todo_list, flags | TODO_LIST_SHORTEN_IDS); - 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(0, flags & TODO_LIST_KEEP_EMPTY, buf); + append_todo_help(flags & TODO_LIST_KEEP_EMPTY, command_count, + shortrevisions, shortonto, buf); if (write_message(buf->buf, buf->len, todo_file, 0)) return error_errno(_("could not write '%s'"), todo_file); From patchwork Sun Oct 7 19:54:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629719 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 512A214D6 for ; Sun, 7 Oct 2018 20:00:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4553028BA9 for ; Sun, 7 Oct 2018 20:00:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39C2928DDB; Sun, 7 Oct 2018 20:00:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2FA528BA9 for ; Sun, 7 Oct 2018 20:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728493AbeJHDIq (ORCPT ); Sun, 7 Oct 2018 23:08:46 -0400 Received: from mail-wr1-f49.google.com ([209.85.221.49]:37842 "EHLO mail-wr1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728464AbeJHDIq (ORCPT ); Sun, 7 Oct 2018 23:08:46 -0400 Received: by mail-wr1-f49.google.com with SMTP id y11-v6so7831026wrd.4 for ; Sun, 07 Oct 2018 13:00:22 -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=4DvgTeq10F6UWuq8bSIDOGvI0h8opb0/Aja1C2ZWICI=; b=n8Zgkn6WPpuLQ2LUvKqYNbPHFpRIIDEVKHM10/5KORVTTxE3s5iYmjNWac4z125IFE KG10yUc1/akPx5RJZQm/g7LvAqLAZpl6O7SODJpvmLotyTJ+lJGQU0YKUROSCj64BWNC QCBhOZJrwKtr96LbJjcKxLda0ysUmOXSmowuTNMqGLFwAor6YkbZ0YjO7DOZm6esL1mi nxHo948B0gt6kCWU5d0TBrmU+ZMmitgkZhIF9CXdK2R4XPCVANgy4X7AbVKzRwXznptF PxMC54pgoVnvfmFDr+/IUjyfWa8E1OcqcGqV3oFzDhW560LD0yitGXAvYpRjpAQbs3YC xxNw== 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=4DvgTeq10F6UWuq8bSIDOGvI0h8opb0/Aja1C2ZWICI=; b=tuyFuhXblkhm6KTg25WnJqES7HFpNETveyLt4/XKsZ06kVK0BuT7oULzjyxRlG3Rz0 9llMi+LClaoYduRMnC4Vqkt2t5/mBOXkVnyz1TMAkjLPoAKgtxCaYMNNYWj2HgQf5phH wg2oeyUCiKNK1S0qAdG6d8JbfwEjI9KNylX0HOmhzrU7wrQDY5a/j9TINy5ZHVaTpWQH F56gKqY0a2I4LVacLbJFMsTwF28katcaAkoeTs+vngfQonsBjFjloC4azvdtOYbgKpfd bC+Hd4iatb5nbIJwvwweeXGHLvb9YFBo4Fn7R/iyspVBaxAAsV6q7O6j7luRepE01pNA X5Tw== X-Gm-Message-State: ABuFfoj9k/Ptc9u3XPhXCLNgbgOzxJJSA9ixU/lmzNLUpjTD8JXpoQbI 8hLjCL91WI0ap1T3gh2dtEVUoKtx X-Google-Smtp-Source: ACcGV63NXJIHEYrXgPVipM61wUW6kknHhCMxl6Fh6PPcbuJT+eFj1GWbh0+FRCXn5icTpuzWbgUQ1Q== X-Received: by 2002:adf:ad65:: with SMTP id p92-v6mr15023929wrc.7.1538942421924; Sun, 07 Oct 2018 13:00:21 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:21 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 12/15] rebase-interactive: rewrite edit_todo_list() to handle the initial edit Date: Sun, 7 Oct 2018 21:54:15 +0200 Message-Id: <20181007195418.25752-13-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 work if the old todo list has invalid commands. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 22 +++++++++++++++- rebase-interactive.c | 49 ++++++++++++++++++----------------- rebase-interactive.h | 4 ++- sequencer.c | 3 +-- sequencer.h | 1 + 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 0700339f90..264e940b47 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -13,6 +13,26 @@ 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) && + write_message(new_todo.buf.buf, new_todo.buf.len, todo_file, 0) < 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) @@ -231,7 +251,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 7168d56d17..6ee60ac03f 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -86,39 +86,40 @@ 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; + unsigned initial = shortrevisions && shortonto; - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); + if (initial || !todo_list_parse_insn_buffer(todo_list->buf.buf, todo_list)) + todo_list_transform(todo_list, flags | TODO_LIST_SHORTEN_IDS); - strbuf_stripspace(&todo_list.buf, 1); - if (!todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) - todo_list_transform(&todo_list, flags | TODO_LIST_SHORTEN_IDS); + if (initial) + append_todo_help(flags & TODO_LIST_KEEP_EMPTY, command_count, + shortrevisions, shortonto, &todo_list->buf); + else + append_todo_help(flags, 0, NULL, NULL, &todo_list->buf); - append_todo_help(flags, 0, NULL, NULL, &todo_list.buf); + if (write_message(todo_list->buf.buf, todo_list->buf.len, todo_file, 0)) + return error_errno(_("could not write '%s''"), todo_file); - if (write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0)) { - todo_list_release(&todo_list); - return -1; - } + if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666)) + return error(_("could not copy '%s' to '%s'."), todo_file, + rebase_path_todo_backup()); - 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)) { - todo_list_transform(&todo_list, flags & ~(TODO_LIST_SHORTEN_IDS)); - res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); - } + 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)) + todo_list_transform(new_todo, flags & ~(TODO_LIST_SHORTEN_IDS)); + + 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 94d3058359..bfcbe8239b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -55,8 +55,7 @@ static GIT_PATH_FUNC(rebase_path, "rebase-merge") * file and written to the tail of 'done'. */ GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo") -static GIT_PATH_FUNC(rebase_path_todo_backup, - "rebase-merge/git-rebase-todo.backup") +GIT_PATH_FUNC(rebase_path_todo_backup, "rebase-merge/git-rebase-todo.backup") /* * The rebase command lines that have already been processed. A line diff --git a/sequencer.h b/sequencer.h index 5bd3b79282..fa84918c55 100644 --- a/sequencer.h +++ b/sequencer.h @@ -9,6 +9,7 @@ struct commit; const char *git_path_commit_editmsg(void); const char *git_path_seq_dir(void); const char *rebase_path_todo(void); +const char *rebase_path_todo_backup(void); #define APPEND_SIGNOFF_DEDUP (1u << 0) From patchwork Sun Oct 7 19:54: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: 10629721 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 4DF2114D6 for ; Sun, 7 Oct 2018 20:00:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41E7C28BA9 for ; Sun, 7 Oct 2018 20:00:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3665028DDB; Sun, 7 Oct 2018 20:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA92628BA9 for ; Sun, 7 Oct 2018 20:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728500AbeJHDIs (ORCPT ); Sun, 7 Oct 2018 23:08:48 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43992 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728019AbeJHDIr (ORCPT ); Sun, 7 Oct 2018 23:08:47 -0400 Received: by mail-wr1-f68.google.com with SMTP id n1-v6so18560702wrt.10 for ; Sun, 07 Oct 2018 13:00:23 -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=IruHl0hMBftjMx1LoJgGdc1u8HOmZRkzqCH7OEFdMJ0=; b=WVfBJy6/HaFBNRPVxCcp6FXsDkyCF9cgkvB+Et3tVDAONxSRMra0AvKSXflpzkM6Rs itSMxY3kfsk8fAugs8fOh+Gy0U99b46Y7I0uOLEg+wIKB5KuzxCmbBwgfTHXMxltdas+ Umv/RvHJhM95uzbSM84Gkeiqpq3cn8V8bA5Y0hNGBszIVqHqTN43qZfkXfx4c+JI58s4 1rxIA1Rt6v+m1nxuHR6KcmEt0gAK/axknI4ZkJeg7Nx4IjAnYA9UN6A9VOLmbjqe0msq qsbFdj0CXs2VSEZ/2xbPue/EwW2/VeYSxyMLfoNtNKWFQBOz+HbG4OE9KWrDoGyO91Ry YfoQ== 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=IruHl0hMBftjMx1LoJgGdc1u8HOmZRkzqCH7OEFdMJ0=; b=gwL+a5q6hLs6i7PEkdOqLjpgLbgYRP0N1SXDrozGGa5K3JhKqD01nOFafVn6BECARE UckET8/lJf7aRy9QIc0C6t+i3PjY+xWOqlqSn1Gu7T38pdb4YSSMN10Bc0CwE3Fr1uhF mvRZ8MPVVRQdYYFKVekw5BBYPMdD/GkF1kBL1BYurIvaBk6rgFsZSUHSodT8TXMUQcIg 8hfPXLk90SWxuzK2LDcTr8hQ/HJKNIFM+pRaNW3/9wz0JhM557WKuWedX/zPucTQ7uhi AlicP1XFVx03MtSsFW4EzWLxi7hFR4aJzVxEP2V9hTxSCWRxv05qHBnw5mmquThT6U8Y rq3A== X-Gm-Message-State: ABuFfoimEFC4jzcC2//V4WSd/SXr8adzq6+CmgZifegUApZJgjJNO7/R eoxECub+jw7/YG1s8Cs7DBGY+rPr X-Google-Smtp-Source: ACcGV63yWiQ89SOh9fUcW076V4wB56J/nsYAuxsT81Y+pQv4pyDEYWfF5CvGXD1yGhovFw3m9THUwg== X-Received: by 2002:adf:9464:: with SMTP id 91-v6mr14647707wrq.200.1538942422937; Sun, 07 Oct 2018 13:00:22 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:22 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 13/15] sequencer: use edit_todo_list() in complete_action() Date: Sun, 7 Oct 2018 21:54:16 +0200 Message-Id: <20181007195418.25752-14-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/sequencer.c b/sequencer.c index bfcbe8239b..93b9b40f66 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4608,7 +4608,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); @@ -4633,27 +4633,16 @@ int complete_action(struct replay_opts *opts, unsigned flags, return error(_("nothing to do")); } - todo_list_transform(todo_list, flags | TODO_LIST_SHORTEN_IDS); - - append_todo_help(flags & TODO_LIST_KEEP_EMPTY, command_count, - shortrevisions, shortonto, buf); - - if (write_message(buf->buf, buf->len, todo_file, 0)) - 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); @@ -4668,8 +4657,6 @@ int complete_action(struct replay_opts *opts, unsigned flags, return -1; } - todo_list_transform(&new_todo, flags & ~(TODO_LIST_SHORTEN_IDS)); - if (opts->allow_ff && skip_unnecessary_picks(&new_todo, &oid)) { todo_list_release(&new_todo); return error(_("could not skip unnecessary pick commands")); From patchwork Sun Oct 7 19:54: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: 10629723 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 79D1E14DB for ; Sun, 7 Oct 2018 20:00:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E59828BA9 for ; Sun, 7 Oct 2018 20:00:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62F9C28DDB; Sun, 7 Oct 2018 20:00:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CF6228BA9 for ; Sun, 7 Oct 2018 20:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728507AbeJHDIt (ORCPT ); Sun, 7 Oct 2018 23:08:49 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42494 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728464AbeJHDIs (ORCPT ); Sun, 7 Oct 2018 23:08:48 -0400 Received: by mail-wr1-f67.google.com with SMTP id g15-v6so15936611wru.9 for ; Sun, 07 Oct 2018 13:00:24 -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=XvUG1Qp1UeDyWRLFMHRivt4EQ0EfCG3osOgL4zO3kUA=; b=DQJvAFacy45nT3www0jcxKrHMX03349p5WFGvo88F70Rev7rpqBnDKA2ijurDnKY1Q +YQev6oK4QSbJK+GYybJM5tJZHWL7hVzeb2FR1lcDt30iZJUv+jIkIGzDRgF+5r4lcSO MXjcs5I2a0ruOLytsWrQu3k9bX0xgnrPt/BvOxa5184thT6tuN1Ku4argEz347XwvdG7 JcFZpp56Qntzl+CHC+7jNopK5j2QbiQpZjKhYmZlvyviZ6v+7CKjxX9r+8GaohSLXEa8 1ZgrXsEJGJkN2ll67ozFCR8EhOt6qFys6YxExWyF09Qh39+XObh7euKjH/35o36C42fe 3kVA== 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=XvUG1Qp1UeDyWRLFMHRivt4EQ0EfCG3osOgL4zO3kUA=; b=S4c4gM/jq1T9U4OQWiUTrjKpmAhJ74nIlKQNFbParw7VWgeTqfT4UxOLUYiYdVePVY 1gky5uhnrBfRHskyiBeafD8E5zCKsqN/7edazRj1v39d9SeSxnCOCsfHN35xUAm9HJi3 u67F4J/7ca8pJOD8aoPb1u8gAuhi9F+y3AovKkVVOeVq25mHbmueu3gw386TvTqpwQS4 Ty1k/KTnj+27Yju1j/ZVsll/kTevYbnIS1tcHgRQZmo0sjEJLgNQSqESojOgoMowRTMo P2AW4WdVisan0kNc9UaxBEzi+8BUuJfZfAcuredF8c4pH4/pk/DFcbc+G5ZEbdp2ETpk drOw== X-Gm-Message-State: ABuFfohp3xDF+GHL9FYDJrp8Q+fFVpUxu9eVkmUHw8h6CM2mQqU+xzGr Cla8jAz/RWYMMzDFjsENhj13tKC8 X-Google-Smtp-Source: ACcGV62f8ENY+dWV5wBVOtCNOaLXwIsc3dVqobfbp3mTEwl42He0yJJoFDJfOyaZFBCHoGjs99cC9A== X-Received: by 2002:adf:aa90:: with SMTP id h16-v6mr13572178wrc.216.1538942424045; Sun, 07 Oct 2018 13:00:24 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:23 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 14/15] sequencer: fix a call to error() in transform_todo_file() Date: Sun, 7 Oct 2018 21:54:17 +0200 Message-Id: <20181007195418.25752-15-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 --- sequencer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index 93b9b40f66..65bf251ba5 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4421,7 +4421,7 @@ int sequencer_add_exec_commands(const char *commands) int res; if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); + return error_errno(_("could not read '%s'."), todo_file); if (todo_list_parse_insn_buffer(todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); From patchwork Sun Oct 7 19:54:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10629725 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 AF43314DB for ; Sun, 7 Oct 2018 20:00:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2D4028BA9 for ; Sun, 7 Oct 2018 20:00:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9735828DDB; Sun, 7 Oct 2018 20:00:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B6E928BA9 for ; Sun, 7 Oct 2018 20:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728513AbeJHDIu (ORCPT ); Sun, 7 Oct 2018 23:08:50 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39524 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728509AbeJHDIu (ORCPT ); Sun, 7 Oct 2018 23:08:50 -0400 Received: by mail-wr1-f66.google.com with SMTP id 61-v6so17827564wrb.6 for ; Sun, 07 Oct 2018 13:00:25 -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=xHdkcsiWDiIW490lyZ3JpitTbg1V1pur8blPR1lks0Q=; b=VQ+CuR3CWro6bTb6r666o3Z5OahAUDNn7Fn189qQdhUmxBYUo/NmspE0runY3dHthh KvmJOa33H7R/8FRsqnoCkN2IjeekGES+jjv+XrH7DUIhVoB1bGUDngDp4sfc9dMxHUwY p/RYwrsEb+Kf9V3di4NQgZ3IgSwfSaeCT6Bu8X7exBMZTH9nNF3kJzrnuQ7Mh03cLNGg vRsjmEKfCdKFZ/OEOZahiA+PFcUUt/uh4xpgRI47H9YF9NPXTylQbxskX+7mvccRFZSp qGNj4+CDBPiS4jo1y5x6hSs/BN1Dq2/xNymwF6f5aKdu2G3HzYokssIbDNWQo9S6ekUb Umtw== 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=xHdkcsiWDiIW490lyZ3JpitTbg1V1pur8blPR1lks0Q=; b=gYBXVFFGl7Ht9S5r6XwMzyNsRScEAVtiKecvw1wc/MAPT2QUKsJM58AmKU8XVY4oSp 0gPJ2K1/A2xanUUomWO4aQafcHHNESaMNql2PgeQz4wLjuLikKIuRQ7yvKfb9ep0pH9D QOAPU4HW7Qo1ZCfn7LTdWLz1MhzLDaYfAZ5Hwi9CXZ6UALN6RAwG00Jx8+wNNGLE5oy0 qJ1Xh1NVoUxkLAGr9ZlPpW9G0uUfUadJLX73SbFHXTiMADcY4ouuFnfdLOjIhWiQlZ4H 3mxybpDTgjagYLg59p2JRDn7XKS7JTbK0kbhNjNLbN2MtSCqn7Ak7vlaNF40p8otJA4s tr6w== X-Gm-Message-State: ABuFfojVF6TVugHzLmzzjMxFMQao2JvHfPzKKNJXMqqJ8WUTuwlGtx24 AvF1bP4TNGYulUCx2i9uWms9rDVO X-Google-Smtp-Source: ACcGV605sbvj2YOUuMn63yPXv1inYQ5GBvNcNRjoS2+2BLUmcPOY2c57Kz0c5EuMnK/CYBZn6jJpIQ== X-Received: by 2002:adf:dd4c:: with SMTP id u12-v6mr13717504wrm.2.1538942425113; Sun, 07 Oct 2018 13:00:25 -0700 (PDT) Received: from localhost.localdomain (AToulouse-658-1-60-162.w92-136.abo.wanadoo.fr. [92.136.157.162]) by smtp.googlemail.com with ESMTPSA id u76-v6sm17082538wmd.10.2018.10.07.13.00.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Oct 2018 13:00:24 -0700 (PDT) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH 15/15] rebase--interactive: move transform_todo_file() to rebase--interactive.c Date: Sun, 7 Oct 2018 21:54:18 +0200 Message-Id: <20181007195418.25752-16-alban.gruin@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181007195418.25752-1-alban.gruin@gmail.com> References: <20181007195418.25752-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 | 21 +++++++++++++++++++++ sequencer.c | 21 --------------------- sequencer.h | 1 - 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 264e940b47..50b5c25402 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -33,6 +33,27 @@ 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); + } + + 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 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 65bf251ba5..e837e52b64 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4485,27 +4485,6 @@ void todo_list_transform(struct todo_list *todo_list, unsigned flags) 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 res; -} - int check_todo_list_from_file(void) { struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT; diff --git a/sequencer.h b/sequencer.h index fa84918c55..a4b0113206 100644 --- a/sequencer.h +++ b/sequencer.h @@ -137,7 +137,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,