public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Raman Gupta <rocketraman@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH v2] contrib/rerere-train: optionally overwrite existing resolutions
Date: Wed, 26 Jul 2017 11:05:30 -0700	[thread overview]
Message-ID: <xmqqmv7rrs45.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <ae4d9b77-c47e-199b-d40f-ad5b49c5dd60@gmail.com> (Raman Gupta's message of "Tue, 25 Jul 2017 18:48:12 -0400")

Raman Gupta <rocketraman@gmail•com> writes:

> 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.

> +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).

>  . "$(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.

> +	then
> +		git rerere forget .
> +	fi
>  	if test -s "$GIT_DIR/MERGE_RR"
>  	then
>  		git show -s --pretty=format:"Learning from %h %s" "$commit"

  reply	other threads:[~2017-07-26 18:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-25 14:34 [PATCH/RFC] contrib: rerere-train overwrites existing resolutions Raman Gupta
2017-07-25 21:18 ` Junio C Hamano
2017-07-25 22:48   ` [PATCH v2] contrib/rerere-train: optionally overwrite " Raman Gupta
2017-07-26 18:05     ` Junio C Hamano [this message]
2017-07-26 19:06       ` Raman Gupta
2017-07-26 20:41         ` Junio C Hamano
2017-07-28 18:40           ` Raman Gupta
2017-07-26 19:08       ` [PATCH v3] " Raman Gupta

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=xmqqmv7rrs45.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=rocketraman@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox