git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] rebase --update-refs: fix loops

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
May 10, 2023, 22:55 UTC
Message-ID
<2ac7c7a7c615db75a46076b58a51d363bc2daf2e.1683759338.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1531.git.1683759338.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

The `total_nr` field in the `todo_list` structure merely serves display purposes, and should only be used when generating the progress message.

In these two instances, however, we want to loop over all of the commands in the parsed rebase script. The loop limit therefore needs to be `nr`, which refers to the count of commands in the current `todo_list`.

This is important because the two numbers, `nr` and `total_nr` can differ wildly, e.g. due to `total_nr` _not_ counting comments or empty lines, while `nr` skips any commands that already moved from the `git-rebase-todo` file to the `done` file.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 sequencer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 5f22b7cd377..f5d89abdc5e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4202,7 +4202,7 @@ void todo_list_filter_update_refs(struct repository *r,
 		if (!is_null_oid(&rec->after))
 			continue;
 
-		for (j = 0; !found && j < todo_list->total_nr; j++) {
+		for (j = 0; !found && j < todo_list->nr; j++) {
 			struct todo_item *item = &todo_list->items[j];
 			const char *arg = todo_list->buf.buf + item->arg_offset;
 
@@ -4232,7 +4232,7 @@ void todo_list_filter_update_refs(struct repository *r,
 	 * For each todo_item, check if its ref is in the update_refs list.
 	 * If not, then add it as an un-updated ref.
 	 */
-	for (i = 0; i < todo_list->total_nr; i++) {
+	for (i = 0; i < todo_list->nr; i++) {
 		struct todo_item *item = &todo_list->items[i];
 		const char *arg = todo_list->buf.buf + item->arg_offset;
 		int j, found = 0;
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Junio C Hamano
Message 2 of 11 in “Fix two rebase bugs related to total_nr”
  1. 0/2 Fix two rebase bugs related to total_nrJohannes Schindelin via GitGitGadget, May 10, 2023
  2. 1/2 rebase --update-refs: fix loopsJohannes Schindelin via GitGitGadget, May 10, 2023
  3. Junio C HamanoMay 10, 2023
  4. 2/2 rebase -r: fix the total number shown in the progressJohannes Schindelin via GitGitGadget, May 10, 2023
  5. Junio C HamanoMay 10, 2023
  6. Phillip WoodMay 11, 2023
  7. Junio C HamanoMay 11, 2023
  8. 0/2 Fix two rebase bugs related to total_nrJohannes Schindelin via GitGitGadget, May 13, 2023
  9. 1/2 rebase --update-refs: fix loopsJohannes Schindelin via GitGitGadget, May 13, 2023
  10. 2/2 rebase -r: fix the total number shown in the progressJohannes Schindelin via GitGitGadget, May 13, 2023
  11. Phillip WoodMay 14, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.