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

[PATCH v3 3/3] rebase -i: also avoid SHA-1 collisions with missingCommitsCheck

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 23, 2020, 12:28 UTC
Message-ID
<b7b063408f61abbbdf88b2dbf22e6274e75a31f8.1579782500.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.529.v3.git.1579782499.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

When `rebase.missingCommitsCheck` is in effect, we use the backup of the todo list that was copied just before the user was allowed to edit it.

That backup is, of course, just as susceptible to the hash collision as the todo list itself: a reworded commit could make a previously unambiguous short commit ID ambiguous all of a sudden.

So let's not just copy the todo list, but let's instead write out the backup with expanded commit IDs.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 rebase-interactive.c          | 8 +++++---
 t/t3404-rebase-interactive.sh | 2 ++
 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/rebase-interactive.c b/rebase-interactive.c
index aa18ae82b7..1259adc8ea 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -104,9 +104,11 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
 				    -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP))
 		return error_errno(_("could not write '%s'"), todo_file);
 
-	if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666))
-		return error(_("could not copy '%s' to '%s'."), todo_file,
-			     rebase_path_todo_backup());
+	if (initial &&
+	    todo_list_write_to_file(r, todo_list, rebase_path_todo_backup(),
+				    shortrevisions, shortonto, -1,
+				    (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)
+		return error(_("could not write '%s'."), rebase_path_todo_backup());
 
 	if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
 		return -2;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 1cc9f36bc7..b90ea0fe44 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -1277,6 +1277,8 @@ test_expect_success SHA1 'short SHA-1 collide' '
 			.git/rebase-merge/git-rebase-todo.tmp &&
 		grep "^pick [0-9a-f]\{40\}" \
 			.git/rebase-merge/git-rebase-todo &&
+		grep "^pick [0-9a-f]\{40\}" \
+			.git/rebase-merge/git-rebase-todo.backup &&
 		git rebase --continue
 	) &&
 	collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadget
Message 28 of 28 in “Re-fix rebase -i with SHA-1 collisions”
  1. 0/3 Re-fix rebase -i with SHA-1 collisionsJohannes Schindelin via GitGitGadget, Jan 16, 2020
  2. 1/3 parse_insn_line(): improve error message when parsing failedJohannes Schindelin via GitGitGadget, Jan 16, 2020
  3. Junio C HamanoJan 17, 2020
  4. 2/3 rebase -i: re-fix short SHA-1 collisionJohannes Schindelin via GitGitGadget, Jan 16, 2020
  5. Junio C HamanoJan 17, 2020
  6. Johannes SchindelinJan 17, 2020
  7. 3/3 rebase -i: also avoid SHA-1 collisions with missingCommitsCheckJohannes Schindelin via GitGitGadget, Jan 16, 2020
  8. brian m. carlsonJan 16, 2020
  9. Johannes SchindelinJan 17, 2020
  10. brian m. carlsonJan 17, 2020
  11. Junio C HamanoJan 21, 2020
  12. 0/3 Re-fix rebase -i with SHA-1 collisionsJohannes Schindelin via GitGitGadget, Jan 17, 2020
  13. 1/3 parse_insn_line(): improve error message when parsing failedJohannes Schindelin via GitGitGadget, Jan 17, 2020
  14. Junio C HamanoJan 21, 2020
  15. Johannes SchindelinJan 23, 2020
  16. 3/3 rebase -i: also avoid SHA-1 collisions with missingCommitsCheckJohannes Schindelin via GitGitGadget, Jan 17, 2020
  17. 2/3 rebase -i: re-fix short SHA-1 collisionJohannes Schindelin via GitGitGadget, Jan 17, 2020
  18. Eric SunshineJan 20, 2020
  19. Johannes SchindelinJan 20, 2020
  20. Eric SunshineJan 20, 2020
  21. Johannes SchindelinJan 21, 2020
  22. Junio C HamanoJan 21, 2020
  23. Johannes SchindelinJan 22, 2020
  24. Junio C HamanoJan 22, 2020
  25. 0/3 Re-fix rebase -i with SHA-1 collisionsJohannes Schindelin via GitGitGadget, Jan 23, 2020
  26. 1/3 parse_insn_line(): improve error message when parsing failedJohannes Schindelin via GitGitGadget, Jan 23, 2020
  27. 2/3 rebase -i: re-fix short SHA-1 collisionJohannes Schindelin via GitGitGadget, Jan 23, 2020
  28. 3/3 rebase -i: also avoid SHA-1 collisions with missingCommitsCheckJohannes Schindelin via GitGitGadget, Jan 23, 2020

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.