[TopGit PATCH] tg-create.sh: Introduce --add option to add a dependency.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This implements 

    tg create --add DEP

to add dependency DEP to an already existing topgit branch.

The bad thing is that this does not play well with tg undepend;
it won't work to re-add a previously removed dependency.  This
--add is implemented as a merge, and all merge commits are
already present; it is only that lateron they are reverted.

Any ideas on how to fix that?

Signed-off-by: Jan Nieuwenhuizen <janneke@xxxxxxx>
---
 README       |    6 +++++-
 tg-create.sh |   44 ++++++++++++++++++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/README b/README
index 096b9ec..a9957f2 100644
--- a/README
+++ b/README
@@ -215,6 +215,9 @@ tg create
 	it will detect that you are on a topic branch base ref and
 	resume the topic branch creation operation.
 
+	With the --add option, all given arguments are added as
+	dependencies to current topic branch.
+
 tg delete
 ~~~~~~~~~
 	Remove a TopGit-controlled topic branch of given name
@@ -333,7 +336,8 @@ tg export
 tg undepend
 ~~~~~~~~~~~
 	Update the current topic branch by removing the given
-	branch (required argument) from the list of dependencies.
+	branch (required argument) from the list of dependencies
+	and reverting all its commits.
 
 tg update
 ~~~~~~~~~
diff --git a/tg-create.sh b/tg-create.sh
index 939af33..c5bc5fb 100644
--- a/tg-create.sh
+++ b/tg-create.sh
@@ -3,9 +3,11 @@
 # (c) Petr Baudis <pasky@xxxxxxx>  2008
 # GPLv2
 
+add= # Set to 1 when adding dependencies to existing topgit branch
 deps= # List of dependent branches
 restarted= # Set to 1 if we are picking up in the middle of base setup
 merge= # List of branches to be merged; subset of $deps
+merged= # List branches actually merged
 name=
 
 
@@ -14,8 +16,12 @@ name=
 while [ -n "$1" ]; do
 	arg="$1"; shift
 	case "$arg" in
+	--add)
+		add=1
+		name=$(git symbolic-ref HEAD | cut -b 12-)
+		;;
 	-*)
-		echo "Usage: tg create NAME [DEPS...]" >&2
+		echo "Usage: tg create --add|NAME [DEPENDENCY]..." >&2
 		exit 1;;
 	*)
 		if [ -z "$name" ]; then
@@ -50,12 +56,22 @@ fi
 
 [ -n "$merge" -o -n "$restarted" ] || merge="$deps "
 
+if [ -z "$add" ]; then
+	! git rev-parse --verify "$name" >/dev/null 2>&1 \
+		|| die "branch '$name' already exists"
+else
+	dupes=$(grep -E "^${merge// /|}/\$" .topdeps | tr '\n' ' ')
+	[ -z "$dupes" ] || die "already depend on: $dupes"
+	deps=$(echo "$merge" | cat .topdeps - | tr '\n' ' ' | sed -e 's/ \+$//')
+	merged="$merge"
+	merge="$name $merge"
+fi
+
+
 for d in $deps; do
 	git rev-parse --verify "$d" >/dev/null 2>&1 ||
 		die "unknown branch dependency '$d'"
 done
-! git rev-parse --verify "$name" >/dev/null 2>&1 ||
-	die "branch '$name' already exists"
 
 # Clean up any stale stuff
 rm -f "$git_dir/top-name" "$git_dir/top-deps" "$git_dir/top-merge"
@@ -96,7 +112,13 @@ done
 
 ## Set up the topic branch
 
-git update-ref "refs/top-bases/$name" "HEAD" ""
+if [ -z "$add" ]; then
+	git update-ref "refs/top-bases/$name" "HEAD" ""
+else
+	#[ -n "$add" ] && git -D "$name"
+	git branch -D save/"$name" || :
+	git branch -m "$name" save/$name
+fi
 git checkout -b "$name"
 
 echo "$deps" | sed 's/ /\n/g' >"$root_dir/.topdeps"
@@ -104,7 +126,7 @@ git add "$root_dir/.topdeps"
 
 author="$(git var GIT_AUTHOR_IDENT)"
 author_addr="${author%> *}>"
-{
+[ -z "$add" ] && {
 	echo "From: $author_addr"
 	! header="$(git config topgit.to)" || echo "To: $header"
 	! header="$(git config topgit.cc)" || echo "Cc: $header"
@@ -120,7 +142,13 @@ EOT
 } >"$root_dir/.topmsg"
 git add "$root_dir/.topmsg"
 
+if [ -z "$add" ]; then
+	info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
+	info "To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"
+else
+	git commit -am "Add dependency: $merged"
+fi
 
-
-info "Topic branch $name set up. Please fill .topmsg now and make initial commit."
-info "To abort: git rm -f .top* && git checkout ${deps%% *} && tg delete $name"
+# Local Variables:
+# sh-basic-offset:8
+# End:
-- 
1.6.0.rc0.44.g67270


-- 
Jan Nieuwenhuizen <janneke@xxxxxxx> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien       | http://www.lilypond.org

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux