Question

I've played with CVS a little bit and am not the most familiar with all of its capabilities, but a huge annoyance for me is trying to add new directories that contain more directories in them. Running "cvs add" only adds the contents of the current directory, and using "cvs import" didn't look like the right thing either since it's still all code I'm producing (this howto claimed import is for 3rd party sources)

Do you guys know any way to recursively add everything in a given directory to the current CVS project (or if SVN or git makes this notably easier)?

Was it helpful?

Solution

Ah, spaces. This will work with spaces:

find . -type f -print0| xargs -0 cvs add

OTHER TIPS

I found this worked pretty effectively:

First, add all the directories, but not any named "CVS":

find . -type d \! -name CVS -exec cvs add '{}' \;

Then add all the files, excluding anything in a CVS directory:

find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs add '{}' \; \)

Now, if anyone has a cure for the embarrassment of using CVS in this day and age...

I use this:

First add recursively all directories less the CVS ones:

$> find . -type d \! -name CVS -exec cvs add '{}' \;

Second add all files, less ones the CVS directories:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs add '{}' \; \)

Third do “commit” recursively like "first version" comment:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs commit -m "first version" '{}' \; \)

Last tagging all recursively:

 find . \( -type d -name CVS -prune \) -o \( -type f -exec cvs tag -F MY_CVS_TAG '{}' \; \)

First add all directories to CVS

find . -type d -print0| xargs -0 cvs add

Then add all the files in the directories to CVS

find . -type f | grep -v CVS | xargs cvs add

Worked for me

cvs import is not just for 3rd-party sources. In fact, directories are not versioned by CVS, so they are not a subject to branch policies. As long as you import empty directories, it is fine.

Note that you can only use cvs add on files and folders that are located inside an already checked out working copy, otherwise you will get the "Cannot open CVS/Entries for reading" message. A technique for creating a new "root module" using cvs add is explained in this WinCVS FAQ item: http://cvsgui.sourceforge.net/newfaq.htm#add_rootmodule

If you are on Windows, both TortoiseCVS and WinCVS support recursive addition (and optional commit) of multiple files in a single operation. In WinCvs look for the macro Add>Recursive Add (auto-commit)... In Tortoise use the Add Contents command on a directory. Both will allow you to select which files to add and what keyword expansion modes to use for them (mostly used for defining which files are binary).

For further info about recursive add in WinCvs look here: http://cvsgui.sourceforge.net/newfaq.htm#cvs-add_recursive


Apart from that cvs import is well suited for mass-additions. However, the way cvs import is implemented in vanilla CVS has two drawbacks (because it was originally written for third-party code):

  • it creates a mandatory branch with special semantics.
  • it does not create the repository meta-data (i.e. the hidden CVS directories) needed to establish the imported code as a checked out working copy, which means that in order to actually work with the imported files you first have to check them out of the repository

If you are using CVSNT you can avoid both drawbacks by specifying the -nC option on import. -n is for avoiding the "vendor" branch and -C is for creating the CVS directories.

This answer from Mark was usefull (find . -type f -print0| xargs -0 cvs add) but I solved some problem that occured when the cvs add try to add his own files like Tag, Entries, ect..

  1. Add your most high level folder called NEW_FOLDER
cvs add NEW_FOLDER
  1. Use the previous command with some exclusion to add all sub-folders tree

find NEW_FOLDER/ -type d ! -name "CVS" -and ! -name "Tag" -and ! -name "Entries.Log" -and ! -name "Entries" -and ! -name "Repository" -and ! -name "Root" -print0 | xargs -0 cvs add

  1. Use the previous command with some exclusion to add all files

find NEW_FOLDER/ -type f ! -name "CVS" -and ! -name "Tag" -and ! -name "Entries.Log" -and ! -name "Entries" -and ! -name "Repository" -and ! -name "Root" -print0 | xargs -0 cvs add

I think this is what I did back in my CVS days:

find . -type f | xargs cvs add

First add all directories to CVS

find . -type d -print0| xargs -0 cvs add

Then add all the files in the directories to CVS

find . -type f -print0| xargs -0 cvs add

I'm using this simple shell script, which should be started from an already checked-out CVS directory. It will stupidly try to add/commit any files and directories it finds upon its recursive search, so in the end you should end up with a fully commit tree.

Simply save this as something like /usr/bin/cvsadd and don't forget to chmod +x /usr/bin/cvsadd.

#!/bin/sh
# @(#) add files and directories recursively to the current CVS directory
# (c) 2009 by Dirk Jagdmann 

if [ -z "$1" ] ; then
    echo "usage: cvsadd 'import message'"
    exit 1
fi

if [ -d "$2" ] ; then
    cvs add "$2"
    cd "$2" || exit 1
fi

if [ ! -d CVS ] ; then
    echo "current directory needs to contain a CVS/ directory"
    exit 1
fi

XARGS="xargs -0 -r -t -L 1"

# first add all files in current directory
find . -maxdepth 1 -type f -print0 | $XARGS cvs add
find . -maxdepth 1 -type f -print0 | $XARGS cvs ci -m "$1"

# then add all directories
find . -maxdepth 1 -type d -not -name CVS -a -not -name . -print0 | $XARGS "$0" "$1"

Already discussed methods will do recursive lookup, but it will fail if you perform same action again (if you want to add subtree to existed tree) For that reason you need to check that your directories was not added yet and then add only files which not added yet. To do that we use output of cvs up to see which elements was not added yet - its will have question mark at start of line.

We use options -0, -print0 and -zZ to be sure that we correctly process spaces in filenames. We also using --no-run-if-empty to avoid run if nothing need to be added.

CVS_PATTERN=/tmp/cvs_pattern
cvs -z3 -q up | egrep '^\?.*' | sed -e 's/^? //' > $CVS_PATTERN
find . -type d \! -name CVS -print0 | grep -zZf $CVS_PATTERN | xargs -0 --no-run-if-empty cvs add
find . \( -type d  -name CVS -prune \) -o \( -type f  -print0 \) | grep -zZf $CVS_PATTERN | xargs -0 --no-run-if-empty cvs add
cvs commit -m 'commiting tree recursively'

With this approach we will avoid such errors:

cvs add: cannot add special file `.'; skipping
cvs [add aborted]: there is a version in ./dirname1 already

and

cvs add: `./dirname2/filename' already exists, with version number 1.1.1.1

i like to do (as directory's need an add to)

cvs status 2>/dev/null | awk '{if ($1=="?")system("cvs add "$2)}'

you might need to run this multiple times(first for directory's then for its children) until there is no output

Mark's solution resolves the spaces issue, but produces this issue:

cvs add: cannot open CVS/Entries for reading: No such file or directory
cvs [add aborted]: no repository

To fix it, the actual command to use is:

find . -type f -exec cvs add {} \;

SVN definitely makes this trivial task, using a GUI like Tortoise is even easier, however.

This might be a good place to start: http://www-mrsrl.stanford.edu/~brian/cvstutorial/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top