[PATCH 5/5] Add contrib/stg-cvs: helper script to manage a mixed cvs/stgit working copy

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

 



This is an early prototype only, use with care, and be sure to read the
LIMITATIONS section in the script comments.

Signed-off-by: Yann Dirson <ydirson@xxxxxxxxxx>
---

 contrib/stg-cvs |  126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/contrib/stg-cvs b/contrib/stg-cvs
new file mode 100755
index 0000000..ee3e7fa
--- /dev/null
+++ b/contrib/stg-cvs
@@ -0,0 +1,126 @@
+#!/bin/bash
+set -e
+
+# stg-cvs - helper script to manage a mixed cvs/stgit working copy.
+
+# Allows quick synchronization of a cvs mirror branch (does not try to
+# reconstruct patchsets, creates "jumbo" commits), and commits stgit
+# patches to CVS.
+
+# Copyright (c) 2007 Yann Dirson <ydirson@xxxxxxxxxx>
+# Subject to the GNU GPL, version 2.
+
+# LIMITATIONS
+# - this is only a proof-of-concept prototype
+# - lacks an "init" command
+# - "commit" does not "cvs add/remove" any file or dir
+# - "commit" does not ensure the base is uptodate before trying to
+#   commit (but hey, it's CVS ;)
+# - "commit" can only commit a single patch
+# - not much robustness here
+# - this only deals with CVS but could surely be extended to any other
+#   VCS
+# - stg push/pop operations confuse cvsutils because of timestamp
+#   changes
+# - lacks synchronisation of .cvsignore <-> .gitignore
+
+usage()
+{
+    [ "$#" = 0 ] || echo "ERROR: $*"
+    echo "Usage: $(basename $0) <command>"
+    echo " commands: $(do_commands)"
+    exit 1
+}
+
+do_commands()
+{
+    echo $(grep '^[a-z-]*)' $0 | cut -d')' -f1)
+}
+
+do_fetch()
+{
+    local return=0
+    local path
+
+    local parent="$1"
+    local branch="$2"
+
+    # record changes from cvs into index
+    stg branch "$parent"
+    cvs -fq update -dP | grep -v '^\? ' | tee /dev/tty | while read status path; do
+	if [ -e "$path" ]; then
+	    git update-index "$path"
+	else
+	    git rm "$path"
+	fi
+    done
+
+    # create commit
+    if git commit -m "stg-cvs sync"; then
+	:
+    else
+	return=$?
+    fi
+
+    # back to branch
+    stg branch "$branch"
+
+    return $return
+}
+
+# get context
+branch=$(stg branch)
+parent=$(git-repo-config "stgit.yd.${branch}.parent") || 
+    usage "no declared parent for '$branch' - set stgit.yd.${branch}.parent"
+
+# extract command
+
+[ "$#" -ge 1 ] || usage
+command="$1"
+shift
+
+case "$command" in
+fetch)
+    do_fetch "$parent" "$branch"
+    ;;
+
+pull)
+    if do_fetch "$parent" "$branch"; then
+	# update
+	stg pull --merged . "$parent"
+	stg clean --applied
+    fi
+    ;;
+
+commit)
+    # sanity asserts
+    [ $(stg applied | wc -l) = 1 ] ||
+	usage "you don't have exactly one patch applied"
+
+    # context
+    patch=$(stg top)
+    
+    # commit
+    cvs -fq commit \
+	-F ".git/patches/$branch/patches/$patch/description" \
+	$(stg files --bare)
+
+    # sync the parent branch
+    stg branch "$parent"
+    git-cherry-pick "patches/${branch}/${patch}"
+    stg branch "${branch}"
+
+    # update
+    stg pull --merged . "$parent"
+    stg clean --applied
+    ;;
+
+_commands)
+    # hint for bash-completion people :)
+    do_commands
+    ;;
+
+*)
+    usage "unknown command '$command'"
+    ;;
+esac
-
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]