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

Re: [PATCH 4/5] Make sequencer abort safer

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 8, 2016, 17:27 UTC
Message-ID
<xmqqr35itjor.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<alpine.DEB.2.20.1612081627290.23160@virtualbox>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 14 quoted lines
> On Wed, 7 Dec 2016, Stephan Beyer wrote:
>
>> diff --git a/sequencer.c b/sequencer.c
>> index 30b10ba14..c9b560ac1 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -27,6 +27,7 @@ GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
>>  static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
>>  static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
>>  static GIT_PATH_FUNC(git_path_head_file, "sequencer/head")
>> +static GIT_PATH_FUNC(git_path_curr_file, "sequencer/current")
>
> Is it required by law to have a four-letter infix, or can we have a nicer
> variable name (e.g. git_path_current_file)?

I agree with you that, as other git_path_*_file variables match the actual name on the filesystem, this one should too, together with the update_curr_file() function.

By the way, this step seems to be a fix to an existing problem, and the new test added in 3/5 seems to be a demonstration of the issue. If that is the case, shouldn't the new test initially expect failure and updated by this step to expect success?

I'll queue this on top of step 4/5 as "SQUASH???" as usual. The other SQUASH??? that must come after 3/5 for t3510 should be trivial (the reverse of what appears here).

Thanks.
 sequencer.c                     | 22 +++++++++++-----------
 t/t3510-cherry-pick-sequence.sh |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index c9b560ac15..ce04377f8e 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -27,7 +27,7 @@ GIT_PATH_FUNC(git_path_seq_dir, "sequencer")
 static GIT_PATH_FUNC(git_path_todo_file, "sequencer/todo")
 static GIT_PATH_FUNC(git_path_opts_file, "sequencer/opts")
 static GIT_PATH_FUNC(git_path_head_file, "sequencer/head")
-static GIT_PATH_FUNC(git_path_curr_file, "sequencer/current")
+static GIT_PATH_FUNC(git_path_current_file, "sequencer/current")
 
 /*
  * A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
@@ -311,7 +311,7 @@ static int error_dirty_index(struct replay_opts *opts)
 	return -1;
 }
 
-static void update_curr_file()
+static void update_current_file(void)
 {
 	struct object_id head;
 
@@ -320,9 +320,9 @@ static void update_curr_file()
 		return;
 
 	if (!get_oid("HEAD", &head))
-		write_file(git_path_curr_file(), "%s", oid_to_hex(&head));
+		write_file(git_path_current_file(), "%s", oid_to_hex(&head));
 	else
-		write_file(git_path_curr_file(), "%s", "");
+		write_file(git_path_current_file(), "%s", "");
 }
 
 static int fast_forward_to(const unsigned char *to, const unsigned char *from,
@@ -354,7 +354,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
 	strbuf_release(&sb);
 	strbuf_release(&err);
 	ref_transaction_free(transaction);
-	update_curr_file();
+	update_current_file();
 	return 0;
 }
 
@@ -829,7 +829,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 
 leave:
 	free_message(commit, &msg);
-	update_curr_file();
+	update_current_file();
 
 	return res;
 }
@@ -1149,23 +1149,23 @@ static int save_head(const char *head)
 	return 0;
 }
 
-static int rollback_is_safe()
+static int rollback_is_safe(void)
 {
 	struct strbuf sb = STRBUF_INIT;
 	struct object_id expected_head, actual_head;
 
-	if (strbuf_read_file(&sb, git_path_curr_file(), 0) >= 0) {
+	if (strbuf_read_file(&sb, git_path_current_file(), 0) >= 0) {
 		strbuf_trim(&sb);
 		if (get_oid_hex(sb.buf, &expected_head)) {
 			strbuf_release(&sb);
-			die(_("could not parse %s"), git_path_curr_file());
+			die(_("could not parse %s"), git_path_current_file());
 		}
 		strbuf_release(&sb);
 	}
 	else if (errno == ENOENT)
 		oidclr(&expected_head);
 	else
-		die_errno(_("could not read '%s'"), git_path_curr_file());
+		die_errno(_("could not read '%s'"), git_path_current_file());
 
 	if (get_oid("HEAD", &actual_head))
 		oidclr(&actual_head);
@@ -1441,7 +1441,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 		return -1;
 	if (save_opts(opts))
 		return -1;
-	update_curr_file();
+	update_current_file();
 	res = pick_commits(&todo_list, opts);
 	todo_list_release(&todo_list);
 	return res;
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index efcd4fc485..372307c21b 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -147,7 +147,7 @@ test_expect_success '--abort to cancel single cherry-pick' '
 	git diff-index --exit-code HEAD
 '
 
-test_expect_failure '--abort does not unsafely change HEAD' '
+test_expect_success '--abort does not unsafely change HEAD' '
 	pristine_detach initial &&
 	test_must_fail git cherry-pick picked anotherpick &&
 	git reset --hard base &&
Previous: Johannes SchindelinNext: Stephan Beyer
Message 4 of 18 in “am: Fix filename in safe_to_abort() error message”
  1. 1/5 am: Fix filename in safe_to_abort() error messageStephan Beyer, Dec 7, 2016
  2. 4/5 Make sequencer abort saferStephan Beyer, Dec 7, 2016
  3. Johannes SchindelinDec 8, 2016
  4. Junio C HamanoDec 8, 2016
  5. Stephan BeyerDec 8, 2016
  6. Junio C HamanoDec 9, 2016
  7. 1/5 am: Fix filename in safe_to_abort() error messageStephan Beyer, Dec 9, 2016
  8. 3/5 Add test that cherry-pick --abort does not unsafely change HEADStephan Beyer, Dec 9, 2016
  9. 2/5 am: Change safe_to_abort()'s not rewinding error into a warningStephan Beyer, Dec 9, 2016
  10. 4/5 Make sequencer abort saferStephan Beyer, Dec 9, 2016
  11. Christian CouderDec 10, 2016
  12. Jeff KingDec 10, 2016
  13. Stephan BeyerDec 10, 2016
  14. 5/5 sequencer: Remove useless get_dir() functionStephan Beyer, Dec 9, 2016
  15. 2/5 am: Change safe_to_abort()'s not rewinding error into a warningStephan Beyer, Dec 7, 2016
  16. 3/5 Add test that cherry-pick --abort does not unsafely change HEADStephan Beyer, Dec 7, 2016
  17. 5/5 sequencer: Remove useless get_dir() functionStephan Beyer, Dec 7, 2016
  18. Paul TanDec 8, 2016

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.