summaryrefslogtreecommitdiffstats
path: root/merge-helpers/commit
blob: 1f9b473876e647c4fd5236cb6e9138671e2e8125 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#! /bin/sh
#
#  Recurse from current directory assisting in generating ChangeLog entries
#  and committing files to the Source Code Repository.
#
#   TODO:  
#     + Currently supports CVS and git. Could add svn
#

progname=${0##*/}
usage()
{
  echo "$progname [-dlq] [-e editor] [-u user] [-m message] [-M msgfile]"
  echo "options:"
  echo "  -d         .. debug, don't delete change files";
  echo "  -q         .. quiet, don't display directories";
  echo "  -l         .. local directory only";
  echo "  -m message .. text to use for modified files";
  echo "  -M msgfile .. file containing to use for modified files";
  echo "  -u user    .. use user instead of LOGNAME";
  echo "  -U user    .. use explicit user info -- not from passwd";
  echo "  -p PR      .. PR info";
  echo "  -c CID     .. Coverity Id number";
  echo
  exit 1
}

# Determine VCS in use
isgit()
{
  depth=0
  dir=.git
  while [ $depth -lt 10 ]
  do
    if [ -d ${dir} ] ; then
      return 1
    fi
    dir=../${dir}
    depth=`expr ${depth} + 1`
  done  
  return 0
}

isgit
if [ $? -eq 1 ] ; then
  VCS=git
elif [ -d CVS ] ; then
  VCS=cvs
else
  echo "This does not look like a checkout from a VCS I understand."
  exit 1
fi

editor="vim"
changefile="changes-xxx"
rem_changes="yes"
quiet="no"
user=$LOGNAME
mkchoptions="-n"
message=
localdir="no"
while getopts dlqe:M:m:u:U:p:c: OPT
do
  case "$OPT" in 
    d) rem_changes="yes" ;;
    e) editor=$OPTARG ;;
    l) localdir="yes" ;;
    m) message=$OPTARG ;; 
    M) message=`cat $OPTARG` ;; 
    q) quiet="yes" ;;
    u) user=$OPTARG ; mkchoptions=${mkchoptions}" -u ${user}" ;;
    U) userArg="-U" userInfo=$OPTARG ;;
    p) PrInfo=$OPTARG ; mkchoptions=${mkchoptions}" -p ${PrInfo}" ;;
    c) CoverityInfo=$OPTARG ; mkchoptions=${mkchoptions}" -c ${CoverityInfo}" ;;
    *) usage ;;
  esac
done

export message
let $((shiftcount = $OPTIND - 1))
shift #shiftcount

args=$*

# find ChangeLogs and print them by depth
get_subdirs()
{
  find . -name ChangeLog | while read f
  do
    case $1 in
      */*/*/*/*/*/*/*/*/*) d=9 ;;
      */*/*/*/*/*/*/*/*) d=8 ;;
      */*/*/*/*/*/*/*) d=7 ;;
      */*/*/*/*/*/*) d=6 ;;
      */*/*/*/*/*) d=5 ;;
      */*/*/*/*) d=4 ;;
      */*/*/*) d=3 ;;
      */*/*) d=2 ;;
      */*) d=1 ;;
      *) d=0 ;;
    esac
    echo ${d} ${f}
  done | sort -n -r | cut -d' ' -f2- | while read f
  do
    dirname $f
  done
}
if [ ${localdir} = "yes" ] ; then
  subdirs="."
else
  subdirs=`get_subdirs`
fi

# Make sure we have user information
if test "X${userInfo}" = "X" ; then
  user_name=`grep ^${user} /etc/passwd | cut -d':' -f5 | cut -d',' -f1`
  if test "X${user_name}" = "X" ; then
    echo "User information not set"
    usage
  fi
fi

commit_helper()
{
  if [ $? -ne 0 ] ; then
    return
  fi

  prepend ${changefile}

  # Specify VCS support directory
  case ${VCS} in
    cvs)
      ${CVS} up ChangeLog
      cvs commit -F ${changefile}
      ;;
    git)
      echo "git commit -F ${changefile}"
      git add ${changefile} 
      git commit -F ${changefile}
      ;;
    *) echo "${VCS} to be implemented" ;  exit 1 ;;
  esac
}

# Specify VCS support directory
case ${VCS} in
  cvs) VCSDIR=CVS ;;
  git) VCSDIR=.git ;;
  *)
    echo "${VCS} to be implemented"
    exit 1
    ;;
esac

for ddir in ${subdirs} ; do
  test "${ddir}" = "${VCSDIR}" && continue
  test "${ddir}" = "autom4te.cache" && continue
  test "${ddir}" = "install" && continue
  if [ -d "${ddir}" ]; then
    case ${VCS} in
      cvs) 
	if [ ! -d "${ddir}/${VCSDIR}" ] ; then
	  echo "WARNING - ${ddir} is not in .git"
	  continue
	fi
        ;;
      git)
        ;;
      *)
        echo "${VCS} to be implemented"
        exit 1
        ;;
    esac
    test -f "${ddir}/ChangeLog" || continue
    cd "$ddir" >/dev/null
    mkChangeLogList ${mkchoptions} ${userArg} "${userInfo}" \
          -m "${message}" >${changefile}
    test $? -ne 0 && continue 
    while test -s ${changefile} ; do
      fullpath=`pwd`
      test "$quiet" = "no" && echo "** directory: $fullpath **"
      cat ${changefile}
      response="n"
      read -p "Commit changes? [y/n/e(edit)]: " response
      case ${response} in
        y) commit_helper; break ;;
        n) break ;;
        e) ${editor} ${changefile} ;;
        *) echo "*** enter y,n, or e ***" ;;
      esac
    done
    test $rem_changes = "yes" && rm -rf $changefile
    cd - >/dev/null
  fi
done