For example a cron job could simply grab a diff of
everything since the last time it ran and then apply it to the CVS
repository.  The only even slightly tricky part would be getting the
cvs add and rm commands right.  We could run that script an hour.
Anybody who needs more cutting edge sources can switch to SVN.

I don't promise anything on the timing, but I can do this. I already have a very similar arch-to-cvs script which I attach.

Paolo
#!/bin/sh

: ${EDITOR:=`which vi`}

if which baz > /dev/null 2>&1; then
  : ${TLA:=`which baz`}
else
  : ${TLA:=`which tla`}
fi

# Some tools get completely confused in stupid ways by non-default
# settings of LANG (like gawk, which fucks up regexp character ranges).
LANG=C; export LANG

TMP_PFX="/tmp/tla-to-cvs.$$"
if test "$1" == --debug; then
  shift
else
  trap "rm -rf $TMP_PFX" 0 1 2 3 11 15
fi

if test "$#" -ne 2; then
  echo "Usage: tla-to-cvs ARCH-DIR CVS-DIR" >&2
  exit 1
fi

mkdir $TMP_PFX
PWD=`pwd`

TREE_ROOT=`cd $1 && $TLA tree-root 2>/dev/null || echo NONE`
CVS_ROOT=`cd $2 && pwd || echo NONE`

if test $TREE_ROOT = NONE; then
  echo "$TREE_ROOT: Not an arch working directory" >&2
  exit 1
fi

if test $CVS_ROOT != NONE && test -d $CVS_ROOT/CVS; then :; else
  echo "$CVS_ROOT: Not a CVS working directory" >&2
  exit 1
fi

if (cd $2 && cvs update > $TMP_PFX/cvs_update_log 2>&1); then :; else
  cat $TMP_PFX/cvs_update_log >&2
  echo "$CVS_ROOT: problems updating from CVS" >&2
  exit 1
fi

if grep ^C $TMP_PFX/cvs_update_log >&2; then
  echo "$CVS_ROOT: conflicts updating from CVS" >&2
  exit 1
fi

# Get the list of files in the repository

cd $TREE_ROOT
$TLA inventory -s | sort > $TMP_PFX/arch-file-list
cd $PWD

cd $CVS_ROOT
find . ! -type d | sed -e '/\/CVS\//d' -e 's,^\./,,' | sort > 
$TMP_PFX/cvs-file-list
cd $PWD

# Find the added, removed, changed files

comm -13 $TMP_PFX/cvs-file-list $TMP_PFX/arch-file-list | fgrep -v 
.arch-inventory > $TMP_PFX/added-file-list
comm -23 $TMP_PFX/cvs-file-list $TMP_PFX/arch-file-list | fgrep -v .cvsignore > 
$TMP_PFX/removed-file-list
comm -12 $TMP_PFX/cvs-file-list $TMP_PFX/arch-file-list > 
$TMP_PFX/common-file-list

: > $TMP_PFX/changed-file-list
for i in `cat $TMP_PFX/common-file-list`; do
  if cmp $TREE_ROOT/$i $CVS_ROOT/$i >/dev/null 2>&1; then :; else
    echo "$i" > $TMP_PFX/changed-file-list
  fi
done

test -s $TMP_PFX/added-file-list || \
 test -s $TMP_PFX/changed-file-list || test -s $TMP_PFX/removed-file-list || \
  {
    echo $0: CVS repository is up-to-date
    exit 0
  }

# Make a changelog and edit it

echo update from arch > $TMP_PFX/log_msg
echo >> $TMP_PFX/log_msg
for i in `grep -h ChangeLog $TMP_PFX/added-file-list 
$TMP_PFX/changed-file-list`; do
  dir=`dirname $i`
  if [ -f $CVS_ROOT/$dir/ChangeLog ]; then
    cvs_log=$CVS_ROOT/$dir/ChangeLog 
  else
    cvs_log=/dev/null
  fi

  # This script tries to find everything that was added to the ChangeLogs
  # by looking at the diff.  The lines in the first hunk are kept, up to the
  # first bunch of added lines (included).
  diff -u $cvs_log $TREE_ROOT/$dir/ChangeLog | sed \
    -e '1,/^@@/c\' -e "$dir:" \
    -e '/^+/,$ {' \
    -e   's/^+//' \
    -e   't' \
    -e   's/.*//' \
    -e   'q' \
    -e '}' \
    -e '/^-/d' \
    -e 's/^.//' | sed -e '/^\.:/d' >> $TMP_PFX/log_msg
done

$EDITOR $TMP_PFX/log_msg

# Move the changes to the CVS repository

for i in `cat $TMP_PFX/added-file-list`; do
  echo "A $i" >&2
  cp $TREE_ROOT/$i $CVS_ROOT/$i
done

for i in `cat $TMP_PFX/changed-file-list`; do
  echo "M $i" >&2
  cp $TREE_ROOT/$i $CVS_ROOT/$i
done

for i in `cat $TMP_PFX/removed-file-list`; do
  echo "R $i" >&2
  rm $CVS_ROOT/$i
done

# Check them in

cd $CVS_ROOT
if test -s $TMP_PFX/added-file-list; then
  echo "* adding files to CVS" >&2
  xargs cvs add < $TMP_PFX/added-file-list
fi

if test -s $TMP_PFX/removed-file-list; then
  echo "* removing files from CVS" >&2
  xargs cvs remove < $TMP_PFX/removed-file-list
fi

echo "* checking in changes to CVS" >&2
cvs ci -F $TMP_PFX/log_msg

Reply via email to