All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	Alban Gruin <alban.gruin@gmail.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v2 3/3] rebase -i: also avoid SHA-1 collisions with missingCommitsCheck
Date: Fri, 17 Jan 2020 23:38:03 +0000	[thread overview]
Message-ID: <486e9413a6b19d2695878fc19ffc49adabe3b00f.1579304283.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.529.v2.git.1579304283.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

  parent reply	other threads:[~2020-01-17 23:38 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 21:18 [PATCH 0/3] Re-fix rebase -i with SHA-1 collisions Johannes Schindelin via GitGitGadget
2020-01-16 21:18 ` [PATCH 1/3] parse_insn_line(): improve error message when parsing failed Johannes Schindelin via GitGitGadget
2020-01-17 18:00   ` Junio C Hamano
2020-01-16 21:18 ` [PATCH 2/3] rebase -i: re-fix short SHA-1 collision Johannes Schindelin via GitGitGadget
2020-01-17 18:30   ` Junio C Hamano
2020-01-17 21:31     ` Johannes Schindelin
2020-01-16 21:18 ` [PATCH 3/3] rebase -i: also avoid SHA-1 collisions with missingCommitsCheck Johannes Schindelin via GitGitGadget
2020-01-16 23:54 ` [PATCH 0/3] Re-fix rebase -i with SHA-1 collisions brian m. carlson
2020-01-17  9:51   ` Johannes Schindelin
2020-01-17 22:37     ` brian m. carlson
2020-01-21 18:00       ` Junio C Hamano
2020-01-17 23:38 ` [PATCH v2 " Johannes Schindelin via GitGitGadget
2020-01-17 23:38   ` [PATCH v2 1/3] parse_insn_line(): improve error message when parsing failed Johannes Schindelin via GitGitGadget
2020-01-21 22:04     ` Junio C Hamano
2020-01-23 12:26       ` Johannes Schindelin
2020-01-17 23:38   ` [PATCH v2 2/3] rebase -i: re-fix short SHA-1 collision Johannes Schindelin via GitGitGadget
2020-01-20 16:49     ` Eric Sunshine
2020-01-20 20:04       ` Johannes Schindelin
2020-01-20 20:08         ` Eric Sunshine
2020-01-21 11:49           ` Johannes Schindelin
2020-01-21 22:02           ` Junio C Hamano
2020-01-22 14:10             ` Johannes Schindelin
2020-01-22 18:15               ` Junio C Hamano
2020-01-17 23:38   ` Johannes Schindelin via GitGitGadget [this message]
2020-01-23 12:28   ` [PATCH v3 0/3] Re-fix rebase -i with SHA-1 collisions Johannes Schindelin via GitGitGadget
2020-01-23 12:28     ` [PATCH v3 1/3] parse_insn_line(): improve error message when parsing failed Johannes Schindelin via GitGitGadget
2020-01-23 12:28     ` [PATCH v3 2/3] rebase -i: re-fix short SHA-1 collision Johannes Schindelin via GitGitGadget
2020-01-23 12:28     ` [PATCH v3 3/3] rebase -i: also avoid SHA-1 collisions with missingCommitsCheck Johannes Schindelin via GitGitGadget

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

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

  git send-email \
    --in-reply-to=486e9413a6b19d2695878fc19ffc49adabe3b00f.1579304283.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=alban.gruin@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=sandals@crustytoothpaste.net \
    --cc=sunshine@sunshineco.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.