git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Alban Gruin <alban.gruin@gmail.com>
To: git@vger.kernel.org
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	Alban Gruin <alban.gruin@gmail.com>
Subject: [RFC PATCH 7/9] rebase-interactive: todo_list_check() also uses the done list
Date: Wed, 17 Jul 2019 16:39:16 +0200	[thread overview]
Message-ID: <20190717143918.7406-8-alban.gruin@gmail.com> (raw)
In-Reply-To: <20190717143918.7406-1-alban.gruin@gmail.com>

todo_list_check() works by checking if every commit in old_todo (the
backup list) is also present in new_todo (the todo list to check).

This works only when no commits have been picked (ie. right after the
initial edit).  In other cases, the backup list will contain one or
several commits that have been applied and are no longer in the todo
list.  Let's take this todo list, for instance:

	pick 123abc An interesting change
	break
	pick cba321 A boring change

After executing the `break' command, the backup list will contain the
original todo list, while the todo list will only contain the last
`pick' insn.  Even if commit 123abc has been picked up, in this case,
todo_list_check() will fail because it is not part of the todo list.

There is another list containing every command that have been executed:
the "done" list.  In our example, after the `break' command, the "done"
list will contain the first commit (123abc).  Comparing the backup list
against the todo list and the done list will fix this problem.

This changes todo_list_check() to compare old_todo against new_todo
_and_ the done list.  This should be useful to check the todo list when
resuming a rebase or reloading the todo list after an `exec' command,
but not for `--edit-todo' (the todo list is copied before edition).
But, for the sake of safety, it is still done in the next commit.

This also adds a function, todo_list_check_against_backup(), to load the
done list and the backup list, and call todo_list_check().

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
---
 rebase-interactive.c | 57 ++++++++++++++++++++++++++++++++++++++------
 rebase-interactive.h |  6 ++++-
 sequencer.c          |  4 ++--
 3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/rebase-interactive.c b/rebase-interactive.c
index aa18ae82b7..c7dea85553 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -6,6 +6,8 @@
 #include "commit-slab.h"
 #include "config.h"
 
+static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done")
+
 enum missing_commit_check_level {
 	MISSING_COMMIT_CHECK_IGNORE = 0,
 	MISSING_COMMIT_CHECK_WARN,
@@ -124,13 +126,27 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
 }
 
 define_commit_slab(commit_seen, unsigned char);
+
+static void mark_commits_as_seen(struct commit_seen *commit_seen,
+				 struct todo_list *list)
+{
+	int i;
+
+	for (i = 0; i < list->nr; i++) {
+		struct commit *commit = list->items[i].commit;
+		if (commit)
+			*commit_seen_at(commit_seen, commit) = 1;
+	}
+}
+
 /*
  * 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)
+int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo,
+		    struct todo_list *done)
 {
 	enum missing_commit_check_level check_level = get_missing_commit_check_level();
 	struct strbuf missing = STRBUF_INIT;
@@ -142,12 +158,11 @@ int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo)
 	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;
-	}
+	/* Mark the commits in git-rebase-todo and git-rebase-done as
+	   seen */
+	mark_commits_as_seen(&commit_seen, new_todo);
+	if (done)
+		mark_commits_as_seen(&commit_seen, done);
 
 	/* Find commits in git-rebase-todo.backup yet unseen */
 	for (i = old_todo->nr - 1; i >= 0; i--) {
@@ -187,3 +202,31 @@ int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo)
 	clear_commit_seen(&commit_seen);
 	return res;
 }
+
+int todo_list_check_against_backup(struct repository *r,
+				   struct todo_list *todo_list)
+{
+	struct todo_list done = TODO_LIST_INIT, initial = TODO_LIST_INIT;
+	int res;
+
+	if (strbuf_read_file(&done.buf, rebase_path_done(), 0) < 0 && errno != ENOENT)
+		return error(_("could not read '%s'"), rebase_path_done());
+
+	strbuf_read_file(&done.buf, rebase_path_done(), 0);
+	todo_list_parse_insn_buffer(r, done.buf.buf, &done);
+
+	if (strbuf_read_file(&initial.buf, rebase_path_todo_backup(), 0) < 0 &&
+	    errno != ENOENT) {
+		todo_list_release(&done);
+		return error(_("could not read '%s'"), rebase_path_done());
+	}
+
+	todo_list_parse_insn_buffer(r, initial.buf.buf, &initial);
+
+	res = todo_list_check(&initial, todo_list, &done);
+
+	todo_list_release(&done);
+	todo_list_release(&initial);
+
+	return res;
+}
diff --git a/rebase-interactive.h b/rebase-interactive.h
index 44dbb06311..ac401cda25 100644
--- a/rebase-interactive.h
+++ b/rebase-interactive.h
@@ -11,6 +11,10 @@ void append_todo_help(unsigned keep_empty, int command_count,
 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);
+
+int todo_list_check(struct todo_list *old_todo, struct todo_list *new_todo,
+		    struct todo_list *done);
+int todo_list_check_against_backup(struct repository *r,
+				   struct todo_list *todo_list);
 
 #endif
diff --git a/sequencer.c b/sequencer.c
index 3fb15ff8d9..0638c92f12 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4898,7 +4898,7 @@ int check_todo_list_from_file(struct repository *r)
 	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);
+		res = todo_list_check(&old_todo, &new_todo, NULL);
 	if (res)
 		fprintf(stderr, _(edit_todo_list_advice));
 out:
@@ -5008,7 +5008,7 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
 	}
 
 	if (todo_list_parse_insn_buffer(r, new_todo.buf.buf, &new_todo) ||
-	    todo_list_check(todo_list, &new_todo)) {
+	    todo_list_check(todo_list, &new_todo, NULL)) {
 		fprintf(stderr, _(edit_todo_list_advice));
 		checkout_onto(r, opts, onto_name, &onto->object.oid, orig_head);
 		todo_list_release(&new_todo);
-- 
2.22.0


  parent reply	other threads:[~2019-07-17 14:42 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-17 14:39 [RFC PATCH 0/9] rebase -i: extend rebase.missingCommitsCheck to `--edit-todo' and co Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 1/9] t3404: demonstrate that --edit-todo does not check for dropped commits Alban Gruin
