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

Re: [PATCH v2] contrib/rerere-train: optionally overwrite existing resolutions

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 26, 2017, 18:05 UTC
Message-ID
<xmqqmv7rrs45.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<ae4d9b77-c47e-199b-d40f-ad5b49c5dd60@gmail.com>
Raman Gupta <rocketraman@gmail.com> writes:
Show 32 quoted lines
> Provide the user an option to overwrite existing resolutions using an
> `--overwrite` flag. This might be used, for example, if the user knows
> that they already have an entry in their rerere cache for a conflict,
> but wish to drop it and retrain based on the merge commit(s) passed to
> the rerere-train script.
>
> Signed-off-by: Raman Gupta <rocketraman@gmail.com>
> ---
>  contrib/rerere-train.sh | 36 ++++++++++++++++++++++++++++++++++--
>  1 file changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/contrib/rerere-train.sh b/contrib/rerere-train.sh
> index 52ad9e4..e25bf8a 100755
> --- a/contrib/rerere-train.sh
> +++ b/contrib/rerere-train.sh
> @@ -3,10 +3,38 @@
>  # Prime rerere database from existing merge commits
>  
>  me=rerere-train
> -USAGE="$me rev-list-args"
>  
>  SUBDIRECTORY_OK=Yes
> -OPTIONS_SPEC=
> +OPTS_SPEC="\
> +$me [--overwrite] <rev-list-args>
> +--
> +h,help        show the help
> +o,overwrite   overwrite any existing rerere cache
> +"
> +eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
> +
> +overwrite=0

It is very good that you initialize overwrite explicitly here, to prevent it from seeping through from the caller's environment.

Show 19 quoted lines
> +while test $# -gt 0
> +do
> +	opt="$1"
> +	case "$opt" in
> +	-o)
> +		overwrite=1
> +		shift
> +		shift
> +		;;
> +	--)
> +		shift
> +		break
> +		;;
> +	*)
> +		break
> +		exit 1
> +		;;
> +	esac
> +done

I haven't tried this patch, but would this work well with options meant for the 'git rev-list --parents "$@"' that grabs the list of merge commits to learn from? e.g.

	$ contrib/rerere-train.sh -n 4 --merges master
	$ contrib/rerere-train.sh --overwrite -n 4 --merges master
	$ contrib/rerere-train.sh -n 4 --overwrite --merges master

I do not think it is necessary to make the last one work; as long as the first two work as expected, we are good even if the last one dies with a sensible message e.g. "options X, Y and Z must be given before other options" (currently "X, Y and Z" consists only of "--overwrite", but I think you get what I mean).

Show 8 quoted lines
>  . "$(git --exec-path)/git-sh-setup"
>  require_work_tree
>  cd_to_toplevel
> @@ -34,6 +62,10 @@ do
>  		# Cleanly merges
>  		continue
>  	fi
> +	if [ $overwrite == 1 ]
	if test "$overwrite" = 1
cf. Documentation/CodingGuidelines.
Show 6 quoted lines
> +	then
> +		git rerere forget .
> +	fi
>  	if test -s "$GIT_DIR/MERGE_RR"
>  	then
>  		git show -s --pretty=format:"Learning from %h %s" "$commit"
Previous: Raman GuptaNext: Raman Gupta
Message 4 of 8 in “contrib: rerere-train overwrites existing resolutions”
  1. contrib: rerere-train overwrites existing resolutionsRaman Gupta, Jul 25, 2017
  2. Junio C HamanoJul 25, 2017
  3. contrib/rerere-train: optionally overwrite existing resolutionsRaman Gupta, Jul 25, 2017
  4. Junio C HamanoJul 26, 2017
  5. Raman GuptaJul 26, 2017
  6. Junio C HamanoJul 26, 2017
  7. Raman GuptaJul 28, 2017
  8. contrib/rerere-train: optionally overwrite existing resolutionsRaman Gupta, Jul 26, 2017

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.