5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
28 # which_scm outputs two strings: one identifying the SCM in use, and
29 # the second giving the root directory for the SCM, if known, or just
30 # the current working directory if not known.
32 # There are three distinct types of SCM systems we can detect. The first
33 # type have a control directory per directory (RCS and SCCS), with no other
34 # structure. The second type have a control directory in each subdirectory
35 # within a tree (CVS and SVN). The last type have a single control
36 # directory at the top of the tree (Teamware and Mercurial).
38 # If the common CODEMGR_WS variable is set, then we look there for the
39 # SCM type and bail out if we can't determine it.
41 # If that variable is not set, then we start in the current directory
42 # and work our way upwards until we find the top of the tree or we
45 # We do handle nested SCM types, and report the innermost one, but if
46 # you nest one of the "second type" systems within another instance of
47 # itself, we'll keep going upwards and report the top of the nested
51 # Check for well-known tree-type source code management (SCM) systems.
56 [ -d "$1/Codemgr_wsdata" ] && scmid
="$scmid teamware"
57 [ -d "$1/.hg" ] && scmid
="$scmid mercurial"
58 [ -d "$1/CVS" ] && scmid
="$scmid cvs"
59 [ -d "$1/.svn" ] && scmid
="$scmid subversion"
60 [ -d "$1/.git" ] && scmid
="$scmid git"
64 if [[ -n "$CODEMGR_WS" ]]; then
65 if [[ ! -d "$CODEMGR_WS" ]]; then
66 print
-u2 "which_scm: $CODEMGR_WS is not a directory."
69 set -- $
(primary_type
"$CODEMGR_WS")
70 if [[ $# != 1 ]]; then
84 # If it's not Teamware, it could just be local SCCS.
86 [[ -d SCCS
]] && LOCAL_TYPE
="sccs"
88 # Scan upwards looking for top of tree.
90 CWD_TYPE
=$
(primary_type
"$DIR")
92 while [[ "$DIR" != / ]]; do
93 set -- $
(primary_type
"$DIR")
95 echo "unknown $ORIG_CWD"
99 # We're done searching if we hit either a change in type or the top
100 # of a "third type" control system.
101 if [[ "$SCM_TYPE" != "$CWD_TYPE" ||
"$SCM_TYPE" == git || \
102 "$SCM_TYPE" == mercurial ||
"$SCM_TYPE" == teamware
]]; then
106 DIR
=$
(dirname "$DIR")
109 # We assume here that the system root directory isn't the root of the SCM.
111 # Check for the "second type" of repository. In all cases, we started
112 # out in the tree and stepped out on the last iteration, so we want
114 if [[ "$CWD_TYPE" == cvs ||
"$CWD_TYPE" == subversion
]]; then
115 echo "$CWD_TYPE $PREVDIR"
119 # If we still don't know what it is, then check for a local type in the
120 # original directory. If none, then we don't know what it is.
121 if [[ -z "$SCM_TYPE" ]]; then
122 if [[ -z "$LOCAL_TYPE" ]]; then
130 echo "$SCM_TYPE $DIR"