Skip to contentSkip to conversation

contrib: rerere-train overwrites existing resolutions

PATCH/RFC Superseded Raman Gupta 2 participants 8 messages Jul 25, 2017 – Jul 28, 2017

lore
Share & tools
lore
#0 lore raw

From 41116889f7eb2ddd590d165d9ca89646f7b15aaf Mon Sep 17 00:00:00 2001
From: Raman Gupta <[email protected]>
Date: Tue, 25 Jul 2017 10:28:35 -0400
Subject: [PATCH] contrib: rerere-train overwrites existing resolutions

When running rerere-train, the user is explicitly asking the training to occur based on the current merge commit. However, if the current cache has a resolution for the same conflict (even if out of date or wrong), rerere-train does not currently update the rr-cache. Now, forget existing resolutions before training so that training is always reflective of the trained data.

---
 contrib/rerere-train.sh | 1 +
 1 file changed, 1 insertion(+)
contrib/rerere-train.sh +1 -0
index 52ad9e4..a222d38 100755
@@ -34,6 +34,7 @@ do
 		# Cleanly merges
 		continue
 	fi
+	git rerere forget .
 	if test -s "$GIT_DIR/MERGE_RR"
 	then
 		git show -s --pretty=format:"Learning from %h %s" "$commit"
Signature · 1 line
2.9.4
#1 lore raw
Quoted 4 lines · Raman Gupta

From 41116889f7eb2ddd590d165d9ca89646f7b15aaf Mon Sep 17 00:00:00 2001
From: Raman Gupta <[email protected]>
Date: Tue, 25 Jul 2017 10:28:35 -0400
Subject: [PATCH] contrib: rerere-train overwrites existing resolutions

These do not belong to the body of the message.

Imagine that your title line appears in "git shortlog --no-merges" output together with 600 other commits, and you see that list 3 months later. Can you tell what this change was about?

To me, it sounds like a user is complaining that it overwrites and loses a precious one, implying that the change is to fix it by being more careful, i.e. checking if there is an existing one and avoid overwriting it.

As our convention is to write the log message as if you are giving an order to the codebase "to behave like so",

contrib/rerere-train: overwrite existing resolutions

would convey what you are doing better, I would think.

As to the change itself, I do anticipate that a user who is used to rerere-train will complain that the updated one overwrites existing resolutions, losing data, as the existing one didn't, and they are used to the way to correct an incorrect resolution that is recorded earlier, which is:

* perform the botched merge again, which will materialize the botched merge result in the working tree;

* do "git rerere forget" for the path;

* correct the path with the right merge result; and then finally

* do "git rerere".

If this new behaviour is triggered only when a command line option is given (e.g. "--overwrite" which is better than "--force"), I would imagine that it might give us an easier way to achieve the same thing without learning about "rerere forget". So I do not fundamentally oppose to having such an option, but changing the default behaviour is not going to fly.

Quoted 7 lines

When running rerere-train, the user is explicitly asking the training to occur based on the current merge commit. However, if the current cache has a resolution for the same conflict (even if out of date or wrong), rerere-train does not currently update the rr-cache. Now, forget existing resolutions before training so that training is always reflective of the trained data.
---

Actually, the user is asking to record what is not recorded yet, which is the originally intended use case. You may fetch my 'pu' branch into a repository you already have a copy of git.git, and want to grab conflict resolutions I did between master..pu that you still do not know about. The tool is conservative and avoids clobbering your resolution if you already have resolved some of the merges yourself.

In any case, please make it a habit to sign-off your work when posting here.

Quoted 15 lines
 contrib/rerere-train.sh | 1 +
 1 file changed, 1 insertion(+)
contrib/rerere-train.sh +1 -0
index 52ad9e4..a222d38 100755
@@ -34,6 +34,7 @@ do
 		# Cleanly merges
 		continue
 	fi
+	git rerere forget .
 	if test -s "$GIT_DIR/MERGE_RR"
 	then
 		git show -s --pretty=format:"Learning from %h %s" "$commit"
#2 lore raw

PATCH v2 1/1 contrib/rerere-train: optionally overwrite existing resolutions

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.

---
 contrib/rerere-train.sh | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
contrib/rerere-train.sh +34 -2
index 52ad9e4..e25bf8a 100755
@@ -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
+
+while test $# -gt 0
+do
+	opt="$1"
+	case "$opt" in
+	-o)
+		overwrite=1
+		shift
+		shift
+		;;
+	--)
+		shift
+		break
+		;;
+	*)
+		break
+		exit 1
+		;;
+	esac
+done
+
 . "$(git --exec-path)/git-sh-setup"
 require_work_tree
 cd_to_toplevel
@@ -34,6 +62,10 @@ do
 		# Cleanly merges
 		continue
 	fi
+	if [ $overwrite == 1 ]
+	then
+		git rerere forget .
+	fi
 	if test -s "$GIT_DIR/MERGE_RR"
 	then
 		git show -s --pretty=format:"Learning from %h %s" "$commit"
Signature · 1 line
2.9.4
#3 lore raw

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

Quoted 22 lines · Raman Gupta

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.

---
 contrib/rerere-train.sh | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)
contrib/rerere-train.sh +0 -1
index 52ad9e4..e25bf8a 100755
@@ -3,10 +3,38 @@
 # Prime rerere database from existing merge commits
 
 me=rerere-train
-USAGE="$me rev-list-args"
 
 SUBDIRECTORY_OK=Yes

contrib/rerere-train.sh line 16

Quoted 10 lines
contrib/rerere-train.sh +9 -1
-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.

Quoted 9 lines
contrib/rerere-train.sh +9 -0
+while test $# -gt 0
+do
+	opt="$1"
+	case "$opt" in
+	-o)
+		overwrite=1
+		shift
+		shift
+		;;

contrib/rerere-train.sh line 36

Quoted 10 lines
contrib/rerere-train.sh +10 -0
+	--)
+		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).

contrib/rerere-train.sh do · line 65

Quoted 8 lines
contrib/rerere-train.sh +1 -0
 . "$(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.

Quoted 6 lines
contrib/rerere-train.sh +3 -0
+	then
+		git rerere forget .
+	fi
 	if test -s "$GIT_DIR/MERGE_RR"
 	then
 		git show -s --pretty=format:"Learning from %h %s" "$commit"
#4 lore raw

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

Quoted 8 lines · Junio C Hamano

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
Quoted 5 lines

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

You're right -- I didn't try all the cases. I wasn't able to figure out how to get rev-parse --parseopt to deal with this situation, so I did it manually. I'm not super-happy with the result, but it does work. Look for PATCH v3.

Regards,
Raman

#5 lore raw

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

Quoted 15 lines · Raman Gupta
Quoted 8 lines · Junio C Hamano

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
Quoted 5 lines

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

Quoted 4 lines

You're right -- I didn't try all the cases. I wasn't able to figure out how to get rev-parse --parseopt to deal with this situation, so I did it manually. I'm not super-happy with the result, but it does work. Look for PATCH v3.

Yes, I think you could squash the two case arms in the later loop into one i.e.

	-h|--help|-o|--overwrite)
		die "please don't." ;;

but still the repetition does look ugly.

As a contrib/ material, I do not care too deeply about it, though.

Will queue.

#6 lore raw

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

Quoted 22 lines · Junio C Hamano
Quoted 15 lines · Raman Gupta
Quoted 8 lines · Junio C Hamano

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
Quoted 5 lines

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

Quoted 4 lines

You're right -- I didn't try all the cases. I wasn't able to figure out how to get rev-parse --parseopt to deal with this situation, so I did it manually. I'm not super-happy with the result, but it does work. Look for PATCH v3.

Quoted 5 lines

Yes, I think you could squash the two case arms in the later loop into one i.e.

	-h|--help|-o|--overwrite)
		die "please don't." ;;

I considered that but decided the non-collapsed version better supports this list growing in the future.

Quoted 1 line

but still the repetition does look ugly.

Agreed.

Quoted 3 lines

As a contrib/ material, I do not care too deeply about it, though.

Will queue.

Thanks.

Regards,
Raman

#7 lore raw

PATCH v3 1/1 contrib/rerere-train: optionally overwrite existing resolutions

In reply to Junio C Hamano

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.

---
 contrib/rerere-train.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 52 insertions(+), 2 deletions(-)
contrib/rerere-train.sh +52 -2
index 52ad9e4..eeee45d 100755
@@ -3,10 +3,56 @@
 # Prime rerere database from existing merge commits
 
 me=rerere-train
-USAGE="$me rev-list-args"
+USAGE=$(cat <<-EOF
+usage: $me [--overwrite] <rev-list-args>
+
+    -h, --help            show the help
+    -o, --overwrite       overwrite any existing rerere cache
+EOF
+)
 
 SUBDIRECTORY_OK=Yes
-OPTIONS_SPEC=
+
+overwrite=0
+
+while test $# -gt 0
+do
+	opt="$1"
+	case "$opt" in
+	-h|--help)
+		echo "$USAGE"
+		exit 0
+		;;
+	-o|--overwrite)
+		overwrite=1
+		shift
+		break
+		;;
+	--)
+		shift
+		break
+		;;
+	*)
+		break
+		;;
+	esac
+done
+
+# Overwrite or help options are not valid except as first arg
+for opt in "$@"
+do
+	case "$opt" in
+	-h|--help)
+		echo "$USAGE"
+		exit 0
+		;;
+	-o|--overwrite)
+		echo "$USAGE"
+		exit 0
+		;;
+	esac
+done
+
 . "$(git --exec-path)/git-sh-setup"
 require_work_tree
 cd_to_toplevel
@@ -34,6 +80,10 @@ do
 		# Cleanly merges
 		continue
 	fi
+	if test $overwrite = 1
+	then
+		git rerere forget .
+	fi
 	if test -s "$GIT_DIR/MERGE_RR"
 	then
 		git show -s --pretty=format:"Learning from %h %s" "$commit"
Signature · 1 line
2.9.4