Skip to contentSkip to conversation

tg-push: prevent multiple occurences of branches

PATCH Superseded Bert Wesarg 2 participants 3 messages Jun 15, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tg-push: prevent multiple occurences of branches

So, I finally tried tg-push and got a lot of warnings and errors:

warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master

error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/bw/log is at a16df35cc7009b36f6f71717ae3d9a3dc29987da but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/bw/log
error: Ref refs/top-bases/bw/log is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/top-bases/bw/log

! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] bw/log -> bw/log (failed to lock)
! [remote rejected] refs/top-bases/bw/log -> refs/top-bases/bw/log (failed to lock)

Also the result was ok this output is defintive not ok.

To prevent multiple occurences of the same branchname we maintain these in a file.

In push_branch ref_exists was called, which is redundant because _dep_is_tgish tells us exactly this.

Regards,
Bert

---
 tg-push.sh |   48 +++++++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 19 deletions(-)
tg-push.sh +29 -19
index 8d09a02..c813927 100644
@@ -45,31 +45,41 @@ for name in $branches; do
 	ref_exists "$name" || die "detached HEAD? Can't push $name"
 done
 
+_listfile="$(mktemp -t tg-push-listfile.XXXXXX)"
+trap "rm -f \"$_listfile\"" 0
+
+# prevent multiple occurrences of the same branch
+add_to_list()
+{
+	fgrep -qx "$1" "$_listfile" ||
+		echo "$1" >> "$_listfile"
+}
+
 push_branch()
 {
 	# if so desired omit non tgish deps
 	$tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
 
-	echo "$_dep"
-	local base="top-bases/$_dep"
-	if ref_exists "$base"; then
-		echo "top-bases/$_dep"
-	else
-		echo "warning, no base found $base" 1>&2
-	fi
+	add_to_list "$_dep"
+	[ -z "$_dep_is_tgish" ] ||
+		add_to_list "top-bases/$_dep"
 }
 
 for name in $branches; do
-	list="$(
-		# deps
-		if $recurse_deps; then
-			no_remotes=1 recurse_deps push_branch "$name"
-		fi
-		# current branch
-		_dep="$name"
-		_dep_is_tgish=1
-		push_branch "$name"
-	)"
-	echo "pushing:"; echo $list
-	git push $dry_run "$remote" $list
+	# current branch
+	# re-use push_branch, which expects some pre-defined variables
+	_dep="$name"
+	_dep_is_tgish=1
+	ref_exists "top-bases/$_dep" ||
+		_dep_is_tgish=
+	push_branch "$name"
+
+	# deps
+	$recurse_deps &&
+		no_remotes=1 recurse_deps push_branch "$name"
+
+	cat "$_listfile" |
+		sed '1{ s/^/Pushing: /; n; }; s/^/         /;'
+
+	cat "$_listfile" | xargs git push $dry_run "$remote"
 done
Signature · 1 line
tg: (b725fc9..) bw/push-fixes (depends on: master)
#1 lore raw

Hi Bert,

Quoted 40 lines · Bert Wesarg

So, I finally tried tg-push and got a lot of warnings and errors:

warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master

error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/bw/log is at a16df35cc7009b36f6f71717ae3d9a3dc29987da but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/bw/log
error: Ref refs/top-bases/bw/log is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/top-bases/bw/log

Quoted 12 lines

! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] master -> master (failed to lock)
! [remote rejected] bw/log -> bw/log (failed to lock)
! [remote rejected] refs/top-bases/bw/log -> refs/top-bases/bw/log (failed to lock)

hhm, does this happen because

git push $remote master master master master

tries to lock master four times? I'd think this is something that needs fixing in git-core.

Quoted 7 lines

Also the result was ok this output is defintive not ok.

To prevent multiple occurences of the same branchname we maintain these in a file.

In push_branch ref_exists was called, which is redundant because _dep_is_tgish tells us exactly this.

... what about breaking this out?

Quoted 11 lines
---
 tg-push.sh |   48 +++++++++++++++++++++++++++++-------------------
 1 files changed, 29 insertions(+), 19 deletions(-)
tg-push.sh +0 -0
index 8d09a02..c813927 100644
@@ -45,31 +45,41 @@ for name in $branches; do
 	ref_exists "$name" || die "detached HEAD? Can't push $name"
 done

tg-push.sh for name in $branches; do · line 56

Quoted 10 lines
tg-push.sh +9 -0
 
