Re: Switching to CVS: how to get all my Debian diffs?
On Tuesday 9 March 1999, at 19 h 43, the keyboard of Wichert Akkerman
<wichert@cs.leidenuniv.nl> wrote:
> If somebody comes up with an easy way to do this I just might switch to
> CVS.
Here is a script (it is an updated version of cvs-inject, which is in cvs-buildpackage) that Frederic Lepied <Frederic.Lepied@sugix.frmug.org> wrote and that I did not test yet:
#! /bin/bash
# -*- Mode: Sh -*-
# cvs-inject ---
# Author : Manoj Srivastava ( srivasta@tiamat.datasync.com )
# Created On : Mon May 26 14:23:17 1997
# Created On Node : tiamat.datasync.com
# Last Modified By : Frederic Lepied
# Last Modified On : Sun Mar 7 18:29:48 1999
# Last Machine Used: tiamat.golden-gryphon.com
# Update Count : 310
# Status : Unknown, Use with caution!
# HISTORY :
# Description :
# $Id: cvs-inject,v 1.10 1999/02/22 08:40:40 srivasta Exp $
#
# Make sure we abort on error
set -e
progname="`basename \"$0\"`"
pversion='$Revision: 1.10 $'
setq() {
# Variable Value Doc string
if [ "x$2" = "x" ]; then
echo >&2 "$progname: Unable to determine $3"
exit 1;
else
if [ ! "x$Verbose" = "x" ]; then
echo "$progname: $3 is $2";
fi
eval "$1=\"\$2\"";
fi
}
withecho () {
echo " $@" >&2
"$@"
}
usageversion () {
cat >&2 <<END
Usage: $progname [options] <package>.dsc
Options:
-h print this message
-M<module> CVS module name.
-R<root dir> Root directory.
-W<work dir> Working directory.
-d<digit> Set Debug Level
-n "Dry-run" mode - No action taken, only print commands.
-v Make the command verbose
-ctp Include <package>_ at start of CVS tag.
-u Update mechanism
-x<prefix> CVS default module prefix.
Note that the current behaviour of cvs-inject is to ignore any files
that match the default list of file name patterns to be ignored (this
is built into cvs); and that any .cvsignore files in the upstream
sources shall be honoured.
END
}
# We need a debian source control file
if [ $# = 0 ]; then
usageversion;
exit 1;
fi
# The defaults
rootdir='/usr/local/src/Packages'
tmpdir="temp-$progname"
docmd='YES'
action='withecho'
DEBUG=0
VERBOSE=0
# parse Command line
while [ $# != 0 ]; do
value="`echo x\"$1\" | sed -e 's/^x-.//'`"
case "$1" in
-h) usageversion; exit 0 ;;
-M*) opt_cvsmodule="$value" ;;
-R*) opt_rootdir="$value" ;;
-W*) opt_workdir="$value" ;;
-n) action='echo';docmd='NO' ;;
-v) VERBOSE=1 ;;
-d*) opt_DEBUG="$value" ;;
-x*) opt_prefix="$value" ;;
-ctp) opt_packageintag=1 ;;
-u) UPDATE=1 ;;
-*) echo >&2 "Unknown option $1."
usageversion; exit 1 ;;
*.dsc)
if [ "X$opt_dsc" = "X" ]; then
opt_dsc="$1";
else
echo >&2 "I can only deal with one Debian Source Control"
echo >&2 "file at a time. I think I already have one "
echo >&2 "in $opt_dsc. So, whats this $1 ?"
exit 1
fi
;;
*) echo >&2 "Unknown argument $1. I understand only a"
echo >&2 "Debian Source Control file name as an argument"
usageversion; exit 1 ;;
esac
shift
done
CVS_QUIET="-Q"
TAR_QUIET=""
if [ $VERBOSE -gt 0 ]; then
echo "Initializing ..."
CVS_QUIET="-q"
TAR_QUIET="v"
fi
# did the user specify a dsc file?
if [ "X$opt_dsc" = "X" ]; then
echo "package descscription file needs to be specified" 1>&2
usageversion;
exit 1
fi
if [ "X$CVSROOT" = "X" ]; then
echo "You should have set the CVSROOT env variable." 1>&2
usageversion;
exit 1
fi
# can we read the dsc file?
if [ ! -r $opt_dsc ]; then
echo "package descscription file $opt_dsc is not available" 1>&2
usageversion;
exit 1
fi
# Load site defaults and over rides.
if [ -f /etc/cvsdeb.conf ]; then
. /etc/cvsdeb.conf
fi
# Load user defaults and over rides.
if [ -f ~/.cvsdeb.conf ]; then
. ~/.cvsdeb.conf
fi
# If asked to debug on command line, that's what we get
if [ ! "x$opt_DEBUG" = "x" ]; then
DEBUG="$opt_DEBUG"
fi
if [ "$DEBUG" -gt 0 ]; then
CVS_QUIET=""
TAR_QUIET="vv"
fi
# Command line, env variable, config file, or default
if [ ! "x$opt_rootdir" = "x" ]; then
rootdir="$opt_rootdir"
elif [ ! "x$CVSDEB_ROOTDIR" = "x" ]; then
rootdir="$CVSDEB_ROOTDIR"
elif [ ! "x$conf_rootdir" = "x" ]; then
rootdir="$conf_rootdir"
fi
# Command line, env variable, config file, or default
if [ ! "x$opt_prefix" = "x" ]; then
prefix="$opt_prefix"
elif [ ! "x$CVSDEB_PREFIX" = "x" ]; then
prefix="$CVSDEB_PREFIX"
elif [ ! "x$conf_prefix" = "x" ]; then
prefix="$conf_prefix"
else
prefix=""
fi
# Command line, env variable, config file, or default
if [ ! "x$opt_packageintag" = "x" ]; then
packageintag="$opt_packageintag"
elif [ ! "x$CVSDEB_PACKAGEINTAG" = "x" ]; then
packageintag="$CVSDEB_PACKAGEINTAG"
elif [ ! "x$conf_packageintag" = "x" ]; then
packageintag="$conf_packageintag"
else
packageintag=""
fi
# put a slash at the end of the prefix
if [ "X$prefix" != "X" ]; then
prefix="$prefix/";
prefix=`echo $prefix | sed 's://:/:g'`;
fi
filename=`basename $opt_dsc .dsc`
package=`cat $opt_dsc | perl -wnle 'm/^\s*Source\s*:\s*(\S+)/io && print $1;'`
version=`cat $opt_dsc | perl -wnle 'm/^\s*Version\s*:\s*(\S+)/io && print $1;' | head -1`
# Command line, env variable, or default
if [ ! "x$opt_cvsmodule" = "x" ]; then
cvsmodule="$opt_cvsmodule"
elif [ ! "x$CVSDEB_MODULE" = "x" ]; then
cvsmodule="$CVSDEB_MODULE"
else
cvsmodule="${prefix}$package"
fi
non_epoch_version=`echo "$version" | perl -pe 's/^\d+://'`
upstream_version=`echo "$non_epoch_version" | sed -e 's/-[^-]*$//'`
cvstag=`echo "debian_version_$non_epoch_version" | tr . _ `
cvs_upstream_tag=`echo "upstream_version_$upstream_version" | tr . _ `
if [ "x$packageintag" != x ]; then
cvstag="${package}_$cvstag"
cvs_upstream_tag="${package}_$cvs_upstream_tag"
fi
if [ "X$version" != "X$upstream_version" ]; then
debian_version=`echo $non_epoch_version|perl -nle 'm/-([^-]*)$/ && print $1'`
DEB_ONLY='FALSE'
else
DEB_ONLY='TRUE'
fi
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "Debian only package"
fi
if [ $DEBUG ]; then
echo "package=${package} cvsmodule=$cvsmodule"
echo "upstream_version=${upstream_version} "
echo "cvs_upstream_tag=${cvs_upstream_tag} "
if [ "X$DEB_ONLY" = "XTRUE" ]; then
echo "Debian only package"
else
echo "debian_version=${debian_version} cvstag=${cvstag}"
fi
fi
# Command line, env variable, config file, or default
if [ ! "x$opt_workdir" = "x" ]; then
workdir="$opt_workdir"
elif [ ! "x$CVSDEB_WORKDIR" = "x" ]; then
workdir="$CVSDEB_WORKDIR"
elif [ ! "x$conf_workdir" = "x" ]; then
workdir="$conf_workdir"
else
workdir="$rootdir/$package"
fi
sourcedir=`dirname $opt_dsc`
srcfile=`basename $opt_dsc`
#set the absolute path name to the dsc file
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Getting the absolute path name to the dsc file"
fi
cd "$sourcedir"
sourcedir=`pwd`
opt_dsc="$sourcedir/$srcfile"
if [ ! -d "$workdir" ]; then
$action mkdir -p "$workdir"
fi
if [ "X$docmd" = "XYES" ]; then
if [ ! -d "$workdir" ]; then
echo "Could not create $workdir"
exit 1;
fi
fi
$action cd "$workdir"
if [ -f "$tmpdir" ]; then
echo >&2 "$workdir/$tmpdir directory exists"
echo >&2 "It shall be scribbled on if I continue"
echo >&2 "Aborting"
exit 1;
fi
$action mkdir "$tmpdir"
if [ "X$docmd" = "XYES" ]; then
if [ ! -d "$tmpdir" ]; then
echo >$2 "The working directory ($workdir) is not writable"
exit 1
fi
fi
$action cd "$tmpdir"
# extract the sources
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Extracting the source"
fi
$action dpkg-source -su -x "$opt_dsc"
if [ $? != 0 ]; then
echo "Error extracting package: exiting" 1>&2
exit 1
fi
######################################################################
# clean up the temporary locations
clean_up() {
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Cleaning up"
fi
$action cd "${workdir}"
if [ "X$docmd" = "XYES" ]; then
if [ -d "$tmpdir" ]; then
$action rm -rf "$tmpdir"
fi
else
$action rm -rf "$tmpdir"
fi
}
# check for symbolic links in the upstream sources
check_symlinks() {
symbolic_links=$(find . -type l -print)
if [ "X$symbolic_links" != "X" ]; then
echo >&2 "The upstream sources contain symbolic links."
echo >&2 "CVS ignores symblic links, you have to handle link "
echo >&2 "creation in the modules file (-e and -o args)"
echo >&2 "Please hit return to continue."
read ans
fi
}
check_CVS_dirs() {
CVS_dirs=$(find . -type d -name CVS -print)
if [ "X$CVS_dirs" != "X" ]; then
echo >&2 "The upstream sources contain CVS directories."
echo >&2 "This I can't handle. Please delete the following"
echo >&2 "directories and try again."
echo >&2 "$CVS_dirs"
clean_up;
exit 1
fi
}
# Importing the upstream sources
import_orig() {
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Import the original source tree"
fi
$action cd "$1"
if [ "X$docmd" = "XYES" ]; then
check_symlinks;
fi
$action cvs "$CVS_QUIET" import -ko -m'Initial Import' "${cvsmodule}" source-dist "${cvs_upstream_tag}"
$action cd "${workdir}/$tmpdir"
}
#
co_import() {
# For non debian only packages
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Extracting the imported files"
fi
$action cvs co "${cvsmodule}"
# Where did it go?
if [ -d "${package}-${upstream_version}" ]; then
$action cd "${package}-${upstream_version}";
elif [ -d "${prefix}$package-${upstream_version}" ]; then
mv "${prefix}$package-${upstream_version}" "${package}-${upstream_version}";
$action cd "$package-${upstream_version}";
fi
if [ "X$docmd" = "XYES" ]; then
tar cf - . | (cd "../${cvsmodule}"; tar "${TAR_QUIET}xf" -)
else
echo "tar cf - . | (cd ../${cvsmodule}; tar ${TAR_QUIET}xf -)"
fi
$action cd ..
}
# commit debianized tree (non debian only packages
commit_debianized() {
# For non debian only packages
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Committing the Debianized version"
fi
$action cd "${cvsmodule}"
$action cvs add debian
if [ "X$docmd" = "XYES" ]; then
done=""
while [ "X$done" != "X1" ]; do
dirs=$(cvs -n update | sed -n 's:^\? ::p')
if [ "X$dirs" = "X" ]; then
done=1
break
fi
for item in $(cvs -n update | sed -n 's:^\? ::p'); do
dir=$(dirname $item)
file=$(basename $item)
(cd $dir; cvs add $file)
done
done
else
echo "cvs add <other files found dynamically>"
fi
$action cvs commit -m'Added all debian changes'
$action cvs "$CVS_QUIET" tag -F "${cvstag}"
$action cd "${workdir}/$tmpdir"
}
##########################################################
# UPDATE SUPPORT
##########################################################
# Checkout the module and remove all the files it contains.
# If an arg is given, remove the debian directory.
co_empty() {
# For non debian only packages
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Extracting the module files"
fi
$action cvs "$CVS_QUIET" co "${cvsmodule}"
$action cd ${cvsmodule}
if [ "X$docmd" = "XYES" ]; then
find . -type f | fgrep -v CVS | xargs rm -f
else
echo "find . -type f | fgrep -v CVS | xargs rm -f"
fi
if [ $# -gt 0 ]; then
if [ "X$docmd" = "XYES" ]; then
echo y | cvs release -d debian
mv CVS/Entries CVS/Entries.bak
grep -v '^D/debian/' < CVS/Entries.bak > CVS/Entries
else
echo 'cvs release -d debian'
fi
fi
$action cd "${workdir}/$tmpdir"
}
# Move the source from the source dir to the module dir.
# If an arg is given, move the files from the orig dir.
replace_module() {
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Replacing module files"
fi
if [ $# -gt 0 ]; then
$action cd "${package}-${upstream_version}.orig"
else
$action cd "${package}-${upstream_version}"
fi
if [ "X$docmd" = "XYES" ]; then
tar cf - . | (cd "../${cvsmodule}"; tar "${TAR_QUIET}xf" -)
else
echo "tar cf - . | (cd ../${cvsmodule}; tar ${TAR_QUIET}xf -)"
fi
$action cd "${workdir}/$tmpdir"
}
# Add a new directory and its content into CVS
add_directory() {
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Adding directory $1"
fi
dir=$1
cur=$PWD
cd $dir
for f in `ls * .??*`; do
$action cvs add -ko $f
add_directory $f
done
cd $cur
}
# commit debianized tree (non debian only packages
commit_version() {
# For non debian only packages
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Committing the Debianized version"
fi
$action cd "${cvsmodule}"
if [ "X$docmd" = "XYES" ]; then
done=""
while [ "X$done" != "X1" ]; do
dirs=$(cvs -n update | sed -n 's:^\? ::p')
if [ "X$dirs" = "X" ]; then
done=1
break
fi
for item in $(cvs -n update | sed -n 's:^\? ::p'); do
dir=$(dirname $item)
file=$(basename $item)
(cd $dir; cvs add -ko $file)
if [ -d $item ]; then
add_directory $item
fi
done
done
# If a file is marked as update it means that it has been removed
# from the hierarchy.
for item in $(cvs -n update 2>/dev/null | sed -n 's:^U ::p'); do
dir=$(dirname $item)
file=$(basename $item)
(cd $dir; cvs remove $file)
done
else
echo "cvs add or remove <other files found dynamically>"
fi
$action cvs commit -m'Added all debian changes'
$action cvs "$CVS_QUIET" tag -F "${cvstag}"
$action cd "${workdir}/$tmpdir"
}
# commit orig tree (non debian only packages
commit_orig() {
# For non debian only packages
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Committing the orig version"
fi
$action cd "${cvsmodule}"
if [ "X$docmd" = "XYES" ]; then
done=""
while [ "X$done" != "X1" ]; do
dirs=$(cvs -n update | sed -n 's:^\? ::p')
if [ "X$dirs" = "X" ]; then
done=1
break
fi
for item in $(cvs -n update | sed -n 's:^\? ::p'); do
dir=$(dirname $item)
file=$(basename $item)
(cd $dir; cvs add -ko $file)
if [ -d $item ]; then
add_directory $item
fi
done
done
# If a file is marked as update it means that it has been removed
# from the hierarchy. Don't remove the debian directory
# which is not in the orig tree ;-)
for item in $(cvs -n update 2>/dev/null | fgrep -v debian | sed -n 's:^U ::p'); do
dir=$(dirname $item)
file=$(basename $item)
(cd $dir; cvs remove $file)
done
else
echo "cvs add or remove <other files found dynamically>"
fi
$action cvs commit -m'Added all orig changes'
$action cvs "$CVS_QUIET" tag -F "${cvs_upstream_tag}"
$action cd "${workdir}/$tmpdir"
}
######################################################################
if [ "X$docmd" = "XYES" ]; then
if [ ! -d "${package}-${upstream_version}" ]; then
echo >&2 "No ${workdir}/$tmpdir/${package}-${upstream_version}"
echo >&2 "Error extracting source"
echo >&2 "Aborting"
clean_up;
exit 1
fi
if [ "X$DEB_ONLY" = "XFALSE" ]; then
if [ ! -d "${package}-${upstream_version}.orig" ]; then
echo >&2 "No ${workdir}/$tmpdir/${package}-${upstream_version}.orig"
echo >&2 "Error extracting source"
echo >&2 "Aborting"
clean_up;
exit 1
fi
fi
fi
if [ -n "$UPDATE" ]; then
# the upgrade mechanism only works for non debian only packages
if [ "X$DEB_ONLY" = "XFALSE" ]; then
# If this is the first version import the orig
if [ "$debian_version" -eq "1" ]; then
# Extract the current state of the files without them and
# without the debian dir.
co_empty 1;
# Move the files from the orig directory
replace_module 1;
# commit the version
commit_orig;
# remove module
$action rm -rf ${cvsmodule}
# Extract the current state of the files without them
co_empty;
else
# Extract the current state of the files without them
co_empty;
fi
# Move the files from the extracted directory
replace_module;
# And commit the debianized files
commit_version;
else
echo "update for debian only package not supported for the moment" 1>&2
exit 1
fi
else
# import original source tree.
if [ "X$DEB_ONLY" = "XFALSE" ]; then
import_orig "${package}-${upstream_version}.orig";
# extract the imported files, and add the debianized ones
co_import;
# And commit the debianized files
commit_debianized;
else
import_orig "${package}-${upstream_version}"
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Extracting imported files"
fi
$action cvs "$CVS_QUIET" co "${cvsmodule}"
if [ $VERBOSE -gt 0 ]; then
echo ""
echo "# Tagging the files with debian version"
fi
$action cd "${cvsmodule}"
$action cvs "$CVS_QUIET" tag -F "${cvstag}"
$action cd "${workdir}/$tmpdir"
fi
fi
clean_up
echo "$package registered under CVS"
exit 0
Reply to: