threads / patch / 17367

patchReintegrate script

Subject: [PATCH] Reintegrate script

## tl;dr

3 messages between Jan 26, 2009 and Feb 13, 2009. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Junio C Hamano· Jan 26, 2009, 09:03 UTC · lore

In a workflow that uses topic branches heavily, you would need to keep updating test integration branch(es) all the time. If they are managed like my 'next' by merging the tips of topics that have grown since the last integration, it is not so difficult. You only need to review output from "git branch --no-merged next" to see if there are topics that can and needs to be merged to 'next'.

But sometimes it is easier to rebuild a test integration branch from scratch all the time, especially if you do not publish it for others to build on.

I've been using this script for some time to rebuild jch and pu branches in my workflow. jch's tip is supposed to always match 'next', but it is rebuilt from scratch on top of 'master' by merging the same topics that are in 'next'. You can use the same script in your work.

To use it, you give a commit range base..tip to the script, and you will see a shell script that uses a series of 'git-merge'. "base" is the more stable branch that you rebuild your test integration branch on top (in my case, 'master'), and "tip" is where the tip of the test integration branch is from the last round (in my case, 'jch' or 'pu').

Then you can run the resulting script, fix conflicted merge and use 'git-commit', and then repeat until all the branches are re-integrated on top of the base branch.

    $ Meta/Reintegrate master..jch >/var/tmp/redo-jch.sh
    $ cat /var/tmp/redo-jch.sh
    #!/bin/sh
    while read branch eh
    do
	    case "$eh" in
	    "") git merge "$branch" || break ;;
	    ?*) echo >&2 "Eh? $branch $eh"; break ;;
	    esac
    done <<EOF
    jc/blame
    js/notes
    ks/maint-mailinfo-folded~3
    tr/previous-branch
    EOF
    $ git checkout jch
    $ git reset --hard master
    $ /var/tmp/redo-jch.sh
    ... if there is conflict, resolve, "git commit" here ...
    $ /var/tmp/redo-jch.sh
    ... repeat until everything is applied.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This is taken from my 'todo' branch, which I keep a checkout in Meta/
   directory.
 Reintegrate |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
 create mode 100755 Reintegrate
Show changes to Reintegrate +42 −0
diff --git a/Reintegrate b/Reintegrate
new file mode 100755
index 0000000..dfdb73e
--- /dev/null
+++ b/Reintegrate
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+merge_msg="Merge branch '\(.*\)'"
+x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
+x40="$x40$x40$x40$x40$x40$x40$x40$x40"
+LF='
+'
+
+echo '#!/bin/sh
+while read branch eh
+do
+	case "$eh" in
+	"") git merge "$branch" || break ;;
+	?*) echo >&2 "Eh? $branch $eh"; break ;;
+	esac
+done <<EOF'
+
+git log --pretty=oneline --first-parent "$1" |
+{
+	series=
+	while read commit msg
+	do
+		other=$(git rev-parse --verify "$commit^2") &&
+		branch=$(expr "$msg" : "$merge_msg") &&
+		tip=$(git rev-parse --verify "refs/heads/$branch" 2>/dev/null) &&
+		merged=$(git name-rev --refs="refs/heads/$branch" "$other" 2>/dev/null) &&
+		merged=$(expr "$merged" : "$x40 \(.*\)") &&
+		test "$merged" != undefined || {
+			other=$(git log -1 --pretty='format:%s' $other) &&
+			merged="$branch :rebased? $other"
+		}
+		if test -z "$series"
+		then
+			series="$merged"
+		else
+			series="$merged$LF$series"
+		fi
+	done
+	echo "$series"
+}
+
+echo 'EOF'
-- 
1.6.1.1.248.g7f6d2
Johannes Schindelin· Jan 26, 2009, 11:18 UTC · re: Junio C Hamano · lore

Re: [PATCH] Reintegrate script

Hi,
On Mon, 26 Jan 2009, Junio C Hamano wrote:
Show 10 quoted lines
> In a workflow that uses topic branches heavily, you would need to keep 
> updating test integration branch(es) all the time.  If they are managed 
> like my 'next' by merging the tips of topics that have grown since the 
> last integration, it is not so difficult.  You only need to review 
> output from "git branch --no-merged next" to see if there are topics 
> that can and needs to be merged to 'next'.
> 
> But sometimes it is easier to rebuild a test integration branch from
> scratch all the time, especially if you do not publish it for others to
> build on.
FWIW that is exactly what I am aiming at with my rebase -i -p work.

Ciao, Dscho

Bernt Hansen· Feb 13, 2009, 18:23 UTC · re: Junio C Hamano · lore

[PATCH] Meta/Reintegrate: Record all merges to prevent losing topics

Rebuilding an integration branch loses the initial topics when merging results in fast-forwarding the history.

Force the integration branch to always record merge commits to ensure we keep all of the topics on future integration branch rebuilds.

Signed-off-by: Bernt Hansen <bernt@norang.ca>
---
Thanks for this script Junio!

I started using this script today to clean up one of my integration branches by separating the linear history into separate topics. This works great except for the minor glitch this patch fixes.

 Reintegrate |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to Reintegrate +1 −1
diff --git a/Reintegrate b/Reintegrate
index dfdb73e..5909821 100755
--- a/Reintegrate
+++ b/Reintegrate
@@ -10,7 +10,7 @@ echo '#!/bin/sh
 while read branch eh
 do
 	case "$eh" in
-	"") git merge "$branch" || break ;;
+	"") git merge --no-ff "$branch" || break ;;
 	?*) echo >&2 "Eh? $branch $eh"; break ;;
 	esac
 done <<EOF'
-- 
1.6.2.rc0.55.g30aa4f

← back to recent threads