summaryrefslogtreecommitdiff
path: root/merge-helpers/mkChangeLogList
blob: a97bb28bf153791bedf01e5d8f1735d295cdce3b (plain)
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
#! /bin/sh
#
#   Use git from the current directory and put the file names
#   in suitable format for use in a ChangeLog.
#
#   TODO:  Initial conversion from cvs
#

mklog_()
{
  cat >XXX
  if test `cat XXX | wc -l` -ne 0 ; then
    (cat XXX | cut -d':' -f2 | \
    sed -e '$!s/$/,/' -e '$s/$/:/' ; \
    test $? -ne 0 || echo "$*" )| \
    xargs -s80 | sed -e '1s/^/	\* /' -e '2,$s/^/	/' 
  fi
  rm -f XXX
}

progname=${0##*/}
usage()
{
  echo "$progname [-ln] [-u user] [-U user_information] [-m message] [-M msgfile]"
  exit 1
}

print_name="no"
user=$LOGNAME
git_local_arg=""
basedir=.
while getopts d:lnM:m:p:c:u:U: OPT
do
  case "$OPT" in 
    d) basedir=$OPTARG ;;
    l) git_local_arg="-l" ;;
    n) print_name="yes" ;;
    p) prnum=$OPTARG ;;
    c) coverity_num=$OPTARG ;;
    m) message=$OPTARG ;; 
    M) message=`cat $OPTARG` ;; 
    u) user=$OPTARG ; print_name="yes" ;;
    U) user_name=$OPTARG ; print_name="yes" ;;
    *) usage ;;
  esac
done

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

args=$*

dirarg="${basedir}"

# 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

if [ ! -r ChangeLog ] ; then
  ( echo "There is no ChangeLog in this directory." ;
    echo "Where are you putting the entry?" )>/dev/stderr
  exit 1
fi

case ${VCS} in
  cvs)
    # done parsing arguments, now work 
    if [ "X${CVSROOT}" = "X" ] ; then
      CVS=cvs
    else
      CVS="cvs -d ${CVSROOT}"
    fi
    CVS="${CVS}"

    files_modded=`${CVS} diff ${dirarg} 2>&1 | grep ^Index | wc -l`
    files_added=`${CVS} diff ${dirarg} 2>&1 | grep "is a new entry, no " | wc -l`
    files_deleted=`${CVS} diff ${dirarg} 2>&1 | grep " was removed, no " | wc -l`
    ;;
  git)
    files_modded=`git status ${dirarg} 2>&1 | grep "modified: " | wc -l`
    files_added=`git status ${dirarg} 2>&1 | grep "new file: " | wc -l`
    files_deleted=0
    #files_deleted=`${CVS} diff ${dirarg} 2>&1 | grep " was removed, no " | wc -l`
    ;;
  *)
    echo "${VCS} to be implemented"
    exit 1
    ;;
esac

files_changed=`expr ${files_modded} + ${files_added} + ${files_deleted}`
if test ${files_changed} -eq 0 ; then
  exit 0
fi

if test ${print_name} = "yes" ; then
  if test "X${user_name}" = "X" ; then
    if test "X${user}" = "X" ; then
      echo "User not specified (LOGNAME not set or no -u option)"
      usage
    fi

    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

  date=`date +%Y-%m-%d`
  echo "${date}	${user_name}"
  echo
fi

if test "X${prnum}" != "X" ; then
  echo "	PR ${prnum}"
fi
if test "X${coverity_num}" != "X" ; then
  echo "	Coverity Id ${coverity_num}"
fi

case ${VCS} in
  cvs)
    # Generate list of modified files
    ${CVS} diff ${dirarg} 2>/dev/null | grep ^Index | mklog_ ${message}

    # Generate list of deleted files
    test ${files_added} -gt 1 && plural=s
    ${CVS} diff ${dirarg} 2>&1 | grep "is a new entry, no comparison" | \
      sed -e 's/^.*: //' -e 's/ is a .*$//' | mklog_ "New file${plural}."

    # Generate list of removed files
    ${CVS} diff ${dirarg} 2>&1 | grep "was removed, no comparison" | \
      sed -e 's/^.*: //' -e 's/ was removed, no comparison.*$//' | \
      mklog_ Removed.
    ;;
  git)
    # Generate list of modified files
    git status 2>&1 | grep "modified: " | mklog_ ${message}

    # Generate list of deleted files
    test ${files_added} -gt 1 && plural=s
    git status 2>&1 | grep "new file: " | \
      sed -e 's/^.*: //' -e 's/ is a .*$//' | mklog_ "New file${plural}."

    # Generate list of removed files
    #${CVS} diff ${dirarg} 2>&1 | grep "was removed, no comparison" | \
    #  sed -e 's/^.*: //' -e 's/ was removed, no comparison.*$//' | \
    #  mklog_ Removed.
    ;;
  *)
    echo "${VCS} to be implemented"
    exit 1
    ;;
esac

echo

# rm -f XXX
exit 0