2019-07-18 18:31   ` Junio C Hamano
2019-07-19 18:12     ` Alban Gruin
2019-07-19 19:51       ` Junio C Hamano
2019-07-17 14:39 ` [RFC PATCH 2/9] t3429: demonstrate that rebase exec " Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 3/9] sequencer: update `total_nr' when adding an item to a todo list Alban Gruin
2019-07-18 19:52   ` Junio C Hamano
2019-07-19 18:12     ` Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 4/9] sequencer: update `done_nr' when skipping commands in " Alban Gruin
2019-07-18 19:55   ` Junio C Hamano
2019-07-19 18:13     ` Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 5/9] sequencer: move the code writing total_nr on the disk to a new function Alban Gruin
2019-07-18 20:04   ` Junio C Hamano
2019-07-19 18:14     ` Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 6/9] sequencer: add a parameter to sequencer_continue() to accept a todo list Alban Gruin
2019-07-17 14:39 ` Alban Gruin [this message]
2019-07-17 14:39 ` [RFC PATCH 8/9] rebase-interactive: warn if commit is dropped with --edit-todo Alban Gruin
2019-07-17 14:39 ` [RFC PATCH 9/9] sequencer: have read_populate_todo() check for dropped commits Alban Gruin
2019-07-24 13:29 ` [RFC PATCH 0/9] rebase -i: extend rebase.missingCommitsCheck to `--edit-todo' and co Phillip Wood
2019-07-25  9:01   ` Johannes Schindelin
2019-07-25 20:26   ` Alban Gruin
2019-07-29  9:38     ` Phillip Wood
2019-09-24 20:15       ` Alban Gruin
2019-11-04  9:54 ` [RFC PATCH v2 0/2] rebase -i: extend rebase.missingCommitsCheck to `--edit-todo' Alban Gruin
2019-11-04  9:54   ` [RFC PATCH v2 1/2] t3404: demonstrate that --edit-todo does not check for dropped commits Alban Gruin
2019-11-04  9:54   ` [RFC PATCH v2 2/2] rebase-interactive: warn if commit is dropped with --edit-todo Alban Gruin
2019-11-05 14:20     ` Phillip Wood
2019-12-02 23:47   ` [PATCH v3 0/2] rebase -i: extend rebase.missingCommitsCheck Alban Gruin
2019-12-02 23:47     ` [PATCH v3 1/2] sequencer: move check_todo_list_from_file() to rebase-interactive.c Alban Gruin
2019-12-06 14:38       ` Johannes Schindelin
2019-12-02 23:47     ` [PATCH v3 2/2] rebase-interactive: warn if commit is dropped with `rebase --edit-todo' Alban Gruin
2019-12-04 19:19       ` Junio C Hamano
2019-12-09 16:00         ` Phillip Wood
2020-01-09 21:13           ` Alban Gruin
2020-01-10 17:13             ` Phillip Wood
2020-01-10 21:31               ` Alban Gruin
2020-01-11 14:44                 ` Phillip Wood
2019-12-09 16:08       ` Phillip Wood
2019-12-04 21:51     ` [PATCH v3 0/2] rebase -i: extend rebase.missingCommitsCheck Junio C Hamano
2019-12-05 23:15       ` Alban Gruin
2019-12-06 10:41         ` Phillip Wood
2019-12-06 14:30           ` Johannes Schindelin
2020-01-11 17:39     ` [PATCH v4 " Alban Gruin
2020-01-11 17:39       ` [PATCH v4 1/2] sequencer: move check_todo_list_from_file() to rebase-interactive.c Alban Gruin
2020-01-11 17:39       ` [PATCH v4 2/2] rebase-interactive: warn if commit is dropped with `rebase --edit-todo' Alban Gruin
2020-01-19 16:28         ` Phillip Wood
2020-01-25 15:17           ` Alban Gruin
2020-01-25 17:54       ` [PATCH v5 0/2] rebase -i: extend rebase.missingCommitsCheck Alban Gruin
2020-01-25 17:54         ` [PATCH v5 1/2] sequencer: move check_todo_list_from_file() to rebase-interactive.c Alban Gruin
2020-01-25 17:54         ` [PATCH v5 2/2] rebase-interactive: warn if commit is dropped with `rebase --edit-todo' Alban Gruin
2020-01-26 10:04         ` [PATCH v5 0/2] rebase -i: extend rebase.missingCommitsCheck Johannes Schindelin
2020-01-27 21:39           ` Alban Gruin
2020-01-28 22:46             ` Johannes Schindelin
2020-01-28 21:12         ` [PATCH v6 " Alban Gruin
2020-01-28 21:12           ` [PATCH v6 1/2] sequencer: move check_todo_list_from_file() to rebase-interactive.c Alban Gruin
2020-01-28 21:12           ` [PATCH v6 2/2] rebase-interactive: warn if commit is dropped with `rebase --edit-todo' Alban Gruin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190717143918.7406-8-alban.gruin@gmail.com \
    --to=alban.gruin@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).