#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# which_scm outputs two strings: one identifying the SCM in use, and
# the second giving the root directory for the SCM, if known, or just
# the current working directory if not known.
# There are three distinct types of SCM systems we can detect. The first
# type have a control directory per directory (RCS and SCCS), with no other
# structure. The second type have a control directory in each subdirectory
# within a tree (CVS and SVN). The last type have a single control
# directory at the top of the tree (Teamware and Mercurial).
# If the common CODEMGR_WS variable is set, then we look there for the
# SCM type and bail out if we can't determine it.
# If that variable is not set, then we start in the current directory
# and work our way upwards until we find the top of the tree or we
# encounter an error.
# We do handle nested SCM types, and report the innermost one, but if
# you nest one of the "second type" systems within another instance of
# itself, we'll keep going upwards and report the top of the nested
# set of trees.
# Check for well-known tree-type source code management (SCM) systems.
function primary_type
{
typeset scmid
echo $scmid
}
if [[ -n "$CODEMGR_WS" ]]; then
if [[ ! -d "$CODEMGR_WS" ]]; then
print -u2 "which_scm: $CODEMGR_WS is not a directory."
exit 1
fi
if [[ $# != 1 ]]; then
set -- unknown
fi
echo "$1 $CODEMGR_WS"
exit 0
fi
ORIG_CWD=$(pwd)
if [[ -d RCS ]]; then
echo "rcs $ORIG_CWD"
exit 0
fi
# If it's not Teamware, it could just be local SCCS.
# Scan upwards looking for top of tree.
while [[ "$DIR" != / ]]; do
if [[ $# > 1 ]]; then
echo "unknown $ORIG_CWD"
exit 0
fi
SCM_TYPE="$1"
# We're done searching if we hit either a change in type or the top
# of a "third type" control system.
break
fi
done
# We assume here that the system root directory isn't the root of the SCM.
# Check for the "second type" of repository. In all cases, we started
# out in the tree and stepped out on the last iteration, so we want
# $PREVDIR.
exit 0
fi
# If we still don't know what it is, then check for a local type in the
# original directory. If none, then we don't know what it is.
if [[ -z "$SCM_TYPE" ]]; then
if [[ -z "$LOCAL_TYPE" ]]; then
else
fi
fi
exit 0