+_listfile="$(mktemp -t tg-push-listfile.XXXXXX)"
+trap "rm -f \"$_listfile\"" 0
+
+# prevent multiple occurrences of the same branch
+add_to_list()
+{
+	fgrep -qx "$1" "$_listfile" ||
+		echo "$1" >> "$_listfile"
+}

This has complexity O(n**2) for n calls (I think). Just writing then to the list and doing sort -u afterwards only has O(n log n) (for a reasonable implementation of sort).

tg-push.sh for name in $branches; do · line 53

Quoted 6 lines
tg-push.sh +0 -1
 push_branch()
 {
 	# if so desired omit non tgish deps
 	$tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
 
-	echo "$_dep"

what about $tgish_deps_only?

tg-push.sh for name in $branches; do · line 65

Quoted 9 lines
tg-push.sh +3 -6
-	local base="top-bases/$_dep"
-	if ref_exists "$base"; then
-		echo "top-bases/$_dep"
-	else
-		echo "warning, no base found $base" 1>&2
-	fi
+	add_to_list "$_dep"
+	[ -z "$_dep_is_tgish" ] ||
+		add_to_list "top-bases/$_dep"

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#2 lore raw

2009/5/27 Uwe Kleine-König <[email protected]>:

Quoted 1 line

Hi Bert,

Moin Uwe,

Quoted 54 lines · Bert Wesarg
Quoted 40 lines

So, I finally tried tg-push and got a lot of warnings and errors:

warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master
warning, no base found top-bases/master

error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/master is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/master
error: Ref refs/heads/bw/log is at a16df35cc7009b36f6f71717ae3d9a3dc29987da but expected 0000000000000000000000000000000000000000
error: failed to lock refs/heads/bw/log
error: Ref refs/top-bases/bw/log is at b725fc951a37854fc65945ac5bcab3bc61ccbd94 but expected 0000000000000000000000000000000000000000
error: failed to lock refs/top-bases/bw/log

Quoted 12 lines

 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] master -> master (failed to lock)
 ! [remote rejected] bw/log -> bw/log (failed to lock)
 ! [remote rejected] refs/top-bases/bw/log -> refs/top-bases/bw/log (failed to lock)

Quoted 3 lines

hhm, does this happen because

       git push $remote master master master master

Exactly.

Quoted 3 lines

tries to lock master four times?  I'd think this is something that needs fixing in git-core.

Cc'd Junio. And Junio, you can stop reading now.

Quoted 9 lines
Quoted 8 lines

Also the result was ok this output is defintive not ok.

To prevent multiple occurences of the same branchname we maintain these in a file.

In push_branch ref_exists was called, which is redundant because _dep_is_tgish tells us exactly this.

... what about breaking this out?

By your command.

Quoted 13 lines
Quoted 13 lines

---
 tg-push.sh |   48 +++++++++++++++++++++++++++++-------------------

 1 files changed, 29 insertions(+), 19 deletions(-)
tg-push.sh +0 -0
index 8d09a02..c813927 100644
@@ -45,31 +45,41 @@ for name in $branches; do

      ref_exists "$name" || die "detached HEAD? Can't push $name" done

Quoted 12 lines

tg-push.sh for name in $branches; do · line 56

Quoted 9 lines
tg-push.sh +9 -0
+_listfile="$(mktemp -t tg-push-listfile.XXXXXX)"
+trap "rm -f \"$_listfile\"" 0
+
+# prevent multiple occurrences of the same branch
+add_to_list()
+{
+     fgrep -qx "$1" "$_listfile" ||
+             echo "$1" >> "$_listfile"
+}

This has complexity O(n**2) for n calls (I think).  Just writing then to the list and doing sort -u afterwards only has O(n log n) (for a reasonable implementation of sort).

Ahh, that takes a while, but yes. I thought I need to sort each time I put a new branch in this file.

Quoted 8 lines
Quoted 7 lines

 push_branch()
 {

      # if so desired omit non tgish deps
      $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0

-     echo "$_dep"

what about $tgish_deps_only?

Hmm, I think I have not changed the semantics here. I replace this line with 'add_to_list "$_dep"'.

Quoted 10 lines
Quoted 9 lines

-     local base="top-bases/$_dep"
-     if ref_exists "$base"; then
-             echo "top-bases/$_dep"
-     else
-             echo "warning, no base found $base" 1>&2
-     fi
+     add_to_list "$_dep"
+     [ -z "$_dep_is_tgish" ] ||
+             add_to_list "top-bases/$_dep"

Bert

Quoted 2 lines

Best regards
Uwe