Print this page
Add git support to which_scm utility
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/tools/scripts/which_scm.sh
+++ new/usr/src/tools/scripts/which_scm.sh
1 1 #!/usr/bin/ksh -p
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License (the "License").
7 7 # You may not use this file except in compliance with the License.
8 8 #
9 9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 # or http://www.opensolaris.org/os/licensing.
11 11 # See the License for the specific language governing permissions
12 12 # and limitations under the License.
13 13 #
14 14 # When distributing Covered Code, include this CDDL HEADER in each
15 15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 # If applicable, add the following below this CDDL HEADER, with the
17 17 # fields enclosed by brackets "[]" replaced with your own identifying
18 18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 19 #
20 20 # CDDL HEADER END
21 21 #
22 22
23 23 #
24 24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 25 # Use is subject to license terms.
26 26 #
27 27 # ident "%Z%%M% %I% %E% SMI"
28 28 #
29 29
30 30 # which_scm outputs two strings: one identifying the SCM in use, and
31 31 # the second giving the root directory for the SCM, if known, or just
32 32 # the current working directory if not known.
33 33
34 34 # There are three distinct types of SCM systems we can detect. The first
35 35 # type have a control directory per directory (RCS and SCCS), with no other
36 36 # structure. The second type have a control directory in each subdirectory
37 37 # within a tree (CVS and SVN). The last type have a single control
38 38 # directory at the top of the tree (Teamware and Mercurial).
39 39
40 40 # If the common CODEMGR_WS variable is set, then we look there for the
41 41 # SCM type and bail out if we can't determine it.
42 42
43 43 # If that variable is not set, then we start in the current directory
44 44 # and work our way upwards until we find the top of the tree or we
45 45 # encounter an error.
46 46
47 47 # We do handle nested SCM types, and report the innermost one, but if
48 48 # you nest one of the "second type" systems within another instance of
49 49 # itself, we'll keep going upwards and report the top of the nested
50 50 # set of trees.
51 51
|
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
52 52
53 53 # Check for well-known tree-type source code management (SCM) systems.
54 54 function primary_type
55 55 {
56 56 typeset scmid
57 57
58 58 [ -d "$1/Codemgr_wsdata" ] && scmid="$scmid teamware"
59 59 [ -d "$1/.hg" ] && scmid="$scmid mercurial"
60 60 [ -d "$1/CVS" ] && scmid="$scmid cvs"
61 61 [ -d "$1/.svn" ] && scmid="$scmid subversion"
62 + [ -d "$1/.git" ] && scmid="$scmid git"
62 63 echo $scmid
63 64 }
64 65
65 66 if [[ -n "$CODEMGR_WS" ]]; then
66 67 if [[ ! -d "$CODEMGR_WS" ]]; then
67 68 print -u2 "which_scm: $CODEMGR_WS is not a directory."
68 69 exit 1
69 70 fi
70 71 set -- $(primary_type "$CODEMGR_WS")
71 72 if [[ $# != 1 ]]; then
72 73 set -- unknown
73 74 fi
74 75 echo "$1 $CODEMGR_WS"
75 76 exit 0
76 77 fi
77 78
78 79 ORIG_CWD=$(pwd)
79 80
80 81 if [[ -d RCS ]]; then
81 82 echo "rcs $ORIG_CWD"
82 83 exit 0
83 84 fi
84 85
85 86 # If it's not Teamware, it could just be local SCCS.
86 87 LOCAL_TYPE=
87 88 [[ -d SCCS ]] && LOCAL_TYPE="sccs"
88 89
89 90 # Scan upwards looking for top of tree.
90 91 DIR=$ORIG_CWD
91 92 CWD_TYPE=$(primary_type "$DIR")
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
92 93 SCM_TYPE=
93 94 while [[ "$DIR" != / ]]; do
94 95 set -- $(primary_type "$DIR")
95 96 if [[ $# > 1 ]]; then
96 97 echo "unknown $ORIG_CWD"
97 98 exit 0
98 99 fi
99 100 SCM_TYPE="$1"
100 101 # We're done searching if we hit either a change in type or the top
101 102 # of a "third type" control system.
102 - if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == mercurial || \
103 - "$SCM_TYPE" == teamware ]]; then
103 + if [[ "$SCM_TYPE" != "$CWD_TYPE" || "$SCM_TYPE" == git || \
104 + "$SCM_TYPE" == mercurial || "$SCM_TYPE" == teamware ]]; then
104 105 break
105 106 fi
106 107 PREVDIR="$DIR"
107 108 DIR=$(dirname "$DIR")
108 109 done
109 110
110 111 # We assume here that the system root directory isn't the root of the SCM.
111 112
112 113 # Check for the "second type" of repository. In all cases, we started
113 114 # out in the tree and stepped out on the last iteration, so we want
114 115 # $PREVDIR.
115 116 if [[ "$CWD_TYPE" == cvs || "$CWD_TYPE" == subversion ]]; then
116 117 echo "$CWD_TYPE $PREVDIR"
117 118 exit 0
118 119 fi
119 120
120 121 # If we still don't know what it is, then check for a local type in the
121 122 # original directory. If none, then we don't know what it is.
122 123 if [[ -z "$SCM_TYPE" ]]; then
123 124 if [[ -z "$LOCAL_TYPE" ]]; then
124 125 SCM_TYPE=unknown
125 126 else
126 127 SCM_TYPE=$LOCAL_TYPE
127 128 DIR=$ORIG_CWD
128 129 fi
129 130 fi
130 131
131 132 echo "$SCM_TYPE $DIR"
132 133 exit 0
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX