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

Re: [RFC] rebase: Handle cases where format-patch fails

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 5, 2012, 20:17 UTC
Message-ID
<7vipaou0zw.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1349412790-6087-2-git-send-email-andrew.kw.w@gmail.com>
Andrew Wong <andrew.kw.w@gmail.com> writes:
Show 29 quoted lines
> 'format-patch' could fail due to reasons such as out of memory. Such
> failures are not detected or handled, which causes rebase to incorrectly
> think that it completed successfully and continue with cleanup. i.e.
> calling move_to_original_branch
>
> Since only the exit status of the last command in the pipeline is
> available, we rely on || to detect whether 'format-patch' has failed.
>
> Also print messages to help user with how to recover from such failures.
>
> Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
> ---
>  git-rebase--am.sh | 37 +++++++++++++++++++++++++++++++++++--
>  1 file changed, 35 insertions(+), 2 deletions(-)
>
> diff --git a/git-rebase--am.sh b/git-rebase--am.sh
> index 392ebc9..8dae804 100644
> --- a/git-rebase--am.sh
> +++ b/git-rebase--am.sh
> @@ -26,10 +26,43 @@ then
>  	# makes this easy
>  	git cherry-pick --allow-empty "$revisions"
>  else
> -	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
> +	( git format-patch -k --stdout --full-index --ignore-if-in-upstream \
>  		--src-prefix=a/ --dst-prefix=b/ \
> -		--no-renames $root_flag "$revisions" |
> +		--no-renames $root_flag "$revisions" ||
> +		echo $? > "$GIT_DIR"/format-patch-failed ) |

Please make sure there is no marker-file that was leftover from previous invocation or whatever reason, e.g.

	rm -f "$GIT_DIR/format-patch-failed"
        (
		git format-patch -k --stdout --full-index --ignore-if-in-upstream \
			--src-prefix=a/ --dst-prefix=b/ \
			--no-renames $root_flag "$revisions" ||
		echo $? >"$GIT_DIR"/format-patch-failed
	) |
  	git am $git_am_opt --rebasing --resolvemsg="$resolvemsg"

But when format-patch dies for whatever reason, it is likely that the partial output will cause "am" to barf on the last part of it (either "missing patch text" if it stops in the middle of commit log message, or "corrupt patch" if it stops in the middle of a hunk). It may make sense to make this all-or-none, i.e. when format-patch fails, you do not even start "am", something like...

	rm -f "$GIT_DIR/patch-input"
        if ! git format-patch -k --stdout >"$GIT_DIR/patch-input" \
	        --full-index --ignore-if-in-upstream \
		--src-prefix=a/ --dst-prefix=b/ \
		--no-renames $root_flag "$revisions"
	then
		... format-patch barfed, here is how to deal with it...
	else
        	git am <"$GIT_DIR/patch-input" $git_am_opt ...
	fi
	rm -f "$GIT_DIR/patch-input"
but I wonder what the performance implication would be for normal cases.
Show 35 quoted lines
> +	ret=$?
> +	if test -f "$GIT_DIR"/format-patch-failed
> +	then
> +		ret=1
> +		rm -f "$GIT_DIR"/format-patch-failed
> +		if test -d "$state_dir"
> +		then
> +			echo
> +			echo "'git format-patch' seems to have failed in the middle of 'git am'."
> +			echo "If you continue rebasing, you will likely be losing some commits."
> +			echo "It is recommended that you abort rebasing by running:"
> +			echo
> +			echo "    git rebase --abort"
> +			echo
> +		else
> +			echo
> +			echo "'git format-patch' seems to have failed before 'git am' started."
> +			echo "It is impossible to continue or abort rebasing."
> +			echo "You have to use the following to return to your original head:"
> +			echo
> +			case "$head_name" in
> +			refs/*)
> +				echo "    git checkout $head_name"
> +				;;
> +			*)
> +				echo "    git checkout $orig_head"
> +				;;
> +			esac
> +			echo
> +		fi
> +	fi
> +	test 0 != $ret && false
>  fi && move_to_original_branch
>  
>  ret=$?
Previous: Andrew WongNext: Andrew Wong
Message 10 of 17 in “Rebase doesn't restore branch pointer back on out of memory”
  1. Alexander KostikovOct 3, 2012
  2. Andrew WongOct 3, 2012
  3. Andrew WongOct 4, 2012
  4. Alexander KostikovOct 4, 2012
  5. Alexander KostikovOct 4, 2012
  6. Andrew WongOct 4, 2012
  7. Alexander KostikovOct 4, 2012
  8. Andrew WongOct 5, 2012
  9. [RFC] rebase: Handle cases where format-patch failsAndrew Wong, Oct 5, 2012
  10. Junio C HamanoOct 5, 2012
  11. Andrew WongOct 8, 2012
  12. [RFC] rebase: Handle cases where format-patch failsAndrew Wong, Oct 8, 2012
  13. Junio C HamanoOct 8, 2012
  14. Andrew WongOct 11, 2012
  15. rebase: Handle cases where format-patch failsAndrew Wong, Oct 11, 2012
  16. Alexander KostikovOct 19, 2012
  17. Junio C HamanoOct 19, 2012

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.