# -*- tcl -*-
# --------------------------------------------------
# (C) 1997	Andreas Kupries <a.kupries@westend.com>
#
# CVS:	$Id: retr_cvs,v 1.2 1998/06/02 16:59:14 aku Exp $
#
# @c Retrieval of modules from a CVS repository
# @s Retrieval from cVS
# @i retrieval, cvs
# --------------------------------------------------


::makedist::retriever cvs CVS {
    # @c Retrieves the <a module> via 'cvs'.
    #
    # @a module:  Logical name of the module to be retrieved.
    # @a version: number/tag of the version to retrieve. The head revision
    # @a version:  will be accessed, if this argument is empty.
    #
    # @n Assumes that the working directory is set to be the build directory.
    # @n The command 'cvs' has to be reachable via path.

    # See "doc/Interfaces" too.

    # a small sanity check first: is there a CVSROOT environment
    # variable ?   if not, even 'cvs' cannot help us, as the
    # location of the repository will be unknown.

    global env
    if {[catch {set env(CVSROOT)}]} {
	error "environment variable CVSROOT not set. CVS not reachable."
    }

    # @danger UNIX dependent (redirection maybe, /dev/null surely)
    # @future use a 'pipe', 'fileevent' and 'vwait' to follow the
    # @future execution of 'cvs checkout' too.

    if {[string length $version] == 0} {
	exec cvs checkout $module >/dev/null 2>/dev/null
    } else {
	exec cvs checkout -r $version $module >/dev/null 2>/dev/null
    }

    # CVS places a subdirectory named CVS containing administrative files into
    # all retrieved directories. Remove them from the distribution.

    ::pool::file::descendDirs d . {
	catch {file delete -force CVS}
    }
    return
}
