42
43 # If that variable is not set, then we start in the current directory
44 # and work our way upwards until we find the top of the tree or we
45 # encounter an error.
46
47 # We do handle nested SCM types, and report the innermost one, but if
48 # you nest one of the "second type" systems within another instance of
49 # itself, we'll keep going upwards and report the top of the nested
50 # set of trees.
51
52
53 # Check for well-known tree-type source code management (SCM) systems.
54 function primary_type
55 {
56 typeset scmid
57
58 [ -d "$1/Codemgr_wsdata" ] && scmid="$scmid teamware"
59 [ -d "$1/.hg" ] && scmid="$scmid mercurial"
60 [ -d "$1/CVS" ] && scmid="$scmid cvs"
61 [ -d "$1/.svn" ] && scmid="$scmid subversion"
62 echo $scmid
63 }
64
65 if [[ -n "$CODEMGR_WS" ]]; then
66 if [[ ! -d "$CODEMGR_WS" ]]; then
67 print -u2 "which_scm: $CODEMGR_WS is not a directory."
68 exit 1
69 fi
70 set -- $(primary_type "$CODEMGR_WS")
71 if [[ $# != 1 ]]; then
72 set -- unknown
73 fi
74 echo "$1 $CODEMGR_WS"
75 exit 0
76 fi
77
78 ORIG_CWD=$(pwd)
79
80 if [[ -d RCS ]]; then
81 echo "rcs $ORIG_CWD"
82 exit 0
83 fi
84
85 # If it's not Teamware, it could just be local SCCS.
86 LOCAL_TYPE=
87 [[ -d SCCS ]] && LOCAL_TYPE="sccs"
88
89 # Scan upwards looking for top of tree.
90 DIR=$ORIG_CWD
91 CWD_TYPE=$(primary_type "$DIR")
92 SCM_TYPE=
93 while [[ "$DIR" != / ]]; do
94 set -- $(primary_type "$DIR")
95 if [[ $# > 1 ]]; then
96 echo "unknown $ORIG_CWD"
97 exit 0
98 fi
99 SCM_TYPE="$1"
100 # We're done searching if we hit either a change in type or the top
101 # of a "third type" control system.
102 if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == mercurial || \
103 "$SCM_TYPE" == teamware ]]; then
104 break
105 fi
106 PREVDIR="$DIR"
107 DIR=$(dirname "$DIR")
108 done
109
110 # We assume here that the system root directory isn't the root of the SCM.
111
112 # Check for the "second type" of repository. In all cases, we started
113 # out in the tree and stepped out on the last iteration, so we want
114 # $PREVDIR.
115 if [[ "$CWD_TYPE" == cvs || "$CWD_TYPE" == subversion ]]; then
116 echo "$CWD_TYPE $PREVDIR"
117 exit 0
118 fi
119
120 # If we still don't know what it is, then check for a local type in the
121 # original directory. If none, then we don't know what it is.
122 if [[ -z "$SCM_TYPE" ]]; then
123 if [[ -z "$LOCAL_TYPE" ]]; then
|
42
43 # If that variable is not set, then we start in the current directory
44 # and work our way upwards until we find the top of the tree or we
45 # encounter an error.
46
47 # We do handle nested SCM types, and report the innermost one, but if
48 # you nest one of the "second type" systems within another instance of
49 # itself, we'll keep going upwards and report the top of the nested
50 # set of trees.
51
52
53 # Check for well-known tree-type source code management (SCM) systems.
54 function primary_type
55 {
56 typeset scmid
57
58 [ -d "$1/Codemgr_wsdata" ] && scmid="$scmid teamware"
59 [ -d "$1/.hg" ] && scmid="$scmid mercurial"
60 [ -d "$1/CVS" ] && scmid="$scmid cvs"
61 [ -d "$1/.svn" ] && scmid="$scmid subversion"
62 [ -d "$1/.git" ] && scmid="$scmid git"
63 echo $scmid
64 }
65
66 if [[ -n "$CODEMGR_WS" ]]; then
67 if [[ ! -d "$CODEMGR_WS" ]]; then
68 print -u2 "which_scm: $CODEMGR_WS is not a directory."
69 exit 1
70 fi
71 set -- $(primary_type "$CODEMGR_WS")
72 if [[ $# != 1 ]]; then
73 set -- unknown
74 fi
75 echo "$1 $CODEMGR_WS"
76 exit 0
77 fi
78
79 ORIG_CWD=$(pwd)
80
81 if [[ -d RCS ]]; then
82 echo "rcs $ORIG_CWD"
83 exit 0
84 fi
85
86 # If it's not Teamware, it could just be local SCCS.
87 LOCAL_TYPE=
88 [[ -d SCCS ]] && LOCAL_TYPE="sccs"
89
90 # Scan upwards looking for top of tree.
91 DIR=$ORIG_CWD
92 CWD_TYPE=$(primary_type "$DIR")
93 SCM_TYPE=
94 while [[ "$DIR" != / ]]; do
95 set -- $(primary_type "$DIR")
96 if [[ $# > 1 ]]; then
97 echo "unknown $ORIG_CWD"
98 exit 0
99 fi
100 SCM_TYPE="$1"
101 # We're done searching if we hit either a change in type or the top
102 # of a "third type" control system.
103 if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == git || \
104 "$SCM_TYPE" == mercurial || "$SCM_TYPE" == teamware ]]; then
105 break
106 fi
107 PREVDIR="$DIR"
108 DIR=$(dirname "$DIR")
109 done
110
111 # We assume here that the system root directory isn't the root of the SCM.
112
113 # Check for the "second type" of repository. In all cases, we started
114 # out in the tree and stepped out on the last iteration, so we want
115 # $PREVDIR.
116 if [[ "$CWD_TYPE" == cvs || "$CWD_TYPE" == subversion ]]; then
117 echo "$CWD_TYPE $PREVDIR"
118 exit 0
119 fi
120
121 # If we still don't know what it is, then check for a local type in the
122 # original directory. If none, then we don't know what it is.
123 if [[ -z "$SCM_TYPE" ]]; then
124 if [[ -z "$LOCAL_TYPE" ]]; then
|