From patchwork Wed Jan 23 20:58:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777843 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 B04B613BF for ; Wed, 23 Jan 2019 20:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F7D52DAD7 for ; Wed, 23 Jan 2019 20:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93BB42DB0F; Wed, 23 Jan 2019 20:59: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 448072DAD7 for ; Wed, 23 Jan 2019 20:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726872AbfAWU7W (ORCPT ); Wed, 23 Jan 2019 15:59:22 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46376 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbfAWU7V (ORCPT ); Wed, 23 Jan 2019 15:59:21 -0500 Received: by mail-wr1-f65.google.com with SMTP id l9so4077068wrt.13 for ; Wed, 23 Jan 2019 12:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LYYfdfiAcoCJF4U6QUWjDSmv01tdT3OgSmavxE5+B4Y=; b=q93LzjZk7oRWKdv41iM6fjtCFfOPwgokYbwD6mSywH2ucaYS3kw+aNrA1J6ypJR+Hr sIiJ4rIl8phFG6XevgHhhwhLv8mekYZv4QdeIrhdlBnDCvkqQ45QnFRSd9yMyPpucYlu 9M8eOToHx/VJDsmkcgp6yHLnuSqFDJImkNZo/lCUtAD9Awp3xSnrLE4JRwba/HVmBCdg unhzfPlXXarhORd+wJwmGd7UkPJMFigFCcgMmiv9X7v0aGzijllEs/dZEVf5EyB9v3ej eW2fCU5yMeFH0NSGwx3KPLMfXvBRGV/pu8Q3OY7p7zq+kdnqrUbgcP7GftoVK2H8MHza YYNg== 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=LYYfdfiAcoCJF4U6QUWjDSmv01tdT3OgSmavxE5+B4Y=; b=M3Yq0me3y/srBH/dgD+WHVi+/EwQYqA7r5RTN30Fa4M8/cFOPpGOIO3jnHKk1SALqy GrRG50BNYQxcKQzM+1g6o4okFYyO44V4Y1tly+JaxnjdxqYoWpaLyaOH1anXgkMinew3 XOMgo0IVPW8UYshMd+lUsjphhn9vMi18Vnd7rPif4DiIl8OYo0utaeZMf+bB7wegVKgz sFvZEeUbK7NccC03XQ9DlmCxdiYreTlhOxC6qfwov4RWBc9JQtjxAelYkspxCE64plBC cJyQy0cYu44u7eHQNw6hScXevR6tbmddUZwIq+XXBW0cyTGZQStKl3to9QfAnKhIWHY2 TeCQ== X-Gm-Message-State: AJcUukfyR6rNpZa3J9ojLS8BoYOV1hZqir/zkch9vaBIHCkHQ3QTUF9D e1kW9LFRSHZfdoeGet0W1ut98Nl1 X-Google-Smtp-Source: ALg8bN7LovKSsqc7lEadXJKsWgGDuO4xxkuE/hS5uoDvegxec/BjEM6o/BUcdSy/2KNtgQ7H5kDj7A== X-Received: by 2002:adf:91a3:: with SMTP id 32mr3928977wri.99.1548277159464; Wed, 23 Jan 2019 12:59:19 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:18 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 01/16] sequencer: changes in parse_insn_buffer() Date: Wed, 23 Jan 2019 21:58:06 +0100 Message-Id: <20190123205821.27459-2-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This clears the number of items of a todo_list before parsing it to allow to parse the same list multiple times without issues. As its items are not dynamically allocated, or don’t need to allocate memory, no additionnal memory management is required here. Furthermore, if a line is invalid, the type of the corresponding command is set to a garbage value, and its argument is defined properly. This will allow to recreate the text of a todo list from its commands, even if one of them is incorrect. Signed-off-by: Alban Gruin --- Unchanged since v4. sequencer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sequencer.c b/sequencer.c index d726f77e11..a7afaf6882 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2091,6 +2091,8 @@ static int parse_insn_buffer(struct repository *r, char *buf, char *p = buf, *next_p; int i, res = 0, fixup_okay = file_exists(rebase_path_done()); + todo_list->current = todo_list->nr = 0; + for (i = 1; *p; i++, p = next_p) { char *eol = strchrnul(p, '\n'); @@ -2104,7 +2106,10 @@ static int parse_insn_buffer(struct repository *r, char *buf, if (parse_insn_line(r, item, p, eol)) { res = error(_("invalid line %d: %.*s"), i, (int)(eol - p), p); - item->command = TODO_NOOP; + item->command = TODO_COMMENT + 1; + item->arg = p; + item->arg_len = (int)(eol - p); + item->commit = NULL; } if (fixup_okay) From patchwork Wed Jan 23 20:58:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777845 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 CCBD4746 for ; Wed, 23 Jan 2019 20:59:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC092DAD7 for ; Wed, 23 Jan 2019 20:59:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B04D32DB0F; Wed, 23 Jan 2019 20:59: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 BAFCD2DAD7 for ; Wed, 23 Jan 2019 20:59:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726895AbfAWU7Y (ORCPT ); Wed, 23 Jan 2019 15:59:24 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35254 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbfAWU7Y (ORCPT ); Wed, 23 Jan 2019 15:59:24 -0500 Received: by mail-wr1-f68.google.com with SMTP id 96so4143453wrb.2 for ; Wed, 23 Jan 2019 12:59:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZLrJvqGo9/a7DxNTFFnBPgKMldEvQMgdwBXGdrm58Ug=; b=Cwg0WjhMi0fswX0ndq9NY7A8NVVs0Pc7sQLu/dH59wJDI3fI+/FEI22zGq/NvGdUhG ZoMVzJgTyt/UgqMxAlqeWEUUOQotSQq4S1K6UNVi1OjZky2px0iHRZXbHBJRQIKmZ4lM i9KxVLAaDWyCi3F94ly//TfxOq6b4Ya89cCJunX3WyEzF6m0Rhka8WZmHbVYlXyfupJv IkAlrKDV6tJf4r/4alM5MHeSlkWTMOlgvkfFy04ds05/OvpLnIp15KXm/Ooj2eQSdOTV 0Uo2z2B/dRYEP6auzphH2j6lboIDqGvcx07eFDtdr9D3CGISYWApqSgsDUACTEU8v7DH AEww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZLrJvqGo9/a7DxNTFFnBPgKMldEvQMgdwBXGdrm58Ug=; b=XmZHPWbtq3AEK3b85hJHg93hSxepaCtxP1wMv3Fiyc0p9a/QAQw2RQoM9Mr1TOlPzA YXthJeJu12aeGqqE06MlEk2l/1eWawCyO6rfyUmKm/Yoa7hbfp85YaGK21EF2UJaTl07 Fp/lWiVWb8byVcXlAJK+RnnDPh5hYRFnaX4qFi77eht8lJQWnUgY2MAI5jkMXP5OJQ57 xLTr1AFdtn197nX4arZQB0IxvFgbCjt7qmaW0t7UKgagS4WTZvqVgf3vxPjigYvsqZzO /NKMKQ4vxDWS0N1XcIuZy3VvR55ykZol/SyhqaGOf0Hqy41MxBkRPpY4qBsMB8K0pHa5 aIlw== X-Gm-Message-State: AJcUukf6xy9lnASeeKD801KYBm2emYS4tAPb85lvAGYetTcIF7UfQXEK ttxoKlihvSnPEHCJJzkBIhCB3MOQ X-Google-Smtp-Source: ALg8bN6jDLZ5itbrSUjc4DWc/JvFEuIPZDmHIMdEMH5g2Gw444SpmbHuap4FqZCzCmnSQgXB888n9A== X-Received: by 2002:a5d:5409:: with SMTP id g9mr4417861wrv.88.1548277161449; Wed, 23 Jan 2019 12:59:21 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:20 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 02/16] sequencer: make the todo_list structure public Date: Wed, 23 Jan 2019 21:58:07 +0100 Message-Id: <20190123205821.27459-3-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-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 --- Unchanged since v4. sequencer.c | 69 ++++++++++------------------------------------------- sequencer.h | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 57 deletions(-) diff --git a/sequencer.c b/sequencer.c index a7afaf6882..5b84a20532 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1460,32 +1460,6 @@ static int allow_empty(struct repository *r, return 1; } -/* - * Note that ordering matters in this enum. Not only must it match the mapping - * below, it is also divided into several sections that matter. When adding - * new commands, make sure you add it in the right section. - */ -enum todo_command { - /* commands that handle commits */ - TODO_PICK = 0, - TODO_REVERT, - TODO_EDIT, - TODO_REWORD, - TODO_FIXUP, - TODO_SQUASH, - /* commands that do something else than handling a single commit */ - TODO_EXEC, - TODO_BREAK, - TODO_LABEL, - TODO_RESET, - TODO_MERGE, - /* commands that do nothing but are counted for reporting progress */ - TODO_NOOP, - TODO_DROP, - /* comments (not counted for reporting progress) */ - TODO_COMMENT -}; - static struct { char c; const char *str; @@ -1962,26 +1936,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); @@ -2084,8 +2039,8 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, return !item->commit; } -static int parse_insn_buffer(struct repository *r, char *buf, - struct todo_list *todo_list) +int todo_list_parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list) { struct todo_item *item; char *p = buf, *next_p; @@ -2184,7 +2139,7 @@ static int read_populate_todo(struct repository *r, return error(_("could not stat '%s'"), todo_file); fill_stat_data(&todo_list->stat, &st); - res = parse_insn_buffer(r, todo_list->buf.buf, todo_list); + res = todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); if (res) { if (is_rebase_i(opts)) return error(_("please fix this using " @@ -2215,7 +2170,7 @@ static int read_populate_todo(struct repository *r, FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w"); if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 && - !parse_insn_buffer(r, done.buf.buf, &done)) + !todo_list_parse_insn_buffer(r, done.buf.buf, &done)) todo_list->done_nr = count_commands(&done); else todo_list->done_nr = 0; @@ -4501,7 +4456,7 @@ int sequencer_add_exec_commands(struct repository *r, if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4557,7 +4512,7 @@ int transform_todos(struct repository *r, unsigned flags) if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4643,7 +4598,7 @@ int check_todo_list(struct repository *r) goto leave_check; } advise_to_edit_todo = res = - parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); if (res || check_level == MISSING_COMMIT_CHECK_IGNORE) goto leave_check; @@ -4662,7 +4617,7 @@ int check_todo_list(struct repository *r) goto leave_check; } strbuf_release(&todo_file); - res = !!parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + res = !!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); /* Find commits in git-rebase-todo.backup yet unseen */ for (i = todo_list.nr - 1; i >= 0; i--) { @@ -4744,7 +4699,7 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } @@ -4832,7 +4787,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (strbuf_read_file(buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - if (parse_insn_buffer(r, buf->buf, &todo_list)) { + if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) { todo_list_release(&todo_list); return error(_("unusable todo list: '%s'"), todo_file); } @@ -4940,7 +4895,7 @@ int rearrange_squash(struct repository *r) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) return -1; - if (parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { todo_list_release(&todo_list); return -1; } diff --git a/sequencer.h b/sequencer.h index d2c18edd3a..7dc4d8946b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -73,6 +73,56 @@ enum missing_commit_check_level { int write_message(const void *buf, size_t len, const char *filename, int append_eol); +/* + * Note that ordering matters in this enum. Not only must it match the mapping + * of todo_command_info (in sequencer.c), it is also divided into several + * sections that matter. When adding new commands, make sure you add it in the + * right section. + */ +enum todo_command { + /* commands that handle commits */ + TODO_PICK = 0, + TODO_REVERT, + TODO_EDIT, + TODO_REWORD, + TODO_FIXUP, + TODO_SQUASH, + /* commands that do something else than handling a single commit */ + TODO_EXEC, + TODO_BREAK, + TODO_LABEL, + TODO_RESET, + TODO_MERGE, + /* commands that do nothing but are counted for reporting progress */ + TODO_NOOP, + TODO_DROP, + /* comments (not counted for reporting progress) */ + TODO_COMMENT +}; + +struct todo_item { + enum todo_command command; + struct commit *commit; + unsigned int flags; + const char *arg; + int arg_len; + size_t offset_in_buf; +}; + +struct todo_list { + struct strbuf buf; + struct todo_item *items; + int nr, alloc, current; + int done_nr, total_nr; + struct stat_data stat; +}; + +#define TODO_LIST_INIT { STRBUF_INIT } + +int todo_list_parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list); +void todo_list_release(struct todo_list *todo_list); + /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); int sequencer_pick_revisions(struct repository *repo, From patchwork Wed Jan 23 20:58:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777847 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 0C03F746 for ; Wed, 23 Jan 2019 20:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFC562DB02 for ; Wed, 23 Jan 2019 20:59:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E41C62DB54; Wed, 23 Jan 2019 20:59:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B2F02DB02 for ; Wed, 23 Jan 2019 20:59:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726945AbfAWU72 (ORCPT ); Wed, 23 Jan 2019 15:59:28 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35255 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbfAWU7Z (ORCPT ); Wed, 23 Jan 2019 15:59:25 -0500 Received: by mail-wr1-f65.google.com with SMTP id 96so4143542wrb.2 for ; Wed, 23 Jan 2019 12:59:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CHCEIct0xj17J2FrYa9T4rR7NSGDzAZvbtGwvt2P0RA=; b=WufJ2+t8ER03epyxGZkUnVG/6jPXRt9SVpit3mzcq00VbJDRC1aDwEh13aKw+HNGDl loWFkzAqAy8PLAlz9W0SZpcp3uaevC0Z9DRO5rAKq6DXNTgDaTLar/s+J7DcZjoZmz38 qOThLCdfQoEuueWpbe8PQTajRcL/31W0vYORpJbRZ+9n7KrkKj6H/tecnH4gK04FrsfG v5kKAi6eZcqZRDSeZWSTAwRrriAFfhd4DPdlu7Q0P9w0FPDHk7CbzbDoUhUYCfbnw/qk LjqyjnhrndIHBiAeDIZH6ntABDuDqpSYgLBtKlzmOrfVsgVWlDJkh+wqk8KLEmbGcc3I 8tTw== 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=CHCEIct0xj17J2FrYa9T4rR7NSGDzAZvbtGwvt2P0RA=; b=p+xaQQxYruFTCtKoGsiyZyWrfUyQENAEggCnNfKRTy4eNSZfrWrtHwrLfpx/cNa9IZ aamZ7oBksHP/QqR7fgmYVTxs0QaWFBTfdNG/b7u8OsHWh/KWMbs9N3UivQKNINiTnuSR b3FVs0TZpGj55Z54wLLsaw9vXDtZO2ybsQu03y57FS7nx/SQ3K9uL3olz5p9Km5chLau YosXmwRMbHploswS8EhhH/UofXFCUSIpveUqLs95QjjZpxhF6SvwF3Zpkul1g9+PiA7T WUtOoOoVjjj376pC4Dnb2MUAl6/rvgGrCu/2aYZJTk2ZOXpwc+CAheAlinxuTUGQFaxh TbUA== X-Gm-Message-State: AJcUukcaAyloAZ+H6wnpSd1iqofIIRR1uAVtNsmG7+m7ZzVv2lmRLf9j 4zYpymHWZiI6GugZjMPL6KJAO3+l X-Google-Smtp-Source: ALg8bN40HkCkHwcHaVo6t2DQWF/IZs64dF9M5KDPmF1sq5dKnIrBbqsoNO8rLVOlFtNf0nEDA/KK8A== X-Received: by 2002:a5d:66c1:: with SMTP id k1mr4247693wrw.132.1548277163291; Wed, 23 Jan 2019 12:59:23 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:22 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 03/16] sequencer: remove the 'arg' field from todo_item Date: Wed, 23 Jan 2019 21:58:08 +0100 Message-Id: <20190123205821.27459-4-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The 'arg' field of todo_item used to store the address of the first byte of the parameter of a command in a todo list. It was associated with the length of the parameter (the 'arg_len' field). This replaces the 'arg' field by 'arg_offset'. This new field does not store the address of the parameter, but the position of the first character of the parameter in the buffer. todo_item_get_arg() is added to return the address of the parameter of an item. This will prevent todo_list_add_exec_commands() from having to do awful pointer arithmetics when growing the todo list buffer. Signed-off-by: Alban Gruin --- Introduction and use of todo_item_get_arg(). sequencer.c | 67 ++++++++++++++++++++++++++++++----------------------- sequencer.h | 6 +++-- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/sequencer.c b/sequencer.c index 5b84a20532..0e7ab16a05 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1949,8 +1949,14 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list) return todo_list->items + todo_list->nr++; } +const char *todo_item_get_arg(struct todo_list *todo_list, + struct todo_item *item) +{ + return todo_list->buf.buf + item->arg_offset; +} + static int parse_insn_line(struct repository *r, struct todo_item *item, - const char *bol, char *eol) + const char *buf, const char *bol, char *eol) { struct object_id commit_oid; char *end_of_object_name; @@ -1964,7 +1970,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, if (bol == eol || *bol == '\r' || *bol == comment_line_char) { item->command = TODO_COMMENT; item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = eol - bol; return 0; } @@ -1991,7 +1997,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, return error(_("%s does not accept arguments: '%s'"), command_to_string(item->command), bol); item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = eol - bol; return 0; } @@ -2003,7 +2009,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, if (item->command == TODO_EXEC || item->command == TODO_LABEL || item->command == TODO_RESET) { item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = (int)(eol - bol); return 0; } @@ -2017,7 +2023,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, } else { item->flags |= TODO_EDIT_MERGE_MSG; item->commit = NULL; - item->arg = bol; + item->arg_offset = bol - buf; item->arg_len = (int)(eol - bol); return 0; } @@ -2029,8 +2035,9 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, status = get_oid(bol, &commit_oid); *end_of_object_name = saved; - item->arg = end_of_object_name + strspn(end_of_object_name, " \t"); - item->arg_len = (int)(eol - item->arg); + bol = end_of_object_name + strspn(end_of_object_name, " \t"); + item->arg_offset = bol - buf; + item->arg_len = (int)(eol - bol); if (status < 0) return -1; @@ -2058,11 +2065,11 @@ int todo_list_parse_insn_buffer(struct repository *r, char *buf, item = append_new_todo(todo_list); item->offset_in_buf = p - todo_list->buf.buf; - if (parse_insn_line(r, item, p, eol)) { + if (parse_insn_line(r, item, buf, p, eol)) { res = error(_("invalid line %d: %.*s"), i, (int)(eol - p), p); item->command = TODO_COMMENT + 1; - item->arg = p; + item->arg_offset = p - buf; item->arg_len = (int)(eol - p); item->commit = NULL; } @@ -2402,7 +2409,7 @@ static int walk_revs_populate_todo(struct todo_list *todo_list, item->command = command; item->commit = commit; - item->arg = NULL; + item->arg_offset = 0; item->arg_len = 0; item->offset_in_buf = todo_list->buf.len; subject_len = find_commit_subject(commit_buffer, &subject); @@ -3438,6 +3445,8 @@ static int pick_commits(struct repository *r, while (todo_list->current < todo_list->nr) { struct todo_item *item = todo_list->items + todo_list->current; + const char *arg = todo_item_get_arg(todo_list, item); + if (save_todo(todo_list, opts)) return -1; if (is_rebase_i(opts)) { @@ -3488,10 +3497,9 @@ static int pick_commits(struct repository *r, fprintf(stderr, _("Stopped at %s... %.*s\n"), short_commit_name(commit), - item->arg_len, item->arg); + item->arg_len, arg); return error_with_patch(r, commit, - item->arg, item->arg_len, opts, res, - !res); + arg, item->arg_len, opts, res, !res); } if (is_rebase_i(opts) && !res) record_in_rewritten(&item->commit->object.oid, @@ -3500,7 +3508,7 @@ static int pick_commits(struct repository *r, if (res == 1) intend_to_amend(); return error_failed_squash(r, item->commit, opts, - item->arg_len, item->arg); + item->arg_len, arg); } else if (res && is_rebase_i(opts) && item->commit) { int to_amend = 0; struct object_id oid; @@ -3519,16 +3527,16 @@ static int pick_commits(struct repository *r, to_amend = 1; return res | error_with_patch(r, item->commit, - item->arg, item->arg_len, opts, + arg, item->arg_len, opts, res, to_amend); } } else if (item->command == TODO_EXEC) { - char *end_of_arg = (char *)(item->arg + item->arg_len); + char *end_of_arg = (char *)(arg + item->arg_len); int saved = *end_of_arg; struct stat st; *end_of_arg = '\0'; - res = do_exec(r, item->arg); + res = do_exec(r, arg); *end_of_arg = saved; /* Reread the todo file if it has changed. */ @@ -3545,14 +3553,14 @@ static int pick_commits(struct repository *r, todo_list->current = -1; } } else if (item->command == TODO_LABEL) { - if ((res = do_label(r, item->arg, item->arg_len))) + if ((res = do_label(r, arg, item->arg_len))) reschedule = 1; } else if (item->command == TODO_RESET) { - if ((res = do_reset(r, item->arg, item->arg_len, opts))) + if ((res = do_reset(r, arg, item->arg_len, opts))) reschedule = 1; } else if (item->command == TODO_MERGE) { if ((res = do_merge(r, item->commit, - item->arg, item->arg_len, + arg, item->arg_len, item->flags, opts)) < 0) reschedule = 1; else if (item->commit) @@ -3561,9 +3569,8 @@ static int pick_commits(struct repository *r, if (res > 0) /* failed with merge conflicts */ return error_with_patch(r, item->commit, - item->arg, - item->arg_len, opts, - res, 0); + arg, item->arg_len, + opts, res, 0); } else if (!is_noop(item->command)) return error(_("unknown command %d"), item->command); @@ -3578,9 +3585,8 @@ static int pick_commits(struct repository *r, if (item->commit) return error_with_patch(r, item->commit, - item->arg, - item->arg_len, opts, - res, 0); + arg, item->arg_len, + opts, res, 0); } todo_list->current++; @@ -4520,7 +4526,8 @@ int transform_todos(struct repository *r, unsigned flags) for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { - strbuf_addf(&buf, "%.*s\n", item->arg_len, item->arg); + strbuf_addf(&buf, "%.*s\n", item->arg_len, + todo_item_get_arg(&todo_list, item)); continue; } @@ -4550,7 +4557,8 @@ int transform_todos(struct repository *r, unsigned flags) if (!item->arg_len) strbuf_addch(&buf, '\n'); else - strbuf_addf(&buf, " %.*s\n", item->arg_len, item->arg); + strbuf_addf(&buf, " %.*s\n", item->arg_len, + todo_item_get_arg(&todo_list, item)); } i = write_message(buf.buf, buf.len, todo_file, 0); @@ -4626,7 +4634,8 @@ int check_todo_list(struct repository *r) if (commit && !*commit_seen_at(&commit_seen, commit)) { strbuf_addf(&missing, " - %s %.*s\n", short_commit_name(commit), - item->arg_len, item->arg); + item->arg_len, + todo_item_get_arg(&todo_list, item)); *commit_seen_at(&commit_seen, commit) = 1; } } diff --git a/sequencer.h b/sequencer.h index 7dc4d8946b..cdb9ed7a2d 100644 --- a/sequencer.h +++ b/sequencer.h @@ -104,9 +104,9 @@ struct todo_item { enum todo_command command; struct commit *commit; unsigned int flags; - const char *arg; int arg_len; - size_t offset_in_buf; + /* The offset of the command and its argument in the strbuf */ + size_t offset_in_buf, arg_offset; }; struct todo_list { @@ -122,6 +122,8 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); void todo_list_release(struct todo_list *todo_list); +const char *todo_item_get_arg(struct todo_list *todo_list, + struct todo_item *item); /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); From patchwork Wed Jan 23 20:58:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777849 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 C9D9D13BF for ; Wed, 23 Jan 2019 20:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8DEC2DB02 for ; Wed, 23 Jan 2019 20:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8F2B2DB54; Wed, 23 Jan 2019 20:59: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 1C5402DB02 for ; Wed, 23 Jan 2019 20:59:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbfAWU72 (ORCPT ); Wed, 23 Jan 2019 15:59:28 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:33026 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbfAWU72 (ORCPT ); Wed, 23 Jan 2019 15:59:28 -0500 Received: by mail-wr1-f67.google.com with SMTP id p7so4160876wru.0 for ; Wed, 23 Jan 2019 12:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1hjRCPf7UvfUreMFOiZvUPxg0dOIxoanS1pp4QLB3so=; b=thu+gY2NFJUAWdRagWGYgMW5OuwMQdLD0xZbzt7hlCrZbHqKIDBWY8Bz3TRk3smi0T wsC4iRP92WfaVp7GXrozyfB/fOxj4LzxVg2WCo5LAFuymfFKHOqYj6JlUBjTXWZ86Ptf WkWaOCV3QqO8i3jiOlvUeq1yGOAcg/iuK09WOX27sF2LxqRavY34c3NXn65Gq5rNmJkS ivr90kX9QNoUuBLbOq1TjfUESwTowY1HyfRnJYA9D4AhDTCCV+xXTDQi9r7xc/Hh/7xI jCO6WIXJN4Ta4JdVYsoTSwfaTR5HGGrAXDu899V6idl3/A9x4ZRoK0aQxzL6eBurfKLK kPcA== 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=1hjRCPf7UvfUreMFOiZvUPxg0dOIxoanS1pp4QLB3so=; b=q3KzcGV0LpmZhPJuN3k8HT1/xTbst7w6Hje+K7lLz8hTkTu1NTdnI4l9yj3VdTLxVQ 97FMKnZvzN3Kn4umoWVD8YTxRGKfKXfD65rE0HWusx54VGhwLskqMWvbx17HdMtbSqp/ MOzPC04vqHjbNcDS6319Nd0IM3W2rf8Nl61YxYDNHpueH8mzkph1FT+SPSkEd+as6/Va KHTZ3kyHUvGD4J7H0X5HMwlILDUhQCfGFrTj/IOZ2nvlmJwLEcfSvbRsoYOcR9/SURKt OPkKbOKkbpMdYc+BwAbsDXSYEMkxMOp3PCCfnPVDfIOmCoUgVbAILtBGtZ0fAX4POo/V DHpg== X-Gm-Message-State: AJcUukdX2GVrVWvGHbHI2rYu48W/nuuhAoCwLd7hSTUO5SlH7FbzIjjT fZt8QvtIvzS6VWHVLrTpkNjD6FYB X-Google-Smtp-Source: ALg8bN5pHRmjLYvcMAf/YGuwekK3lyNST3cgRS3c4NAzFGPQ+5PURJUQW4zX+79jh8GxyMxsoqrhHg== X-Received: by 2002:adf:f401:: with SMTP id g1mr4454091wro.103.1548277164952; Wed, 23 Jan 2019 12:59:24 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:24 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 04/16] sequencer: refactor transform_todos() to work on a todo_list Date: Wed, 23 Jan 2019 21:58:09 +0100 Message-Id: <20190123205821.27459-5-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This refactors transform_todos() to work on a todo_list. The function is renamed todo_list_transform(). As rebase -p still need to check the todo list from the disk, a new function is introduced, transform_todo_file(). It is still used by complete_action() and edit_todo_list() for now, but they will be replaced in a future commit. todo_list_transform() is not a static function, because it will be used by edit_todo_list() from rebase-interactive.c in a future commit. Signed-off-by: Alban Gruin --- builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 4 +-- sequencer.c | 54 +++++++++++++++++++++++------------ sequencer.h | 4 ++- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index dd2a55ab1d..0898eb4c59 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -253,7 +253,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) } case SHORTEN_OIDS: case EXPAND_OIDS: - ret = transform_todos(the_repository, flags); + ret = transform_todo_file(the_repository, flags); break; case CHECK_TODO_LIST: ret = check_todo_list(the_repository); diff --git a/rebase-interactive.c b/rebase-interactive.c index 68aff1dac2..842fa07e7e 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -69,7 +69,7 @@ int edit_todo_list(struct repository *r, unsigned flags) strbuf_release(&buf); - transform_todos(r, flags | TODO_LIST_SHORTEN_IDS); + transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS); if (strbuf_read_file(&buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); @@ -85,7 +85,7 @@ int edit_todo_list(struct repository *r, unsigned flags) if (launch_sequence_editor(todo_file, NULL, NULL)) return -1; - transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS)); + transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS)); return 0; } diff --git a/sequencer.c b/sequencer.c index 0e7ab16a05..7a295cbd3f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4507,27 +4507,18 @@ int sequencer_add_exec_commands(struct repository *r, return i; } -int transform_todos(struct repository *r, unsigned flags) +void todo_list_transform(struct repository *r, struct todo_list *todo_list, + unsigned flags) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; struct strbuf buf = STRBUF_INIT; struct todo_item *item; int i; - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) { + for (item = todo_list->items, i = 0; i < todo_list->nr; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { strbuf_addf(&buf, "%.*s\n", item->arg_len, - todo_item_get_arg(&todo_list, item)); + todo_item_get_arg(todo_list, item)); continue; } @@ -4558,12 +4549,39 @@ int transform_todos(struct repository *r, unsigned flags) strbuf_addch(&buf, '\n'); else strbuf_addf(&buf, " %.*s\n", item->arg_len, - todo_item_get_arg(&todo_list, item)); + todo_item_get_arg(todo_list, item)); } - i = write_message(buf.buf, buf.len, todo_file, 0); + strbuf_reset(&todo_list->buf); + strbuf_add(&todo_list->buf, buf.buf, buf.len); + strbuf_release(&buf); + + if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list)) + BUG("unusable todo list"); +} + +int transform_todo_file(struct repository *r, unsigned flags) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_transform(r, &todo_list, flags); + + res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); todo_list_release(&todo_list); - return i; + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } enum missing_commit_check_level get_missing_commit_check_level(void) @@ -4825,7 +4843,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return error(_("could not copy '%s' to '%s'."), todo_file, rebase_path_todo_backup()); - if (transform_todos(r, flags | TODO_LIST_SHORTEN_IDS)) + if (transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS)) return error(_("could not transform the todo list")); strbuf_reset(buf); @@ -4854,7 +4872,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return -1; } - if (transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS))) + if (transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS))) return error(_("could not transform the todo list")); if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) diff --git a/sequencer.h b/sequencer.h index cdb9ed7a2d..35472c137b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -121,6 +121,8 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); +void todo_list_transform(struct repository *r, struct todo_list *todo_list, + unsigned flags); void todo_list_release(struct todo_list *todo_list); const char *todo_item_get_arg(struct todo_list *todo_list, struct todo_item *item); @@ -148,7 +150,7 @@ int sequencer_make_script(struct repository *repo, FILE *out, unsigned flags); int sequencer_add_exec_commands(struct repository *r, const char *command); -int transform_todos(struct repository *r, unsigned flags); +int transform_todo_file(struct repository *r, unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, From patchwork Wed Jan 23 20:58:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777851 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 AB4BA13BF for ; Wed, 23 Jan 2019 20:59:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CF732DB02 for ; Wed, 23 Jan 2019 20:59:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 915F52DB54; Wed, 23 Jan 2019 20:59: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 094F82DB02 for ; Wed, 23 Jan 2019 20:59:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfAWU7b (ORCPT ); Wed, 23 Jan 2019 15:59:31 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43601 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbfAWU73 (ORCPT ); Wed, 23 Jan 2019 15:59:29 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10so4096767wrs.10 for ; Wed, 23 Jan 2019 12:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GPO5BnIUA32a6E0ynCkbvXilHzFIiepRM9A23Q3dtQs=; b=dtep6Thb8XyAAXBcsDF4bPIwrKjxZ3pHCE23LqZzitljwZRp/Fi3gbT3cxIAxy3lDm +BgO8Egq+xEgUOtEsD5dYDLL3do7x0F6WH1IcMT14T56N/OCiVYCw9RjLDQnrEKQdjs+ C4wRd+WkhtRXEjLzon83O+M1G7dgQYqnmSTKqW6hK37MsLVmqIuysPVP6FioneiEJTpe O53M0V9bLtFcGyZxAxC8I0ws28Zlcrrqf/1ZkVXRnOGbHeSwfQ5gGZUsN2sGPhYIl25p rlMegA7nBsOH8NxOCLZmrqhErxJn6MqPPEx9iOHDDJv5K/sZs85AfiHKHsZ6/VmzA5RN H8yg== 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=GPO5BnIUA32a6E0ynCkbvXilHzFIiepRM9A23Q3dtQs=; b=qg1tsNxG9FHP/lkCsI1fsUOnbVYaRs/cA75TjyuWcS6epzlHPnihdudSkHMvfkcNCZ PeHWvJej9kTF4FKAI5EB9geGFBL8DkgOJu+YfzSsWlpeILyAceb11KHO4DV88E/Fv2of aWHmqVK2AtPcPdPQ72ZVVLN4uxi9n0cQRlagfEx4V2eNXTuJyZp2UQFl9gLSrtYpIcc2 tgN6QIfzRPSpLs5RRjXVCSzev7U/1lPlNL7GKxvsMy8m9Q0idfM7w8nkaWJuQzzmpTgr h/W0tm1I5GtZA+CafEKLN/Fd9JzcVmkmbR7ps2D78xvkXF7igFmNG49okvvRgEJDYNel pkzg== X-Gm-Message-State: AJcUukeyVToqPjNt1L9Ni4MBPEDH2daU5IkVMu9PQWbthddITxclnYeW I200v2Oy22mgX3FGJhfqC2ort9AA X-Google-Smtp-Source: ALg8bN5hvuk9MbFZuZoOMAfcRwvdw/r07DdeAl9ew+jM/9nKitsy6Q4/gLuQOnkYj5IIJAIUhL73Fw== X-Received: by 2002:a05:6000:12c4:: with SMTP id l4mr4306143wrx.134.1548277166803; Wed, 23 Jan 2019 12:59:26 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:26 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 05/16] sequencer: introduce todo_list_write_to_file() Date: Wed, 23 Jan 2019 21:58:10 +0100 Message-Id: <20190123205821.27459-6-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This introduces a new function to recreate the text of a todo list from its commands and write it to a file. This will be useful as the next few commits will change the use of the buffer in struct todo_list so it will no longer be a mirror of the file on disk. This functionality already exists in todo_list_transform(), but this function was made to replace the buffer of a todo list, which is not what we want here. Thus, the part of todo_list_transform() that replaces the buffer is dropped, and the function is renamed todo_list_to_strbuf(). It is called by todo_list_write_to_file() to fill the buffer to write to the disk. todo_list_write_to_file() can also take care of appending the help text to the buffer before writing it to the disk, or to write only the first n items of the list. This feature will be used by skip_unnecessary_picks(), which has to write done commands in a file. Signed-off-by: Alban Gruin --- sequencer.c | 61 +++++++++++++++++++++++++++++++++++------------------ sequencer.h | 11 ++++++---- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/sequencer.c b/sequencer.c index 7a295cbd3f..87b43994ff 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4507,26 +4507,28 @@ int sequencer_add_exec_commands(struct repository *r, return i; } -void todo_list_transform(struct repository *r, struct todo_list *todo_list, - unsigned flags) +static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list, + struct strbuf *buf, int num, unsigned flags) { - struct strbuf buf = STRBUF_INIT; struct todo_item *item; - int i; + int i, max = todo_list->nr; - for (item = todo_list->items, i = 0; i < todo_list->nr; i++, item++) { + if (num > 0 && num < max) + max = num; + + for (item = todo_list->items, i = 0; i < max; i++, item++) { /* if the item is not a command write it and continue */ if (item->command >= TODO_COMMENT) { - strbuf_addf(&buf, "%.*s\n", item->arg_len, + strbuf_addf(buf, "%.*s\n", item->arg_len, todo_item_get_arg(todo_list, item)); continue; } /* add command to the buffer */ if (flags & TODO_LIST_ABBREVIATE_CMDS) - strbuf_addch(&buf, command_to_char(item->command)); + strbuf_addch(buf, command_to_char(item->command)); else - strbuf_addstr(&buf, command_to_string(item->command)); + strbuf_addstr(buf, command_to_string(item->command)); /* add commit id */ if (item->commit) { @@ -4536,28 +4538,48 @@ void todo_list_transform(struct repository *r, struct todo_list *todo_list, if (item->command == TODO_MERGE) { if (item->flags & TODO_EDIT_MERGE_MSG) - strbuf_addstr(&buf, " -c"); + strbuf_addstr(buf, " -c"); else - strbuf_addstr(&buf, " -C"); + strbuf_addstr(buf, " -C"); } - strbuf_addf(&buf, " %s", oid); + strbuf_addf(buf, " %s", oid); } /* add all the rest */ if (!item->arg_len) - strbuf_addch(&buf, '\n'); + strbuf_addch(buf, '\n'); else - strbuf_addf(&buf, " %.*s\n", item->arg_len, + strbuf_addf(buf, " %.*s\n", item->arg_len, todo_item_get_arg(todo_list, item)); } +} - strbuf_reset(&todo_list->buf); - strbuf_add(&todo_list->buf, buf.buf, buf.len); +int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, + const char *file, const char *shortrevisions, + const char *shortonto, int num, unsigned flags) +{ + int edit_todo = !(shortrevisions && shortonto), res; + struct strbuf buf = STRBUF_INIT; + + todo_list_to_strbuf(r, todo_list, &buf, num, flags); + + if (flags & TODO_LIST_APPEND_TODO_HELP) { + int command_count = count_commands(todo_list); + if (!edit_todo) { + strbuf_addch(&buf, '\n'); + strbuf_commented_addf(&buf, Q_("Rebase %s onto %s (%d command)", + "Rebase %s onto %s (%d commands)", + command_count), + shortrevisions, shortonto, command_count); + } + append_todo_help(edit_todo, flags & TODO_LIST_KEEP_EMPTY, &buf); + } + + res = write_message(buf.buf, buf.len, file, 0); strbuf_release(&buf); - if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list)) - BUG("unusable todo list"); + return res; } int transform_todo_file(struct repository *r, unsigned flags) @@ -4574,9 +4596,8 @@ int transform_todo_file(struct repository *r, unsigned flags) return error(_("unusable todo list: '%s'"), todo_file); } - todo_list_transform(r, &todo_list, flags); - - res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0); + res = todo_list_write_to_file(r, &todo_list, todo_file, + NULL, NULL, -1, flags); todo_list_release(&todo_list); if (res) diff --git a/sequencer.h b/sequencer.h index 35472c137b..dc3d8f76f7 100644 --- a/sequencer.h +++ b/sequencer.h @@ -121,8 +121,9 @@ struct todo_list { int todo_list_parse_insn_buffer(struct repository *r, char *buf, struct todo_list *todo_list); -void todo_list_transform(struct repository *r, struct todo_list *todo_list, - unsigned flags); +int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, + const char *file, const char *shortrevisions, + const char *shortonto, int num, unsigned flags); void todo_list_release(struct todo_list *todo_list); const char *todo_item_get_arg(struct todo_list *todo_list, struct todo_item *item); @@ -145,8 +146,10 @@ int sequencer_remove_state(struct replay_opts *opts); * commits should be rebased onto the new base, this flag needs to be passed. */ #define TODO_LIST_REBASE_COUSINS (1U << 4) -int sequencer_make_script(struct repository *repo, FILE *out, - int argc, const char **argv, +#define TODO_LIST_APPEND_TODO_HELP (1U << 5) + +int sequencer_make_script(struct repository *r, FILE *out, int argc, + const char **argv, unsigned flags); int sequencer_add_exec_commands(struct repository *r, const char *command); From patchwork Wed Jan 23 20:58:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777853 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 B879D746 for ; Wed, 23 Jan 2019 20:59:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A700A2DB0F for ; Wed, 23 Jan 2019 20:59:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B4FF2DB6A; Wed, 23 Jan 2019 20:59: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 C6FB12DB0F for ; Wed, 23 Jan 2019 20:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726967AbfAWU7c (ORCPT ); Wed, 23 Jan 2019 15:59:32 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34024 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726356AbfAWU7b (ORCPT ); Wed, 23 Jan 2019 15:59:31 -0500 Received: by mail-wr1-f65.google.com with SMTP id f7so4159049wrp.1 for ; Wed, 23 Jan 2019 12:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=buBwOYlM+59gtu9HUT8VKp8owcNA4c+6iTtqvnZtKy4=; b=NkbrlwfDSuBKkpdSTAyBmlTTYSlmelmdfpu+MppdkH3DfVR/Yr6b/SCaokEVQ7Ums4 lpWLgTnYt3WdPDJ9oeeAU+8l80KQyOm2IIQAIl/TNh+qiDKmW0QJJMt5QRYSWiGHqm3V iypxoNlEuRq31KC7DfY8XF7HCx8vs+mRKXse+WlohOenITCbSRs5g3aB8+08s9iSW1pb o4pLcux+Tbpg8dAUlP0b1RqjflowBVWUgVUiIyZbXIfo+vi0ZkPzYgSSmQ/RX2rM00JN rlBngiBnHTBa5XWRRzXBMh2j5eLuyKIfFWlhkvLN8ctrthC6aHeR2EaS+eLbYChZ4yNA 4kFQ== 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=buBwOYlM+59gtu9HUT8VKp8owcNA4c+6iTtqvnZtKy4=; b=ntIWl8Gok7TPvSLqVNYUQ08pCtqNstJUBAlWDSlLGciag4l7hP5/yLh7inYTmRyZoG 6sC3hOf4SWVEMlAkdpRfsAk27CYlJ/P1th+q1HkxH8gGHrjyQOB3OIhHxiHGltuBjCls L7qjlrV5HJZuEf1iOpEE/z74u1Y3VP8eBFT9rbNWfwUdU1epOAqDyMWvr65JZxoIBxbV GpyZL4sM8rPnXjyluxWm5D13B0NTcNz4klIr1E3gjmmnd7mhrAPcGyuSsgPV9bg8wWzK 3ccp7fb8Kf4A7xhrpvyqqHSqaW51P5zWanzscG9yUp+3OqkBZagDP4IdECZDjq8Xjbz/ yllA== X-Gm-Message-State: AJcUukdkrkdvK6UgkjRQNdujrZuQIiWDiG5Jywh1f1tlp765yhp/KJTp mv6GV+c7sZHd9R9kmPNKnBMN7lOC X-Google-Smtp-Source: ALg8bN5kVCPjzIkVCDt9Hh20Az8wpKMw9u4zQ16aa+JdcR317g3abPwZD4CarltUvvST2ax3x1vdjg== X-Received: by 2002:adf:8484:: with SMTP id 4mr4320318wrg.249.1548277168530; Wed, 23 Jan 2019 12:59:28 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:28 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 06/16] sequencer: refactor check_todo_list() to work on a todo_list Date: Wed, 23 Jan 2019 21:58:11 +0100 Message-Id: <20190123205821.27459-7-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This refactors check_todo_list() to work on a todo_list to avoid redundant reads and writes to the disk. The function is renamed todo_list_check(). The parsing of the two todo lists is left to the caller. As rebase -p still need to check the todo list from the disk, a new function is introduced, check_todo_list_from_file(). It reads the file from the disk, parses it, pass the todo_list to todo_list_check(), and writes it back to the disk. As get_missing_commit_check_level() and the enum missing_commit_check_level are no longer needed inside of sequencer.c, they are moved to rebase-interactive.c, and made static again. Signed-off-by: Alban Gruin --- Squashed from Ramsay Jones. builtin/rebase--interactive.c | 2 +- rebase-interactive.c | 91 ++++++++++++++++++++++++- rebase-interactive.h | 2 + sequencer.c | 121 +++++++--------------------------- sequencer.h | 9 +-- 5 files changed, 117 insertions(+), 108 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 0898eb4c59..df19ccaeb9 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -256,7 +256,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = transform_todo_file(the_repository, flags); break; case CHECK_TODO_LIST: - ret = check_todo_list(the_repository); + ret = check_todo_list_from_file(the_repository); break; case REARRANGE_SQUASH: ret = rearrange_squash(the_repository); diff --git a/rebase-interactive.c b/rebase-interactive.c index 842fa07e7e..dfa6dd530f 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -1,8 +1,32 @@ #include "cache.h" #include "commit.h" -#include "rebase-interactive.h" #include "sequencer.h" +#include "rebase-interactive.h" #include "strbuf.h" +#include "commit-slab.h" +#include "config.h" + +enum missing_commit_check_level { + MISSING_COMMIT_CHECK_IGNORE = 0, + MISSING_COMMIT_CHECK_WARN, + MISSING_COMMIT_CHECK_ERROR +}; + +static enum missing_commit_check_level get_missing_commit_check_level(void) +{ + const char *value; + + if (git_config_get_value("rebase.missingcommitscheck", &value) || + !strcasecmp("ignore", value)) + return MISSING_COMMIT_CHECK_IGNORE; + if (!strcasecmp("warn", value)) + return MISSING_COMMIT_CHECK_WARN; + if (!strcasecmp("error", value)) + return MISSING_COMMIT_CHECK_ERROR; + warning(_("unrecognized setting %s for option " + "rebase.missingCommitsCheck. Ignoring."), value); + return MISSING_COMMIT_CHECK_IGNORE; +} void append_todo_help(unsigned edit_todo, unsigned keep_empty, struct strbuf *buf) @@ -89,3 +113,68 @@ int edit_todo_list(struct repository *r, unsigned flags) return 0; } + +define_commit_slab(commit_seen, unsigned char); +/* + * Check if the user dropped some commits by mistake + * Behaviour determined by rebase.missingCommitsCheck. + * Check if there is an unrecognized command or a + * bad SHA-1 in a command. + */ +int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo) +{ + enum missing_commit_check_level check_level = get_missing_commit_check_level(); + struct strbuf missing = STRBUF_INIT; + int res = 0, i; + struct commit_seen commit_seen; + + init_commit_seen(&commit_seen); + + if (check_level == MISSING_COMMIT_CHECK_IGNORE) + goto leave_check; + + /* Mark the commits in git-rebase-todo as seen */ + for (i = 0; i < new_todo->nr; i++) { + struct commit *commit = new_todo->items[i].commit; + if (commit) + *commit_seen_at(&commit_seen, commit) = 1; + } + + /* Find commits in git-rebase-todo.backup yet unseen */ + for (i = old_todo->nr - 1; i >= 0; i--) { + struct todo_item *item = old_todo->items + i; + struct commit *commit = item->commit; + if (commit && !*commit_seen_at(&commit_seen, commit)) { + strbuf_addf(&missing, " - %s %.*s\n", + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), + item->arg_len, + todo_item_get_arg(old_todo, item)); + *commit_seen_at(&commit_seen, commit) = 1; + } + } + + /* Warn about missing commits */ + if (!missing.len) + goto leave_check; + + if (check_level == MISSING_COMMIT_CHECK_ERROR) + res = 1; + + fprintf(stderr, + _("Warning: some commits may have been dropped accidentally.\n" + "Dropped commits (newer to older):\n")); + + /* Make the list user-friendly and display */ + fputs(missing.buf, stderr); + strbuf_release(&missing); + + fprintf(stderr, _("To avoid this message, use \"drop\" to " + "explicitly remove a commit.\n\n" + "Use 'git config rebase.missingCommitsCheck' to change " + "the level of warnings.\n" + "The possible behaviours are: ignore, warn, error.\n\n")); + +leave_check: + clear_commit_seen(&commit_seen); + return res; +} diff --git a/rebase-interactive.h b/rebase-interactive.h index 17b6c9f6d0..187b5032d6 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -3,9 +3,11 @@ struct strbuf; struct repository; +struct todo_list; void append_todo_help(unsigned edit_todo, unsigned keep_empty, struct strbuf *buf); int edit_todo_list(struct repository *r, unsigned flags); +int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); #endif diff --git a/sequencer.c b/sequencer.c index 87b43994ff..266f80d704 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4605,112 +4605,37 @@ int transform_todo_file(struct repository *r, unsigned flags) return 0; } -enum missing_commit_check_level get_missing_commit_check_level(void) -{ - const char *value; - - if (git_config_get_value("rebase.missingcommitscheck", &value) || - !strcasecmp("ignore", value)) - return MISSING_COMMIT_CHECK_IGNORE; - if (!strcasecmp("warn", value)) - return MISSING_COMMIT_CHECK_WARN; - if (!strcasecmp("error", value)) - return MISSING_COMMIT_CHECK_ERROR; - warning(_("unrecognized setting %s for option " - "rebase.missingCommitsCheck. Ignoring."), value); - return MISSING_COMMIT_CHECK_IGNORE; -} +static const char edit_todo_list_advice[] = +N_("You can fix this with 'git rebase --edit-todo' " +"and then run 'git rebase --continue'.\n" +"Or you can abort the rebase with 'git rebase" +" --abort'.\n"); -define_commit_slab(commit_seen, unsigned char); -/* - * Check if the user dropped some commits by mistake - * Behaviour determined by rebase.missingCommitsCheck. - * Check if there is an unrecognized command or a - * bad SHA-1 in a command. - */ -int check_todo_list(struct repository *r) +int check_todo_list_from_file(struct repository *r) { - enum missing_commit_check_level check_level = get_missing_commit_check_level(); - struct strbuf todo_file = STRBUF_INIT; - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf missing = STRBUF_INIT; - int advise_to_edit_todo = 0, res = 0, i; - struct commit_seen commit_seen; - - init_commit_seen(&commit_seen); + struct todo_list old_todo = TODO_LIST_INIT, new_todo = TODO_LIST_INIT; + int res = 0; - strbuf_addstr(&todo_file, rebase_path_todo()); - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file.buf) < 0) { + if (strbuf_read_file_or_whine(&new_todo.buf, rebase_path_todo()) < 0) { res = -1; - goto leave_check; - } - advise_to_edit_todo = res = - todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - - if (res || check_level == MISSING_COMMIT_CHECK_IGNORE) - goto leave_check; - - /* Mark the commits in git-rebase-todo as seen */ - for (i = 0; i < todo_list.nr; i++) { - struct commit *commit = todo_list.items[i].commit; - if (commit) - *commit_seen_at(&commit_seen, commit) = 1; + goto out; } - todo_list_release(&todo_list); - strbuf_addstr(&todo_file, ".backup"); - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file.buf) < 0) { + if (strbuf_read_file_or_whine(&old_todo.buf, rebase_path_todo_backup()) < 0) { res = -1; - goto leave_check; - } - strbuf_release(&todo_file); - res = !!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - - /* Find commits in git-rebase-todo.backup yet unseen */ - for (i = todo_list.nr - 1; i >= 0; i--) { - struct todo_item *item = todo_list.items + i; - struct commit *commit = item->commit; - if (commit && !*commit_seen_at(&commit_seen, commit)) { - strbuf_addf(&missing, " - %s %.*s\n", - short_commit_name(commit), - item->arg_len, - todo_item_get_arg(&todo_list, item)); - *commit_seen_at(&commit_seen, commit) = 1; - } + goto out; } - /* Warn about missing commits */ - if (!missing.len) - goto leave_check; - - if (check_level == MISSING_COMMIT_CHECK_ERROR) - advise_to_edit_todo = res = 1; - - fprintf(stderr, - _("Warning: some commits may have been dropped accidentally.\n" - "Dropped commits (newer to older):\n")); - - /* Make the list user-friendly and display */ - fputs(missing.buf, stderr); - strbuf_release(&missing); - - fprintf(stderr, _("To avoid this message, use \"drop\" to " - "explicitly remove a commit.\n\n" - "Use 'git config rebase.missingCommitsCheck' to change " - "the level of warnings.\n" - "The possible behaviours are: ignore, warn, error.\n\n")); - -leave_check: - clear_commit_seen(&commit_seen); - strbuf_release(&todo_file); - todo_list_release(&todo_list); - - if (advise_to_edit_todo) - fprintf(stderr, - _("You can fix this with 'git rebase --edit-todo' " - "and then run 'git rebase --continue'.\n" - "Or you can abort the rebase with 'git rebase" - " --abort'.\n")); + res = todo_list_parse_insn_buffer(r, old_todo.buf.buf, &old_todo); + if (!res) + res = todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo); + if (!res) + res = todo_list_check(&old_todo, &new_todo); + if (res) + fprintf(stderr, _(edit_todo_list_advice)); +out: + todo_list_release(&old_todo); + todo_list_release(&new_todo); return res; } @@ -4888,7 +4813,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla todo_list_release(&todo_list); - if (check_todo_list(r)) { + if (check_todo_list_from_file(r)) { checkout_onto(opts, onto_name, onto, orig_head); return -1; } diff --git a/sequencer.h b/sequencer.h index dc3d8f76f7..1de97f188d 100644 --- a/sequencer.h +++ b/sequencer.h @@ -64,12 +64,6 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } -enum missing_commit_check_level { - MISSING_COMMIT_CHECK_IGNORE = 0, - MISSING_COMMIT_CHECK_WARN, - MISSING_COMMIT_CHECK_ERROR -}; - int write_message(const void *buf, size_t len, const char *filename, int append_eol); @@ -154,8 +148,7 @@ int sequencer_make_script(struct repository *r, FILE *out, int argc, int sequencer_add_exec_commands(struct repository *r, const char *command); int transform_todo_file(struct repository *r, unsigned flags); -enum missing_commit_check_level get_missing_commit_check_level(void); -int check_todo_list(struct repository *r); +int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, const char *cmd, From patchwork Wed Jan 23 20:58:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777855 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 3A7A113BF for ; Wed, 23 Jan 2019 20:59:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A3AC2DB0F for ; Wed, 23 Jan 2019 20:59:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E2872DB77; Wed, 23 Jan 2019 20:59:36 +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 2682B2DB0F for ; Wed, 23 Jan 2019 20:59:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726986AbfAWU7d (ORCPT ); Wed, 23 Jan 2019 15:59:33 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:56220 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbfAWU7d (ORCPT ); Wed, 23 Jan 2019 15:59:33 -0500 Received: by mail-wm1-f65.google.com with SMTP id y139so829903wmc.5 for ; Wed, 23 Jan 2019 12:59:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vzr7ST56bOP15P0z41IKsg4EpM7opq6/Vf+ElCBUxbQ=; b=PmxwqmbKi91Umf6WfHcTeOCZYyMcoKwgbp9BZwEE4s214HXyOJSg8cB3NmWOOn0l0Z QJqPtxUH69yRX/Tk7r0naRzmghS+pNVBYxz76b1F6q+7MFE3sA8YCM6OfZvUH7dds+WE IyHIvkjaA3PZX4HkgIgdV/0KIBhxsJ98iZ6Rx67oB1z9NOjb18G8pHaLgMwyxp5wL8/Y RxlrotIMxpcLndtTyHUYFN4RNuDCxx3nmlM7f86WIVnVgLBBBo3iHkB5CY38L5DKS2BU 4d5hQHpjC395pxox9JyGcTiW93+MSf4cyxJVEoC5DTUg3tG0Z+Sn2jLi6ot28cif/q0u L5ZQ== 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=vzr7ST56bOP15P0z41IKsg4EpM7opq6/Vf+ElCBUxbQ=; b=WPXIiqIOqWSLjTsZYuyi1/rVXSwL7J8IJSNEJCgb89PLRMUuELZoo6crpaKeleUnZk Brq1Qc4D3Sf6H/FGpvGAQEYl/R0E4sBfPwDr9tSP3wYWfL85L1yaqi8TzfHVYTnFWAw1 aw0oSCPfOgU7bmcylB0gy7vd5A8F8VepOxh0SuWy984AeRcLQclKhcb1h+EAdZwop/1U /UI3/3mkLC7VdV4/Fux4WTNVeMPEeEJgXJ95xJITmRzrqKM3hbo6VlqHgjve+sOIHjcn k0RQhbZ+xP5IHMGzd2NW+FL3Gj1AQ5dG7y2Bid7hkCXNyC9UwfUN5I8GoTP3Vew2bI+q iSXQ== X-Gm-Message-State: AJcUukcgMKiTJBqC7KaotqPbulVvuMu/Ixz28hruYQZhv9tUlzrnNvLA q38zZK351pw0QGN/Bfplz9Jlv1Fl X-Google-Smtp-Source: ALg8bN5TrGFfN7cft5nuy4t1cw9dofFvexM/hvB1aKlGMnoN7mbBkZ7rlsiZRcGVBiOCwd676KLKpw== X-Received: by 2002:a1c:2457:: with SMTP id k84mr4149688wmk.139.1548277170194; Wed, 23 Jan 2019 12:59:30 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:29 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 07/16] sequencer: refactor sequencer_add_exec_commands() to work on a todo_list Date: Wed, 23 Jan 2019 21:58:12 +0100 Message-Id: <20190123205821.27459-8-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This refactors sequencer_add_exec_commands() to work on a todo_list to avoid redundant reads and writes to the disk. Instead of inserting the `exec' commands between the other commands and re-parsing the buffer at the end, they are appended to the buffer once, and a new list of items is created. Items from the old list are copied across and new `exec' items are appended when necessary. This eliminates the need to reparse the buffer, but this also means we have to use todo_list_write_to_disk() to write the file. todo_list_add_exec_commands() and sequencer_add_exec_commands() are modified to take a string list instead of a string -- one item for each command. This makes it easier to insert a new command to the todo list for each command to execute. sequencer_add_exec_commands() still reads the todo list from the disk, as it is needed by rebase -p. complete_action() still uses sequencer_add_exec_commands() for now. This will be changed in a future commit. Signed-off-by: Alban Gruin --- Unchanged since v4. builtin/rebase--interactive.c | 15 +++-- sequencer.c | 110 +++++++++++++++++++++------------- sequencer.h | 5 +- 3 files changed, 82 insertions(+), 48 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index df19ccaeb9..53056ee713 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -65,7 +65,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *onto, const char *onto_name, const char *squash_onto, const char *head_name, const char *restrict_revision, char *raw_strategies, - const char *cmd, unsigned autosquash) + struct string_list *commands, unsigned autosquash) { int ret; const char *head_hash = NULL; @@ -116,7 +116,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, discard_cache(); ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name, onto, - head_hash, cmd, autosquash); + head_hash, commands, autosquash); } free(revisions); @@ -139,6 +139,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) const char *onto = NULL, *onto_name = NULL, *restrict_revision = NULL, *squash_onto = NULL, *upstream = NULL, *head_name = NULL, *switch_to = NULL, *cmd = NULL; + struct string_list commands = STRING_LIST_INIT_DUP; char *raw_strategies = NULL; enum { NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH, @@ -221,6 +222,12 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) warning(_("--[no-]rebase-cousins has no effect without " "--rebase-merges")); + if (cmd && *cmd) { + string_list_split(&commands, cmd, '\n', -1); + if (strlen(commands.items[commands.nr - 1].string) == 0) + --commands.nr; + } + switch (command) { case NONE: if (!onto && !upstream) @@ -228,7 +235,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto, onto_name, squash_onto, head_name, restrict_revision, - raw_strategies, cmd, autosquash); + raw_strategies, &commands, autosquash); break; case SKIP: { struct string_list merge_rr = STRING_LIST_INIT_DUP; @@ -262,7 +269,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = rearrange_squash(the_repository); break; case ADD_EXEC: - ret = sequencer_add_exec_commands(the_repository, cmd); + ret = sequencer_add_exec_commands(the_repository, &commands); break; default: BUG("invalid command '%d'", command); diff --git a/sequencer.c b/sequencer.c index 266f80d704..3a90b419d7 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4446,25 +4446,27 @@ int sequencer_make_script(struct repository *r, FILE *out, return 0; } -/* - * Add commands after pick and (series of) squash/fixup commands - * in the todo list. - */ -int sequencer_add_exec_commands(struct repository *r, - const char *commands) +static void todo_list_add_exec_commands(struct todo_list *todo_list, + struct string_list *commands) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf *buf = &todo_list.buf; - size_t offset = 0, commands_len = strlen(commands); - int i, insert; + struct strbuf *buf = &todo_list->buf; + size_t base_offset = buf->len; + int i, insert, nr = 0, alloc = 0; + struct todo_item *items = NULL, *base_items = NULL; - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error(_("could not read '%s'."), todo_file); + base_items = xcalloc(commands->nr, sizeof(struct todo_item)); + for (i = 0; i < commands->nr; ++i) { + size_t command_len = strlen(commands->items[i].string); - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); + strbuf_addstr(buf, commands->items[i].string); + strbuf_addch(buf, '\n'); + + base_items[i].command = TODO_EXEC; + base_items[i].offset_in_buf = base_offset; + base_items[i].arg_offset = base_offset + strlen("exec "); + base_items[i].arg_len = command_len - strlen("exec "); + + base_offset += command_len + 1; } /* @@ -4473,38 +4475,62 @@ int sequencer_add_exec_commands(struct repository *r, * those chains if there are any. */ insert = -1; - for (i = 0; i < todo_list.nr; i++) { - enum todo_command command = todo_list.items[i].command; - - if (insert >= 0) { - /* skip fixup/squash chains */ - if (command == TODO_COMMENT) - continue; - else if (is_fixup(command)) { - insert = i + 1; - continue; - } - strbuf_insert(buf, - todo_list.items[insert].offset_in_buf + - offset, commands, commands_len); - offset += commands_len; + for (i = 0; i < todo_list->nr; i++) { + enum todo_command command = todo_list->items[i].command; + if (insert >= 0 && command != TODO_COMMENT && !is_fixup(command)) { + ALLOC_GROW(items, nr + commands->nr, alloc); + COPY_ARRAY(items + nr, base_items, commands->nr); + nr += commands->nr; insert = -1; } - if (command == TODO_PICK || command == TODO_MERGE) + ALLOC_GROW(items, nr + 1, alloc); + items[nr++] = todo_list->items[i]; + + if (command == TODO_PICK || command == TODO_MERGE || is_fixup(command)) insert = i + 1; } /* insert or append final */ - if (insert >= 0 && insert < todo_list.nr) - strbuf_insert(buf, todo_list.items[insert].offset_in_buf + - offset, commands, commands_len); - else if (insert >= 0 || !offset) - strbuf_add(buf, commands, commands_len); + if (insert >= 0 || nr == todo_list->nr) { + ALLOC_GROW(items, nr + commands->nr, alloc); + COPY_ARRAY(items + nr, base_items, commands->nr); + nr += commands->nr; + } + + free(base_items); + FREE_AND_NULL(todo_list->items); + todo_list->items = items; + todo_list->nr = nr; + todo_list->alloc = alloc; +} - i = write_message(buf->buf, buf->len, todo_file, 0); +/* + * Add commands after pick and (series of) squash/fixup commands + * in the todo list. + */ +int sequencer_add_exec_commands(struct repository *r, + struct string_list *commands) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res; + + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) + return error_errno(_("could not read '%s'."), todo_file); + + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + todo_list_add_exec_commands(&todo_list, commands); + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); todo_list_release(&todo_list); - return i; + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list, @@ -4735,7 +4761,7 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - const char *onto, const char *orig_head, const char *cmd, + const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash) { const char *shortonto, *todo_file = rebase_path_todo(); @@ -4754,8 +4780,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla if (autosquash && rearrange_squash(r)) return -1; - if (cmd && *cmd) - sequencer_add_exec_commands(r, cmd); + if (commands->nr) + sequencer_add_exec_commands(r, commands); if (strbuf_read_file(buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); diff --git a/sequencer.h b/sequencer.h index 1de97f188d..e79f03e213 100644 --- a/sequencer.h +++ b/sequencer.h @@ -146,12 +146,13 @@ int sequencer_make_script(struct repository *r, FILE *out, int argc, const char **argv, unsigned flags); -int sequencer_add_exec_commands(struct repository *r, const char *command); +int sequencer_add_exec_commands(struct repository *r, + struct string_list *commands); int transform_todo_file(struct repository *r, unsigned flags); int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, - const char *onto, const char *orig_head, const char *cmd, + const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash); int rearrange_squash(struct repository *r); From patchwork Wed Jan 23 20:58:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777857 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 8F75A13BF for ; Wed, 23 Jan 2019 20:59:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F32B2DB54 for ; Wed, 23 Jan 2019 20:59:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 730292DB77; Wed, 23 Jan 2019 20:59:38 +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 CF0FB2DB54 for ; Wed, 23 Jan 2019 20:59:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbfAWU7g (ORCPT ); Wed, 23 Jan 2019 15:59:36 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51129 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbfAWU7e (ORCPT ); Wed, 23 Jan 2019 15:59:34 -0500 Received: by mail-wm1-f68.google.com with SMTP id n190so873692wmd.0 for ; Wed, 23 Jan 2019 12:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ec+4XY7X6i30+0/IQAiO1Pthz6dwVBzHaW22a8WH2Jg=; b=s/MKWltUzWgrzJj1G3/AS3yeBUY5Ekq436oIaVFiDzNIllHCyc4KojRjOd2/2CUD+u WnLQ8PJfuzAFBErOYEU55xQrax/IfgzfhbKWQNvlNJzSdMap7GtuEmoGNMXsvTaE8pRQ p8p4akeSpWL9x7876VtiJ62XqvHzZwUEoBgv5IRsaU9bo7yoOvnx0zPJduqeSEqjyrj8 HREmoux4sxd1UWX1tK8QT9YK9RBqn9rbFUV+ezhYkEJWpkRS4xDkszmHsnYvVb9wIahw M9Fl9d5lxOTa0WAUJIfpGEFIYHRrgUe5I153jX4iOLDfz7Up0ONhAw5k1VVQ0d7GfY+Q LjNw== 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=ec+4XY7X6i30+0/IQAiO1Pthz6dwVBzHaW22a8WH2Jg=; b=n+UWPaBqWtL5pGwfVFo7JguWHMZiQBWV1Mp+W1HsJl9IArbMYkouOcLbVBdE9CnB2P qemLNv9mWPgAl8quRRfP1IC2kvd/MWOZltj1BVtHdcPB1b1o9QFXYSHWoJ8RlxkuCZKL iqVGhsLgr1+IGoxQe+hwDp2uAEBx9hRj+P7fuC2L1Oa7gs9RkSf7J7uUu/DmA5ecX8vZ tmeyPXRJcNa881JUVANd3DcDkNpp1U3z8tSQmzGW7mJ+0iJhS0flRBuScj2z5ZltAD6+ pUV5gk8zVJaaQIAKyWy0MUlsjkFNE+Y/miUs1admIfcUALgVjGVXu8nivAq5uakp3CP8 ovFg== X-Gm-Message-State: AJcUukd+5BeO670bI+ycRPaeyA88UqHSHrSyBmzaOlNneviJhw09ZPbG PeK6cUj8wUR1twldrci9fgY3VtRr X-Google-Smtp-Source: ALg8bN4WppVbC/AfgvlqOj1hLzF8Uc4m5TG6GwK1qQJxiGQ8HecJSf03uYaghQmaAkX9SvVrI8813A== X-Received: by 2002:a1c:b456:: with SMTP id d83mr4339705wmf.115.1548277171872; Wed, 23 Jan 2019 12:59:31 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:31 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 08/16] sequencer: refactor rearrange_squash() to work on a todo_list Date: Wed, 23 Jan 2019 21:58:13 +0100 Message-Id: <20190123205821.27459-9-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This refactors rearrange_squash() to work on a todo_list to avoid redundant reads and writes. The function is renamed todo_list_rearrange_squash(). The old version created a new buffer, which was directly written to the disk. This new version creates a new item list by just copying items from the old item list, without creating a new buffer. This eliminates the need to reparse the todo list, but this also means its buffer cannot be directly written to the disk. As rebase -p still need to check the todo list from the disk, a new function is introduced, rearrange_squash_in_todo_file(). complete_action() still uses rearrange_squash_in_todo_file() for now. This will be changed in a future commit. Signed-off-by: Alban Gruin --- Unchanged since v4. builtin/rebase--interactive.c | 2 +- sequencer.c | 92 ++++++++++++++++++----------------- sequencer.h | 2 +- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 53056ee713..4f0eae9239 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -266,7 +266,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) ret = check_todo_list_from_file(the_repository); break; case REARRANGE_SQUASH: - ret = rearrange_squash(the_repository); + ret = rearrange_squash_in_todo_file(the_repository); break; case ADD_EXEC: ret = sequencer_add_exec_commands(the_repository, &commands); diff --git a/sequencer.c b/sequencer.c index 3a90b419d7..11456be5cc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4777,7 +4777,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla write_message("noop\n", 5, todo_file, 0)) return -1; - if (autosquash && rearrange_squash(r)) + if (autosquash && rearrange_squash_in_todo_file(r)) return -1; if (commands->nr) @@ -4883,21 +4883,13 @@ define_commit_slab(commit_todo_item, struct todo_item *); * message will have to be retrieved from the commit (as the oneline in the * script cannot be trusted) in order to normalize the autosquash arrangement. */ -int rearrange_squash(struct repository *r) +static int todo_list_rearrange_squash(struct todo_list *todo_list) { - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; struct hashmap subject2item; - int res = 0, rearranged = 0, *next, *tail, i; + int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0; char **subjects; struct commit_todo_item commit_todo; - - if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) - return -1; - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { - todo_list_release(&todo_list); - return -1; - } + struct todo_item *items = NULL; init_commit_todo_item(&commit_todo); /* @@ -4910,13 +4902,13 @@ int rearrange_squash(struct repository *r) * be moved to appear after the i'th. */ hashmap_init(&subject2item, (hashmap_cmp_fn) subject2item_cmp, - NULL, todo_list.nr); - ALLOC_ARRAY(next, todo_list.nr); - ALLOC_ARRAY(tail, todo_list.nr); - ALLOC_ARRAY(subjects, todo_list.nr); - for (i = 0; i < todo_list.nr; i++) { + NULL, todo_list->nr); + ALLOC_ARRAY(next, todo_list->nr); + ALLOC_ARRAY(tail, todo_list->nr); + ALLOC_ARRAY(subjects, todo_list->nr); + for (i = 0; i < todo_list->nr; i++) { struct strbuf buf = STRBUF_INIT; - struct todo_item *item = todo_list.items + i; + struct todo_item *item = todo_list->items + i; const char *commit_buffer, *subject, *p; size_t subject_len; int i2 = -1; @@ -4929,7 +4921,6 @@ int rearrange_squash(struct repository *r) } if (is_fixup(item->command)) { - todo_list_release(&todo_list); clear_commit_todo_item(&commit_todo); return error(_("the script was already rearranged.")); } @@ -4964,7 +4955,7 @@ int rearrange_squash(struct repository *r) *commit_todo_item_at(&commit_todo, commit2)) /* found by commit name */ i2 = *commit_todo_item_at(&commit_todo, commit2) - - todo_list.items; + - todo_list->items; else { /* copy can be a prefix of the commit subject */ for (i2 = 0; i2 < i; i2++) @@ -4977,7 +4968,7 @@ int rearrange_squash(struct repository *r) } if (i2 >= 0) { rearranged = 1; - todo_list.items[i].command = + todo_list->items[i].command = starts_with(subject, "fixup!") ? TODO_FIXUP : TODO_SQUASH; if (next[i2] < 0) @@ -4995,10 +4986,8 @@ int rearrange_squash(struct repository *r) } if (rearranged) { - struct strbuf buf = STRBUF_INIT; - - for (i = 0; i < todo_list.nr; i++) { - enum todo_command command = todo_list.items[i].command; + for (i = 0; i < todo_list->nr; i++) { + enum todo_command command = todo_list->items[i].command; int cur = i; /* @@ -5009,37 +4998,50 @@ int rearrange_squash(struct repository *r) continue; while (cur >= 0) { - const char *bol = - get_item_line(&todo_list, cur); - const char *eol = - get_item_line(&todo_list, cur + 1); - - /* replace 'pick', by 'fixup' or 'squash' */ - command = todo_list.items[cur].command; - if (is_fixup(command)) { - strbuf_addstr(&buf, - todo_command_info[command].str); - bol += strcspn(bol, " \t"); - } - - strbuf_add(&buf, bol, eol - bol); - + ALLOC_GROW(items, nr + 1, alloc); + items[nr++] = todo_list->items[cur]; cur = next[cur]; } } - res = rewrite_file(todo_file, buf.buf, buf.len); - strbuf_release(&buf); + FREE_AND_NULL(todo_list->items); + todo_list->items = items; + todo_list->nr = nr; + todo_list->alloc = alloc; } free(next); free(tail); - for (i = 0; i < todo_list.nr; i++) + for (i = 0; i < todo_list->nr; i++) free(subjects[i]); free(subjects); hashmap_free(&subject2item, 1); - todo_list_release(&todo_list); clear_commit_todo_item(&commit_todo); - return res; + + return 0; +} + +int rearrange_squash_in_todo_file(struct repository *r) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res = 0; + + if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) + return -1; + if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list) < 0) { + todo_list_release(&todo_list); + return -1; + } + + res = todo_list_rearrange_squash(&todo_list); + if (!res) + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, 0); + + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; } diff --git a/sequencer.h b/sequencer.h index e79f03e213..c7bb38d6df 100644 --- a/sequencer.h +++ b/sequencer.h @@ -154,7 +154,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, unsigned autosquash); -int rearrange_squash(struct repository *r); +int rearrange_squash_in_todo_file(struct repository *r); extern const char sign_off_header[]; From patchwork Wed Jan 23 20:58:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777863 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 6D274746 for ; Wed, 23 Jan 2019 20:59:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D8602DB54 for ; Wed, 23 Jan 2019 20:59:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51AA82DB77; Wed, 23 Jan 2019 20:59:43 +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 B567E2DB54 for ; Wed, 23 Jan 2019 20:59:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727004AbfAWU7j (ORCPT ); Wed, 23 Jan 2019 15:59:39 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36467 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbfAWU7g (ORCPT ); Wed, 23 Jan 2019 15:59:36 -0500 Received: by mail-wr1-f66.google.com with SMTP id u4so4140902wrp.3 for ; Wed, 23 Jan 2019 12:59:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FjxVxcscXnuEiMjkYfAJSWH+K427KDcc5uPRkdnpPok=; b=r5bwu94WyVSFXFNSOKi4C9CMBE0eq6xdAmPOB3/JJVI+yzGsqN6cTg5jF/2isAub8b +rIBmNAVVUWayaM/wcbLmd0fSk0AQJeCUuer/Q+n7lczyuWxmAinumDIrvicTs31dTq+ DuFyV20TmDwhxyfBBbjUXws7NwGaEk1hBI/DxzIH4myuVzfW/s1X2v5XIQqZybVpNI57 Pgy9obl1eTUii05zg0qvvKOd5/+jThHnueymPqcMt8xTIogAOo6y/7v+6cOC+hsB8V2s OBdAo66oB22bMvJRtf/2TyCIuC+PT0TSHuDhhriCrRTjjue6ulpvNNq2mJzCZCxatDlm nu+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FjxVxcscXnuEiMjkYfAJSWH+K427KDcc5uPRkdnpPok=; b=Iu+EElYdPtTOmqY4QERBO+zJue50LoaABTY73dvVcZuIC5c7NJLPZ+2JZjZ0Tmbtfr G8+y2VOG4oswB1yg7ylGhA82g60ayFbp1a2LhRdP5UMLlCm/F9SRw9aPv6D/iGExA4xq I8BFxm/KPtw9csakAqwJn40atQf3ua4bFnX0HxLGPH+bV1+0Dk9UM1dMZhUD8258tmsg 6S+2shHHHXqSiBRkUjcx8Q++hhdATb6fXGgvLAefrogmAcRtwkF3Km0Uc7TGqoZUJDYX 97PSNXA6YOFtxKizY7OXzft5mhylL/+DmZcurvcYabcUeOgxN9ip37hIJgHVKKzCcouy m4kQ== X-Gm-Message-State: AJcUukefkhVwr+JOY5XN86DlMqiZU43Lrhteigvb17uZ5uO50dDPs8iE cNv94voeRAh/jAxMBuI4dIF2Zl6P X-Google-Smtp-Source: ALg8bN44MQ4yUJJUP+L6EfToGXue9NQyWoKAjWE+YDe8UCojM7Zzw2omf3U9UL2qsLKVuSXeJve/oA== X-Received: by 2002:a5d:64c7:: with SMTP id y7mr4252213wrv.207.1548277173517; Wed, 23 Jan 2019 12:59:33 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:33 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 09/16] sequencer: make sequencer_make_script() write its script to a strbuf Date: Wed, 23 Jan 2019 21:58:14 +0100 Message-Id: <20190123205821.27459-10-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-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 --- Unchanged since v4. builtin/rebase--interactive.c | 13 ++++++----- sequencer.c | 41 +++++++++++++++-------------------- sequencer.h | 5 ++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 4f0eae9239..92026739c9 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -71,7 +71,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *head_hash = NULL; char *revisions = NULL, *shortrevisions = NULL; struct argv_array make_script_args = ARGV_ARRAY_INIT; - FILE *todo_list; + FILE *todo_list_file; + struct todo_list todo_list = TODO_LIST_INIT; if (prepare_branch_to_be_rebased(opts, switch_to)) return -1; @@ -93,8 +94,8 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, if (!upstream && squash_onto) write_file(path_squash_onto(), "%s\n", squash_onto); - todo_list = fopen(rebase_path_todo(), "w"); - if (!todo_list) { + todo_list_file = fopen(rebase_path_todo(), "w"); + if (!todo_list_file) { free(revisions); free(shortrevisions); @@ -105,10 +106,11 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, if (restrict_revision) argv_array_push(&make_script_args, restrict_revision); - ret = sequencer_make_script(the_repository, todo_list, + ret = sequencer_make_script(the_repository, &todo_list.buf, make_script_args.argc, make_script_args.argv, flags); - fclose(todo_list); + fputs(todo_list.buf.buf, todo_list_file); + fclose(todo_list_file); if (ret) error(_("could not generate todo list")); @@ -121,6 +123,7 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, free(revisions); free(shortrevisions); + todo_list_release(&todo_list); argv_array_clear(&make_script_args); return ret; diff --git a/sequencer.c b/sequencer.c index 11456be5cc..f1c62c5960 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4160,7 +4160,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; @@ -4305,7 +4305,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; @@ -4315,9 +4315,9 @@ static int make_script_with_merges(struct pretty_print_context *pp, entry = oidmap_get(&state.commit2label, &commit->object.oid); if (entry) - fprintf(out, "\n%c Branch %s\n", comment_line_char, entry->string); + strbuf_addf(out, "\n%c Branch %s\n", comment_line_char, entry->string); else - fprintf(out, "\n"); + strbuf_addch(out, '\n'); while (oidset_contains(&interesting, &commit->object.oid) && !oidset_contains(&shown, &commit->object.oid)) { @@ -4330,8 +4330,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; @@ -4344,12 +4344,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); } } @@ -4358,11 +4358,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); } @@ -4384,13 +4384,11 @@ static int make_script_with_merges(struct pretty_print_context *pp, return 0; } -int sequencer_make_script(struct repository *r, FILE *out, - int argc, const char **argv, - unsigned flags) +int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, + const char **argv, unsigned flags) { char *format = NULL; struct pretty_print_context pp = {0}; - struct strbuf buf = STRBUF_INIT; struct rev_info revs; struct commit *commit; int keep_empty = flags & TODO_LIST_KEEP_EMPTY; @@ -4433,16 +4431,13 @@ int sequencer_make_script(struct repository *r, FILE *out, if (!is_empty && (commit->object.flags & PATCHSAME)) continue; - strbuf_reset(&buf); if (!keep_empty && is_empty) - strbuf_addf(&buf, "%c ", comment_line_char); - strbuf_addf(&buf, "%s %s ", insn, + strbuf_addf(out, "%c ", comment_line_char); + strbuf_addf(out, "%s %s ", insn, oid_to_hex(&commit->object.oid)); - pretty_print_commit(&pp, commit, &buf); - strbuf_addch(&buf, '\n'); - fputs(buf.buf, out); + pretty_print_commit(&pp, commit, out); + strbuf_addch(out, '\n'); } - strbuf_release(&buf); return 0; } diff --git a/sequencer.h b/sequencer.h index c7bb38d6df..9b8edd7df6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -142,9 +142,8 @@ int sequencer_remove_state(struct replay_opts *opts); #define TODO_LIST_REBASE_COUSINS (1U << 4) #define TODO_LIST_APPEND_TODO_HELP (1U << 5) -int sequencer_make_script(struct repository *r, FILE *out, int argc, - const char **argv, - unsigned flags); +int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, + const char **argv, unsigned flags); int sequencer_add_exec_commands(struct repository *r, struct string_list *commands); From patchwork Wed Jan 23 20:58:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777859 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 10BCF746 for ; Wed, 23 Jan 2019 20:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000072DB54 for ; Wed, 23 Jan 2019 20:59:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E88122DB77; Wed, 23 Jan 2019 20:59:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DB012DB54 for ; Wed, 23 Jan 2019 20:59:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727055AbfAWU7j (ORCPT ); Wed, 23 Jan 2019 15:59:39 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:40940 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbfAWU7h (ORCPT ); Wed, 23 Jan 2019 15:59:37 -0500 Received: by mail-wr1-f65.google.com with SMTP id p4so4117695wrt.7 for ; Wed, 23 Jan 2019 12:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O99Hok6wiiMRqhJUu9u9IP6raI0hcWV93WLXLfcWTPU=; b=rqsD/ZW48HVJzgwFrFwE0liwR0zbAmkmPfc+QifCMXhaBQtME7MPNvAQoD1O4G7Ocm 0L/2L4WzksQ8NEBxiv1IlPxshjJLl661LZ1PraM7wxo1wAbkwVBlwN1lf/MZq1F3Qhmy fYjI1TqltlwQWuSNN0qe0q0CyVLQSR+bI0n2Mbcy8VCZMg+YH8tkftoaBg7fvmhtxl+L Kti4vcfurVoh9/AObo+SC09253mcqUvnX5kdTujDC3Bdzg7Tv/CSZa/Xed6mmg9Kg55o nvfJ9TCOzUVz6fBN8dzkH3/j42PZWvZOul2+7i817dLtrvoHyiudet1SzTdRatVLQw9k VQJg== 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=O99Hok6wiiMRqhJUu9u9IP6raI0hcWV93WLXLfcWTPU=; b=epbRKtZ/lqkaA6ufIHBH640fKEgPkBUIwOD3axqrsnYufrB910e7rRVTgLFLH+tYty aMLGn6rM+xBa+h2VBnAkskasd2J5dKD5rVDOEWQcz7WeDRG0kGNd1sC8K93qG9H8+KZQ e9L6YpNp3C0mXKYSPGwc0U0Q6NCghSqxMcU3BxJuiNdaGEIHaQNYvcqMFkHgWQR+WbVy PbsWnSmzRz+mczRDxgaQpOzoj6oR2xgDBK5zKCaPKqeUEUL7jyXDOkASU+35NNfzsMV+ He4SONInN8Umxk9OtawTWTLHYUPvKgMpl4GIS7BOzvot0xBwrWpQEPLsb2S5lorh48RR nu7g== X-Gm-Message-State: AJcUuke+mlxUAgVokKtwKrVt51BRPpBi8EyLpEQnL/98EEYvFfSgY94b t4wUwrMMmFhoHn5O8AhKLYc4LW8Q X-Google-Smtp-Source: ALg8bN6ZBstSKcyvZLT7FZookpYbVHZo6j8xWTgl+eVLQuKGHL7G+gircZLtW1O9uI48o489Qns7zA== X-Received: by 2002:adf:c888:: with SMTP id k8mr4577127wrh.6.1548277175219; Wed, 23 Jan 2019 12:59:35 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:34 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 10/16] sequencer: change complete_action() to use the refactored functions Date: Wed, 23 Jan 2019 21:58:15 +0100 Message-Id: <20190123205821.27459-11-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP complete_action() used functions that read the todo-list file, made some changes to it, and wrote it back to the disk. The previous commits were dedicated to separate the part that deals with the file from the actual logic of these functions. Now that this is done, we can call directly the "logic" functions to avoid useless file access. The parsing of the list has to be done by the caller. If the buffer of the todo list provided by the caller is empty, a `noop' command is directly added to the todo list, without touching the buffer. Signed-off-by: Alban Gruin --- Unchanged since v4. builtin/rebase--interactive.c | 20 +++------ sequencer.c | 81 +++++++++++++++-------------------- sequencer.h | 2 +- 3 files changed, 42 insertions(+), 61 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 92026739c9..2dbf8fc08b 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -71,7 +71,6 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, const char *head_hash = NULL; char *revisions = NULL, *shortrevisions = NULL; struct argv_array make_script_args = ARGV_ARRAY_INIT; - FILE *todo_list_file; struct todo_list todo_list = TODO_LIST_INIT; if (prepare_branch_to_be_rebased(opts, switch_to)) @@ -94,14 +93,6 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, if (!upstream && squash_onto) write_file(path_squash_onto(), "%s\n", squash_onto); - todo_list_file = fopen(rebase_path_todo(), "w"); - if (!todo_list_file) { - free(revisions); - free(shortrevisions); - - return error_errno(_("could not open %s"), rebase_path_todo()); - } - argv_array_pushl(&make_script_args, "", revisions, NULL); if (restrict_revision) argv_array_push(&make_script_args, restrict_revision); @@ -109,16 +100,17 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags, ret = sequencer_make_script(the_repository, &todo_list.buf, make_script_args.argc, make_script_args.argv, flags); - fputs(todo_list.buf.buf, todo_list_file); - fclose(todo_list_file); if (ret) error(_("could not generate todo list")); else { discard_cache(); - ret = complete_action(the_repository, opts, flags, - shortrevisions, onto_name, onto, - head_hash, commands, autosquash); + if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, + &todo_list)) + BUG("unusable todo list"); + + ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name, + onto, head_hash, commands, autosquash, &todo_list); } free(revisions); diff --git a/sequencer.c b/sequencer.c index f1c62c5960..2a43ca685b 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4754,100 +4754,89 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output return 0; } +static int todo_list_rearrange_squash(struct todo_list *todo_list); + int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, - unsigned autosquash) + unsigned autosquash, struct todo_list *todo_list) { const char *shortonto, *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - struct strbuf *buf = &(todo_list.buf); + struct todo_list new_todo = TODO_LIST_INIT; + struct strbuf *buf = &todo_list->buf; struct object_id oid; - struct stat st; get_oid(onto, &oid); shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); - if (!lstat(todo_file, &st) && st.st_size == 0 && - write_message("noop\n", 5, todo_file, 0)) - return -1; + if (buf->len == 0) { + struct todo_item *item = append_new_todo(todo_list); + item->command = TODO_NOOP; + item->commit = NULL; + item->arg_len = item->arg_offset = item->flags = item->offset_in_buf = 0; + } - if (autosquash && rearrange_squash_in_todo_file(r)) + if (autosquash && todo_list_rearrange_squash(todo_list)) return -1; if (commands->nr) - sequencer_add_exec_commands(r, commands); + todo_list_add_exec_commands(todo_list, commands); - if (strbuf_read_file(buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, buf->buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - if (count_commands(&todo_list) == 0) { + if (count_commands(todo_list) == 0) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); return error(_("nothing to do")); } - strbuf_addch(buf, '\n'); - strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", - "Rebase %s onto %s (%d commands)", - count_commands(&todo_list)), - shortrevisions, shortonto, count_commands(&todo_list)); - append_todo_help(0, flags & TODO_LIST_KEEP_EMPTY, buf); - - if (write_message(buf->buf, buf->len, todo_file, 0)) { - todo_list_release(&todo_list); - return -1; - } + if (todo_list_write_to_file(r, todo_list, todo_file, + shortrevisions, shortonto, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) + return error_errno(_("could not write '%s'"), todo_file); if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) return error(_("could not copy '%s' to '%s'."), todo_file, rebase_path_todo_backup()); - if (transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS)) - return error(_("could not transform the todo list")); - - strbuf_reset(buf); - - if (launch_sequence_editor(todo_file, buf, NULL)) { + if (launch_sequence_editor(todo_file, &new_todo.buf, NULL)) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); return -1; } - strbuf_stripspace(buf, 1); - if (buf->len == 0) { + strbuf_stripspace(&new_todo.buf, 1); + if (new_todo.buf.len == 0) { apply_autostash(opts); sequencer_remove_state(opts); - todo_list_release(&todo_list); + todo_list_release(&new_todo); return error(_("nothing to do")); } - todo_list_release(&todo_list); - - if (check_todo_list_from_file(r)) { + if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) || + todo_list_check(todo_list, &new_todo)) { + fprintf(stderr, _(edit_todo_list_advice)); checkout_onto(opts, onto_name, onto, orig_head); + todo_list_release(&new_todo); + return -1; } - if (transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS))) - return error(_("could not transform the todo list")); + if (todo_list_write_to_file(r, &new_todo, todo_file, NULL, NULL, -1, + flags & ~(TODO_LIST_SHORTEN_IDS))) { + todo_list_release(&new_todo); + return error_errno(_("could not write '%s'"), todo_file); + } + + todo_list_release(&new_todo); if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) return error(_("could not skip unnecessary pick commands")); if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head)) return -1; -; + if (require_clean_work_tree(r, "rebase", "", 1, 1)) return -1; diff --git a/sequencer.h b/sequencer.h index 9b8edd7df6..0c30e43f0a 100644 --- a/sequencer.h +++ b/sequencer.h @@ -152,7 +152,7 @@ int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, struct string_list *commands, - unsigned autosquash); + unsigned autosquash, struct todo_list *todo_list); int rearrange_squash_in_todo_file(struct repository *r); extern const char sign_off_header[]; From patchwork Wed Jan 23 20:58:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777861 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 AE2DE13BF for ; Wed, 23 Jan 2019 20:59:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2EB2DB6A for ; Wed, 23 Jan 2019 20:59:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 912882DB78; Wed, 23 Jan 2019 20:59:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A61E2DB77 for ; Wed, 23 Jan 2019 20:59:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727059AbfAWU7j (ORCPT ); Wed, 23 Jan 2019 15:59:39 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45261 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbfAWU7j (ORCPT ); Wed, 23 Jan 2019 15:59:39 -0500 Received: by mail-wr1-f66.google.com with SMTP id t6so4079064wrr.12 for ; Wed, 23 Jan 2019 12:59:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LFpRyJPMms7jsRj3mehl+ss5PrAmF+jHVBIOOFAttJQ=; b=lJj7IWjd8tzfMui+wky1PgefOeRF5EStwHHtDkL30KZ4yFlEsWwkVtOgQAfueqbnYA k4O/QckcPAe3OrkOvc7WqOVfF02PaJ4XvTWXT+fumLT6Sbzla+PR1jf5+IHbtGspSz+k 5V4syWlAvTUCt0yt6qZZqo5RUSI3K8VgWaltrMrbvfTBaSt7SI1GdU/of2sM+UEwZWPS fMfN22eCrmVecZgJq5+pQhT7+N5Cwig4/SAKfFae1Rw8BYiumrRiclOZ7RXbojCYxJJ9 yHplGT2s+zGG3Xn+ezJ0JbfA0skVmO3HmKdSNfIfimIt52jc4+aGec5L5NOOwr9htHmG 2IEQ== 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=LFpRyJPMms7jsRj3mehl+ss5PrAmF+jHVBIOOFAttJQ=; b=cGAnTCBTAqYPnJeH0Rv3Lc73aU5zAKcjd/4J7rzNBWmgHnmoDyzOkVjWZRendiMK4U hGraLgpAV/o9qFcRoHAnYrmJB65bFZ8QykX9f9cFgVP4HdUPCjg6kYHM64pIkDP7SAl5 bJ5JxkjzfT/g91KGW2r5snq4od2DNKfhmRXfStCh4lbGb6XxhHTAo3CFmcREq+XDVq0M obEdpR8WyP9B32145b1o7KEZmI3rZ8ZJtVS2FE42yHA5OCan83AcvjQt2FHKALHgzpmw DQ8wQvvbEGLmoaYf6ZK4Bym2pv2jhG7QJ5HFHsk5M6jMeBUK6VEPQNNlEvaX4nfR80i2 T9NA== X-Gm-Message-State: AJcUukfuwLcWkAkR0zy3DOEEqd2rHUqacm2ilwlL8fT34QNmvfzcv/ph UsX6guW/p+Vwzbz6YftMr9g763kP X-Google-Smtp-Source: ALg8bN4JL5IobN4YdDajL8lZfqY/+hnt6Rh/PYUX4CA2Gp0m7aOEKwNr5YARHPbRSTX+Mbt7DPqkTg== X-Received: by 2002:adf:e284:: with SMTP id v4mr4236923wri.26.1548277176781; Wed, 23 Jan 2019 12:59:36 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:36 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 11/16] sequencer: refactor skip_unnecessary_picks() to work on a todo_list Date: Wed, 23 Jan 2019 21:58:16 +0100 Message-Id: <20190123205821.27459-12-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This refactors skip_unnecessary_picks() to work on a todo_list. As this function is only called by complete_action() (and thus is not used by rebase -p), the file-handling logic is completely dropped here. Instead of truncating the todo list’s buffer, the items are moved to the beginning of the list, eliminating the need to reparse the list. This also means its buffer cannot be directly written to the disk. rewrite_file() is then removed, as it is now unused. Signed-off-by: Alban Gruin --- Unchanged since v4. sequencer.c | 78 ++++++++++++----------------------------------------- 1 file changed, 17 insertions(+), 61 deletions(-) diff --git a/sequencer.c b/sequencer.c index 2a43ca685b..a817afffa9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4661,52 +4661,22 @@ int check_todo_list_from_file(struct repository *r) return res; } -static int rewrite_file(const char *path, const char *buf, size_t len) -{ - int rc = 0; - int fd = open(path, O_WRONLY | O_TRUNC); - if (fd < 0) - return error_errno(_("could not open '%s' for writing"), path); - if (write_in_full(fd, buf, len) < 0) - rc = error_errno(_("could not write to '%s'"), path); - if (close(fd) && !rc) - rc = error_errno(_("could not close '%s'"), path); - return rc; -} - /* skip picking commits whose parents are unchanged */ -static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid) +static int skip_unnecessary_picks(struct repository *r, + struct todo_list *todo_list, + struct object_id *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(r, todo_list.buf.buf, &todo_list) < 0) { - todo_list_release(&todo_list); - return -1; - } + int i; - for (i = 0; i < todo_list.nr; i++) { - struct todo_item *item = todo_list.items + i; + for (i = 0; i < todo_list->nr; i++) { + struct todo_item *item = todo_list->items + i; if (item->command >= TODO_NOOP) continue; if (item->command != TODO_PICK) break; if (parse_commit(item->commit)) { - todo_list_release(&todo_list); return error(_("could not parse commit '%s'"), oid_to_hex(&item->commit->object.oid)); } @@ -4720,37 +4690,21 @@ static int skip_unnecessary_picks(struct repository *r, struct object_id *output oidcpy(output_oid, &item->commit->object.oid); } if (i > 0) { - int offset = get_item_line_offset(&todo_list, i); const char *done_path = rebase_path_done(); - fd = open(done_path, O_CREAT | O_WRONLY | O_APPEND, 0666); - if (fd < 0) { - error_errno(_("could not open '%s' for writing"), - done_path); - todo_list_release(&todo_list); - return -1; - } - if (write_in_full(fd, todo_list.buf.buf, offset) < 0) { + if (todo_list_write_to_file(r, todo_list, done_path, NULL, NULL, i, 0)) { error_errno(_("could not write to '%s'"), done_path); - todo_list_release(&todo_list); - close(fd); return -1; } - close(fd); - if (rewrite_file(rebase_path_todo(), todo_list.buf.buf + offset, - todo_list.buf.len - offset) < 0) { - todo_list_release(&todo_list); - return -1; - } + MOVE_ARRAY(todo_list->items, todo_list->items + i, todo_list->nr - i); + todo_list->nr -= i; + todo_list->current = 0; - todo_list.current = i; - if (is_fixup(peek_command(&todo_list, 0))) - record_in_rewritten(output_oid, peek_command(&todo_list, 0)); + if (is_fixup(peek_command(todo_list, 0))) + record_in_rewritten(output_oid, peek_command(todo_list, 0)); } - todo_list_release(&todo_list); - return 0; } @@ -4823,6 +4777,11 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return -1; } + if (opts->allow_ff && skip_unnecessary_picks(r, &new_todo, &oid)) { + todo_list_release(&new_todo); + return error(_("could not skip unnecessary pick commands")); + } + if (todo_list_write_to_file(r, &new_todo, todo_file, NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) { todo_list_release(&new_todo); @@ -4831,9 +4790,6 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla todo_list_release(&new_todo); - if (opts->allow_ff && skip_unnecessary_picks(r, &oid)) - return error(_("could not skip unnecessary pick commands")); - if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head)) return -1; From patchwork Wed Jan 23 20:58:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777873 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 606741515 for ; Wed, 23 Jan 2019 20:59:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DB8B2DB6A for ; Wed, 23 Jan 2019 20:59:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40B032DB54; Wed, 23 Jan 2019 20:59:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB18D2DB54 for ; Wed, 23 Jan 2019 20:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbfAWU7p (ORCPT ); Wed, 23 Jan 2019 15:59:45 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35273 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbfAWU7k (ORCPT ); Wed, 23 Jan 2019 15:59:40 -0500 Received: by mail-wr1-f67.google.com with SMTP id 96so4144210wrb.2 for ; Wed, 23 Jan 2019 12:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1Va+2fB4tF8JYiUz4dB1BTqGO/Uvg0TfiKWiPrXdaHI=; b=IuQKiOv9bHM6+P5n/LEYM7dHDZgmslRdjfEcKUmQnF5aM+SLc9ETkWL6x7XYiTE6ME 3IQfG35bLewBtLjJUUnlGj0+q3laNFpIX6/0KqOct7xEX0kleiY+4F4tUl/0QbLronpU jd6cREf5hCTFKSZKtJKzT+5lwpA75dbL+dgfeUvC5uqt8OEHMgNgCsJW7BECJdJl4kKn LqYB3k3BqtkhuNsYyRNpyqvsFB/s3JkFth6iMy+zTXWF4Cu5X6/2qd0yC4FHzANZCXH2 NgIeSsoasZyoRykpAPnBo4weZQHyvMQE8HcXH2WONuE3WJj/L56MTVVsnBBjgerduAsr yJww== 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=1Va+2fB4tF8JYiUz4dB1BTqGO/Uvg0TfiKWiPrXdaHI=; b=lHchK4OrUvenBdzIzEN8/Wbip4Ut4/PlPxSmqKnqg3P8kHvUFB328PCpvbXJFeMHqQ 7HZ7PT9UeEZQZjFsVpZsQNvWsviHlOGj3QEfd6Z4UGdnNAtYk6lYsOBP6OMnH1UGvjXY Fe+QJEu0Bb8OcJ1vfjctfTKYKLO0o6v5W/2OVe7spe3lNqpZBMkdPfvk4cbIGrWHtGW+ NMchFAFYaJ8snOl7zRuXMdA/L3AzwXK/NRZxnTchnt9QU1c5RlL48yLl+EGdA3kOXols QxE9rUYBi2fFlLkwrH/jUzK3qN1E55tDxwj3EcsM/PpE98gzm7RbJLj5MSLf/Y5RzMpN 1Cug== X-Gm-Message-State: AJcUukeE2o250xDr10DSuAFnzZr4krJikvxbSJV7skePfFYPHKjdXARS egs8xRgdechhoJhuPp56cu8J7SXl X-Google-Smtp-Source: ALg8bN7Y853hLLJDUqmzW5M47/Cb2FqEz7bKaw2ag4V0BrOPPXpDGmQuw/q4mIvT4o9nPJZ0RJYByg== X-Received: by 2002:adf:dfd1:: with SMTP id q17mr4540249wrn.27.1548277178720; Wed, 23 Jan 2019 12:59:38 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:38 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 12/16] rebase-interactive: use todo_list_write_to_file() in edit_todo_list() Date: Wed, 23 Jan 2019 21:58:17 +0100 Message-Id: <20190123205821.27459-13-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Just like complete_action(), edit_todo_list() used a function (transform_todo_file()) that read the todo list from the disk and wrote it back, resulting in useless disk accesses. This changes edit_todo_list() to call directly todo_list_write_to_file() instead. Signed-off-by: Alban Gruin --- Squashed <5440ddf5-0b80-3d00-7daf-133a8611efa8@ramsayjones.plus.com> from Ramsay Jones. rebase-interactive.c | 38 ++++++++++++++++---------------------- sequencer.c | 4 ++-- sequencer.h | 3 --- 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index dfa6dd530f..d396ecc599 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -79,39 +79,33 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty, int edit_todo_list(struct repository *r, unsigned flags) { - struct strbuf buf = STRBUF_INIT; const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT; + int res = 0; - if (strbuf_read_file(&buf, todo_file, 0) < 0) + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) return error_errno(_("could not read '%s'."), todo_file); - strbuf_stripspace(&buf, 1); - if (write_message(buf.buf, buf.len, todo_file, 0)) { - strbuf_release(&buf); + strbuf_stripspace(&todo_list.buf, 1); + todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); + if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) { + todo_list_release(&todo_list); return -1; } - strbuf_release(&buf); - - transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS); - - if (strbuf_read_file(&buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - append_todo_help(1, 0, &buf); - if (write_message(buf.buf, buf.len, todo_file, 0)) { - strbuf_release(&buf); + strbuf_reset(&todo_list.buf); + if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { + todo_list_release(&todo_list); return -1; } - strbuf_release(&buf); + if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, + flags & ~(TODO_LIST_SHORTEN_IDS)); - if (launch_sequence_editor(todo_file, NULL, NULL)) - return -1; - - transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS)); - - return 0; + todo_list_release(&todo_list); + return res; } define_commit_slab(commit_seen, unsigned char); diff --git a/sequencer.c b/sequencer.c index a817afffa9..d8d045067c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -383,8 +383,8 @@ static void print_advice(struct repository *r, int show_hint, } } -int write_message(const void *buf, size_t len, const char *filename, - int append_eol) +static int write_message(const void *buf, size_t len, const char *filename, + int append_eol) { struct lock_file msg_file = LOCK_INIT; diff --git a/sequencer.h b/sequencer.h index 0c30e43f0a..c5bee8124c 100644 --- a/sequencer.h +++ b/sequencer.h @@ -64,9 +64,6 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } -int write_message(const void *buf, size_t len, const char *filename, - int append_eol); - /* * Note that ordering matters in this enum. Not only must it match the mapping * of todo_command_info (in sequencer.c), it is also divided into several From patchwork Wed Jan 23 20:58:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777865 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 04206746 for ; Wed, 23 Jan 2019 20:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8EBF2DB54 for ; Wed, 23 Jan 2019 20:59:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD4D12DB77; Wed, 23 Jan 2019 20:59:46 +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 774DE2DB54 for ; Wed, 23 Jan 2019 20:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727072AbfAWU7p (ORCPT ); Wed, 23 Jan 2019 15:59:45 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:34041 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbfAWU7n (ORCPT ); Wed, 23 Jan 2019 15:59:43 -0500 Received: by mail-wr1-f66.google.com with SMTP id f7so4159601wrp.1 for ; Wed, 23 Jan 2019 12:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KQuBbgxTdhepmfIatQ3mgqhjkKwSXtfG4dYMHMULmQI=; b=vDbsmt+ZsXFmEbwJFJENTWytF/JyvLl0MUSp3x39uUXxw+GeC6qzWNm8ly20KFQ5EE OFCIAKXyzhrUqHhFjxpNvLofdhU8mgmXoBiRZke9gJ82a3zYlTTh+ZtZaihtaa5y/z8C 8hEKinZVnGCSHusgyJ9QM/uRRayU2H417ZlWDruaE1J0evoIRfEY2rxALQzrma2S2G72 6sA8UQHPIstB84jDH7CHNnMg16H4sTtapHcxeY5QZbVUyZAOWLjPBasCYdkSXDRwbKcb RyhfwR6VLnaDtq0SgHINYaYPCoZPy/xusTTumvtnhOoEYb/kEKaQU9SsX5GrHsH4LGDk LYYQ== 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=KQuBbgxTdhepmfIatQ3mgqhjkKwSXtfG4dYMHMULmQI=; b=tacNAt46qRhpvuTeXnXA5RzvJ20VwkK8if4019cohrzmuysgyhvgkXgcwR9lxvYfab 6Ob49JOt1CwEJcesLFLoxGH64jLj33jLq7NRfxEDutlsTmEpFuhW+4unRYaUrgFXfDT6 72L6z5tkGsPz4acJvkROJqQT9fsaoBpczznfzVxuSX9GDugcaLRO0Jhc4aePFursy69s 9XgPEAPsQLie0geQwpVV264CQJtyNE3ZmoHhUL8HQoIqFkV/dpGvGArAOI4xik9590RY wniSmYEl1WfowlDxfCvQNSNL/Gemhqf6xpQDxTrKHpEVStDEsVVPZzTeKLT9SVzlThlo aufQ== X-Gm-Message-State: AJcUukev1Pnu+qZz1g1zc1MEfmIr2PjEVSgD+LxlJIVRg+mBZE97bpDZ a5W5qdLNhhA3Im24YTemDp0gJ8Vg X-Google-Smtp-Source: ALg8bN4Pr/Pli6Eymci4+CB94gyd2D2EsO00H8RGQ0oy8qmHH6xG0qPBtsZgjQc2UXhAa2/c0u8Ggg== X-Received: by 2002:adf:fa90:: with SMTP id h16mr4598069wrr.326.1548277180473; Wed, 23 Jan 2019 12:59:40 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:39 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 13/16] rebase-interactive: append_todo_help() changes Date: Wed, 23 Jan 2019 21:58:18 +0100 Message-Id: <20190123205821.27459-14-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This moves the writing of the comment "Rebase $shortrevisions onto $shortonto ($command_count commands)" from todo_list_write_to_file() to append_todo_help(). shortrevisions, shortonto, and command_count are passed as parameters to append_todo_help(). During the initial edit of the todo list, shortrevisions and shortonto are not NULL. Therefore, if shortrevisions or shortonto is NULL, then edit_todo would be true, otherwise it would be false. Thus, edit_todo is removed from the parameters of append_todo_help(). Signed-off-by: Alban Gruin --- rebase-interactive.c | 12 +++++++++++- rebase-interactive.h | 3 ++- sequencer.c | 17 ++++------------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/rebase-interactive.c b/rebase-interactive.c index d396ecc599..807f8370db 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -28,7 +28,8 @@ static enum missing_commit_check_level get_missing_commit_check_level(void) return MISSING_COMMIT_CHECK_IGNORE; } -void append_todo_help(unsigned edit_todo, unsigned keep_empty, +void append_todo_help(unsigned keep_empty, int command_count, + const char *shortrevisions, const char *shortonto, struct strbuf *buf) { const char *msg = _("\nCommands:\n" @@ -48,6 +49,15 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty, ". specified). Use -c to reword the commit message.\n" "\n" "These lines can be re-ordered; they are executed from top to bottom.\n"); + unsigned edit_todo = !(shortrevisions && shortonto); + + if (!edit_todo) { + strbuf_addch(buf, '\n'); + strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)", + "Rebase %s onto %s (%d commands)", + command_count), + shortrevisions, shortonto, command_count); + } strbuf_add_commented_lines(buf, msg, strlen(msg)); diff --git a/rebase-interactive.h b/rebase-interactive.h index 187b5032d6..0e5925e3aa 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -5,7 +5,8 @@ struct strbuf; struct repository; struct todo_list; -void append_todo_help(unsigned edit_todo, unsigned keep_empty, +void append_todo_help(unsigned keep_empty, int command_count, + const char *shortrevisions, const char *shortonto, struct strbuf *buf); int edit_todo_list(struct repository *r, unsigned flags); int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); diff --git a/sequencer.c b/sequencer.c index d8d045067c..92de982bc4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4580,22 +4580,13 @@ int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, const char *file, const char *shortrevisions, const char *shortonto, int num, unsigned flags) { - int edit_todo = !(shortrevisions && shortonto), res; + int res; struct strbuf buf = STRBUF_INIT; todo_list_to_strbuf(r, todo_list, &buf, num, flags); - - if (flags & TODO_LIST_APPEND_TODO_HELP) { - int command_count = count_commands(todo_list); - if (!edit_todo) { - strbuf_addch(&buf, '\n'); - strbuf_commented_addf(&buf, Q_("Rebase %s onto %s (%d command)", - "Rebase %s onto %s (%d commands)", - command_count), - shortrevisions, shortonto, command_count); - } - append_todo_help(edit_todo, flags & TODO_LIST_KEEP_EMPTY, &buf); - } + if (flags & TODO_LIST_APPEND_TODO_HELP) + append_todo_help(flags & TODO_LIST_KEEP_EMPTY, count_commands(todo_list), + shortrevisions, shortonto, &buf); res = write_message(buf.buf, buf.len, file, 0); strbuf_release(&buf); From patchwork Wed Jan 23 20:58:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777867 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 ECFAA746 for ; Wed, 23 Jan 2019 20:59:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD8A02DB54 for ; Wed, 23 Jan 2019 20:59:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEB672DB77; Wed, 23 Jan 2019 20:59:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4132C2DB54 for ; Wed, 23 Jan 2019 20:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbfAWU7p (ORCPT ); Wed, 23 Jan 2019 15:59:45 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33048 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727057AbfAWU7o (ORCPT ); Wed, 23 Jan 2019 15:59:44 -0500 Received: by mail-wr1-f66.google.com with SMTP id p7so4161593wru.0 for ; Wed, 23 Jan 2019 12:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PEBl/SNnHlVmq9uEpJOQrncd6iqVH5b5S5tD8CIMJoA=; b=NRJLGlHeTtJXQ7G0b/Y0R0IWQB244MKEuUdLaa5RHgZLleQIgjdG97tcZRMVj6q+l8 TlhrQ0SFTP7/kfdi5O12ZicEHoZ8SExcbxnyJU0lwQIjb/dRT+ANPwNJnnxYhWJcNNUF 4dQZY7iwXVXBTf790IymTEl3B7zJCjr1YRGGs2H9EEEJW/lpLdPRbQQ6Yt173FA51pTj z7Wi0OgLFXJWe4Tg/HhTR2HRaA10zm1tEzXHo4BhwLFSNVW4teEJoskig06iyNqMRwwF ij15Q6C3efyzV4Ewq7dBS+mDBsPkEpZ9JETTNogD3CjapC5JWlMWZZYlmPNBSbR8copK w8Ig== 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=PEBl/SNnHlVmq9uEpJOQrncd6iqVH5b5S5tD8CIMJoA=; b=UUJJ8GNRNSP2E5sVSQaVvEahnvCW4LMC35ggtjF/UM5HH9OKaS3KwBrALPTxwUB2It Ke6Kp/j6sFqwUbemws0UORTnp4hZsMcAq4ewZQBZIF2XLFdYfyyq4TZ2o6XcVfvBYLOx sCT6ePtaMPjGEtAMmKRqk9j7623TbADH9ZDxXSSjAtDqtAjwHuLoYUh0ycR9r+E4ptOZ GPGE33HaGsR5Bq1GopLAzNpgMmWfddH+AX+zPCFip/HtwtpObI8ELBtJ/xVxvVfVs9aU xfIc8t5E/23rxEPnk0w7De1RfDiqNQnG95PtNnz1tH/m6HsHgDCnjpKZVU+J8MIYZxp0 BXWA== X-Gm-Message-State: AJcUukfYSfC49TuazLbEyMHj7TC54pHEJna6xiY1byM5eDesFhuekL/I /eY3ibqGPrBVEXI8wKIhoQbOR+u4 X-Google-Smtp-Source: ALg8bN6nQ69n/DztAXcpAT8eFiUc8t8sm6b4CbXD3u7MNqa0HW2r7YvBOhcqrUdjnKG88O1Vzy25lg== X-Received: by 2002:adf:8323:: with SMTP id 32mr4185323wrd.176.1548277182474; Wed, 23 Jan 2019 12:59:42 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:41 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 14/16] rebase-interactive: rewrite edit_todo_list() to handle the initial edit Date: Wed, 23 Jan 2019 21:58:19 +0100 Message-Id: <20190123205821.27459-15-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-1-alban.gruin@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP edit_todo_list() is changed to work on a todo_list, and to handle the initial edition of the todo list (ie. making a backup of the todo list). It does not check for dropped commits yet, as todo_list_check() does not take the commits that have already been processed by the rebase (ie. the todo list is edited in the middle of a rebase session). Signed-off-by: Alban Gruin --- Unchanged since v4. builtin/rebase--interactive.c | 24 +++++++++++++++++- rebase-interactive.c | 48 ++++++++++++++++++----------------- rebase-interactive.h | 4 ++- sequencer.c | 3 +-- sequencer.h | 1 + 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 2dbf8fc08b..645ac587f7 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -13,6 +13,28 @@ static GIT_PATH_FUNC(path_state_dir, "rebase-merge/") static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto") static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive") +static int edit_todo_file(unsigned flags) +{ + const char *todo_file = rebase_path_todo(); + struct todo_list todo_list = TODO_LIST_INIT, + new_todo = TODO_LIST_INIT; + + 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(the_repository, &todo_list, + &new_todo, NULL, NULL, flags) && + todo_list_write_to_file(the_repository, &new_todo, todo_file, NULL, NULL, + -1, flags & ~(TODO_LIST_SHORTEN_IDS)) < 0) + return error_errno(_("could not write '%s'"), todo_file); + + todo_list_release(&todo_list); + todo_list_release(&new_todo); + + return 0; +} + static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, char **revisions, char **shortrevisions) @@ -242,7 +264,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) break; } case EDIT_TODO: - ret = edit_todo_list(the_repository, flags); + ret = edit_todo_file(flags); break; case SHOW_CURRENT_PATCH: { struct child_process cmd = CHILD_PROCESS_INIT; diff --git a/rebase-interactive.c b/rebase-interactive.c index 807f8370db..3301efbe52 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -87,35 +87,37 @@ void append_todo_help(unsigned keep_empty, int command_count, } } -int edit_todo_list(struct repository *r, unsigned flags) +int edit_todo_list(struct repository *r, struct todo_list *todo_list, + struct todo_list *new_todo, const char *shortrevisions, + const char *shortonto, unsigned flags) { const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res = 0; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - strbuf_stripspace(&todo_list.buf, 1); - todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list); - if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) { - todo_list_release(&todo_list); - return -1; + unsigned initial = shortrevisions && shortonto; + + if (initial) { + todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto, + -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP); + + if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) + return error(_("could not copy '%s' to '%s'."), todo_file, + rebase_path_todo_backup()); + } else { + todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list); + todo_list_write_to_file(r, todo_list, todo_file, NULL, NULL, -1, + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP); } - strbuf_reset(&todo_list.buf); - if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) { - todo_list_release(&todo_list); - return -1; - } + if (launch_sequence_editor(todo_file, &new_todo->buf, NULL)) + return -2; - if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) - res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1, - flags & ~(TODO_LIST_SHORTEN_IDS)); + 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(r, new_todo->buf.buf, new_todo); + + return 0; } define_commit_slab(commit_seen, unsigned char); diff --git a/rebase-interactive.h b/rebase-interactive.h index 0e5925e3aa..44dbb06311 100644 --- a/rebase-interactive.h +++ b/rebase-interactive.h @@ -8,7 +8,9 @@ struct todo_list; void append_todo_help(unsigned keep_empty, int command_count, const char *shortrevisions, const char *shortonto, struct strbuf *buf); -int edit_todo_list(struct repository *r, unsigned flags); +int edit_todo_list(struct repository *r, struct todo_list *todo_list, + struct todo_list *new_todo, const char *shortrevisions, + const char *shortonto, unsigned flags); int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo); #endif diff --git a/sequencer.c b/sequencer.c index 92de982bc4..8f47f0cf39 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 c5bee8124c..68acab980b 100644 --- a/sequencer.h +++ b/sequencer.h @@ -10,6 +10,7 @@ struct repository; const char *git_path_commit_editmsg(void); const char *git_path_seq_dir(void); const char *rebase_path_todo(void); +const char *rebase_path_todo_backup(void); #define APPEND_SIGNOFF_DEDUP (1u << 0) From patchwork Wed Jan 23 20:58:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777869 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 969C513BF for ; Wed, 23 Jan 2019 20:59:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85F5C2DB54 for ; Wed, 23 Jan 2019 20:59:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A79D2DB77; Wed, 23 Jan 2019 20:59:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A1AC2DB54 for ; Wed, 23 Jan 2019 20:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbfAWU7q (ORCPT ); Wed, 23 Jan 2019 15:59:46 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:45271 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727065AbfAWU7q (ORCPT ); Wed, 23 Jan 2019 15:59:46 -0500 Received: by mail-wr1-f66.google.com with SMTP id t6so4079356wrr.12 for ; Wed, 23 Jan 2019 12:59:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0DCJcMRz0JP4DJ7oZrAk1G9A7Y9hdNvFAvKkan2OpFs=; b=gdR23jDIXlfoX/uNfwChl/y+fohCSa6ZmDm6QtUZlMEm3d8wwatUofFzRvVNEPh2+x vjP3aTkV9cgXPWB96VKJ6GsJHN0NVIUYzBgpVP1/lsXqRB5/9wv0z1GPyeIXSZEatQmM IijOYRFP7jtpy8jydiGHDzS93Av6AL+btrS4sjFx0AaFcIV1WFmjBkztV4n8/C5ll3St 5yUR5n7lydd7aeviFjm+qBvmrnxghliYZE43ewRFr7q/V4eze4gJZqPJded+UEAmF3mW Cb0QLDCkG2lssnOPRs/hEQgpc6yXKTzmyYli1PjDqqLYUAW3B5OArNMXLVglP1YSpI0N JJ9Q== 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=0DCJcMRz0JP4DJ7oZrAk1G9A7Y9hdNvFAvKkan2OpFs=; b=msmB9YKztoNOnMpybUwug8ZLiHVHxYK74lnfEMiImjQfi8ALIOAkg3I1rkmD85QvlX EAFUFZRg2wYqLRpt0lPS9vBQW9CxWvdveFHBxblogCm+3WgSwGLpmox1wuOlaYL1MsAY hGE3mvShc/haA4RCPzXw0zxaoJNRqybpIXibQmFrPFblOjfGFGbNbcV94PLSaBXTuqc+ /LnjzxCzmxC0ELLmCBDWO882mPhb5cihxdFtErO8MzzIHjMejLgKNlB6xq5ktu+vn0Kq 1EGipSV35vjFWUDqqLizlQ1N6GPsdgeQlLtgWra5gXy6TYEAZSQtyI3mNoum2bV85ZVD gsGA== X-Gm-Message-State: AJcUukd2kIYoSqo4zNbmjTwOF3sKYwditvGb5v6j4+I9mXMyZPn1sKAw CMXJ3Kp13aderhBzs+5WRe3ojjTk X-Google-Smtp-Source: ALg8bN7cqO32UyFSagKN4s4IihQNCTlA4LLhB3d5MrFagyzIqvoJ/YL7PFX/P+42fi5Y2egbLUuKNg== X-Received: by 2002:a5d:448f:: with SMTP id j15mr4080413wrq.108.1548277184126; Wed, 23 Jan 2019 12:59:44 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:43 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 15/16] sequencer: use edit_todo_list() in complete_action() Date: Wed, 23 Jan 2019 21:58:20 +0100 Message-Id: <20190123205821.27459-16-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-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 --- Unchanged since v4. sequencer.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/sequencer.c b/sequencer.c index 8f47f0cf39..21b04e0642 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4709,6 +4709,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla struct todo_list new_todo = TODO_LIST_INIT; struct strbuf *buf = &todo_list->buf; struct object_id oid; + int res; get_oid(onto, &oid); shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV); @@ -4733,24 +4734,16 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla return error(_("nothing to do")); } - if (todo_list_write_to_file(r, todo_list, todo_file, - shortrevisions, shortonto, -1, - flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) - return error_errno(_("could not write '%s'"), todo_file); - - if (copy_file(rebase_path_todo_backup(), todo_file, 0666)) - return error(_("could not copy '%s' to '%s'."), todo_file, - rebase_path_todo_backup()); - - if (launch_sequence_editor(todo_file, &new_todo.buf, NULL)) { + res = edit_todo_list(r, todo_list, &new_todo, shortrevisions, + shortonto, flags); + if (res == -1) + return -1; + else if (res == -2) { apply_autostash(opts); sequencer_remove_state(opts); return -1; - } - - strbuf_stripspace(&new_todo.buf, 1); - if (new_todo.buf.len == 0) { + } else if (res == -3) { apply_autostash(opts); sequencer_remove_state(opts); todo_list_release(&new_todo); From patchwork Wed Jan 23 20:58:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban Gruin X-Patchwork-Id: 10777871 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 E71D8746 for ; Wed, 23 Jan 2019 20:59:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D51122DB6A for ; Wed, 23 Jan 2019 20:59:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C588F2DB77; Wed, 23 Jan 2019 20:59:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6189E2DB54 for ; Wed, 23 Jan 2019 20:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727006AbfAWU7t (ORCPT ); Wed, 23 Jan 2019 15:59:49 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35281 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727073AbfAWU7r (ORCPT ); Wed, 23 Jan 2019 15:59:47 -0500 Received: by mail-wr1-f65.google.com with SMTP id 96so4144506wrb.2 for ; Wed, 23 Jan 2019 12:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xLIDl5+6UAcPjlAePh0r10VvNSTysYz4SvnNEGQ3BLw=; b=JuloyhfnfWe6UNN5ZYCqZ/dvMuQdlz8utjsaxnH0jUBzb5kzW3s8cbqOLDMHnU5Q7G aMIpGjRpxXZX6lr4Aq8vGWt7HenMFsR2NmJstYncfmHM17SI61672gxbOLqnWeYLprJj S0nAM4A1f5glwbZLxCg/UKap/r2HayZu3Cdu08iFxhRrnv+91cIjtecRAfqbH7m096rf 6UfGFvoaJ2XupNOoH6ZuVsvIt6s1avMWJVDYTq7MO683dpM32OJP2Dx/PVUHrZHGAb7Y C9Qj9m/U3ulJBROZHOxRJ79vA5tfrfU+T7uDFPHl3PKx9yNJcx57DuCydXyU9Z+0fEug RJNQ== 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=xLIDl5+6UAcPjlAePh0r10VvNSTysYz4SvnNEGQ3BLw=; b=G8uZLxaTMIjtreugYiWC7QmCjaKocOu7mT9Y1aptKZPneJn9v5vat3APpY8bUEvbos g5qGF35CT/GTT4lbsUhwjuVjMPHaOCLsu1U23wYfayd8FJAxZjBJLFojK5xHAZAEpwfl pubTs+aXrqyx+5W38bY1aL7qg3PV17EivV87XLeQqZCOwJrqfI2QWnHm2HaGPFBLdCYx AbivV9zM62Wm5HJTi2JfIYzJU6OD+LawF30aBi4qmW8lBU4H4N10UQcmxeKc93CXsgYl UTRdxYlW5kjGr9oBBfZmIJiSS+9H0BZVhDYMbnAcUyDVh0YYnsiui+0dpMTwQT6Rq/Jl XwdA== X-Gm-Message-State: AJcUukcVVQXXMGNdF7TFTXt8rdavN8THIKe5XOFtlzkm8jJe6TEl55ZR IqKi+0gIsBvrE/CEATcI6o+tvspu X-Google-Smtp-Source: ALg8bN5mtSXL/oyflrADkB/OtqZyt12dqOAV+JIJJdTWNEVKNRl+lUXA5Tc7kuY1DuBo3T1FI2atYg== X-Received: by 2002:adf:91a3:: with SMTP id 32mr3929906wri.99.1548277185657; Wed, 23 Jan 2019 12:59:45 -0800 (PST) Received: from localhost.localdomain (atoulouse-658-1-2-163.w86-222.abo.wanadoo.fr. [86.222.145.163]) by smtp.googlemail.com with ESMTPSA id h13sm80634127wrp.61.2019.01.23.12.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 12:59:45 -0800 (PST) From: Alban Gruin To: git@vger.kernel.org Cc: Johannes Schindelin , Phillip Wood , Junio C Hamano , Alban Gruin Subject: [PATCH v5 16/16] rebase--interactive: move transform_todo_file() to rebase--interactive.c Date: Wed, 23 Jan 2019 21:58:21 +0100 Message-Id: <20190123205821.27459-17-alban.gruin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190123205821.27459-1-alban.gruin@gmail.com> References: <20181229160413.19333-1-alban.gruin@gmail.com> <20190123205821.27459-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 --- Unchanged since v4. builtin/rebase--interactive.c | 26 +++++++++++++++++++++++++- sequencer.c | 23 ----------------------- sequencer.h | 1 - 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 645ac587f7..7f1e88a087 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -35,6 +35,30 @@ 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(the_repository, todo_list.buf.buf, + &todo_list)) { + todo_list_release(&todo_list); + return error(_("unusable todo list: '%s'"), todo_file); + } + + res = todo_list_write_to_file(the_repository, &todo_list, todo_file, + NULL, NULL, -1, flags); + todo_list_release(&todo_list); + + if (res) + return error_errno(_("could not write '%s'."), todo_file); + return 0; +} + static int get_revision_ranges(const char *upstream, const char *onto, const char **head_hash, char **revisions, char **shortrevisions) @@ -277,7 +301,7 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) } case SHORTEN_OIDS: case EXPAND_OIDS: - ret = transform_todo_file(the_repository, flags); + ret = transform_todo_file(flags); break; case CHECK_TODO_LIST: ret = check_todo_list_from_file(the_repository); diff --git a/sequencer.c b/sequencer.c index 21b04e0642..5239700efc 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4593,29 +4593,6 @@ int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list, return res; } -int transform_todo_file(struct repository *r, unsigned flags) -{ - const char *todo_file = rebase_path_todo(); - struct todo_list todo_list = TODO_LIST_INIT; - int res; - - if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) - return error_errno(_("could not read '%s'."), todo_file); - - if (todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list)) { - todo_list_release(&todo_list); - return error(_("unusable todo list: '%s'"), todo_file); - } - - res = todo_list_write_to_file(r, &todo_list, todo_file, - NULL, NULL, -1, flags); - todo_list_release(&todo_list); - - if (res) - return error_errno(_("could not write '%s'."), todo_file); - return 0; -} - static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' " "and then run 'git rebase --continue'.\n" diff --git a/sequencer.h b/sequencer.h index 68acab980b..11afd47aa9 100644 --- a/sequencer.h +++ b/sequencer.h @@ -145,7 +145,6 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, int sequencer_add_exec_commands(struct repository *r, struct string_list *commands); -int transform_todo_file(struct repository *r, unsigned flags); int check_todo_list_from_file(struct repository *r); int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name,