3 # Update copyright information in source code with information from
4 # the bzr repository. Run from the BE repository root.
8 # adjust the AUTHORS file
9 AUTHORS=`bzr log | grep '^ *committer\|^ *author' | cut -d: -f2 | sed 's/ <.*//;s/^ *//' | sort | uniq`
10 AUTHORS=`echo "$AUTHORS" | grep -v 'j\^\|wking\|John Doe'` # remove non-names
11 echo "Bugs Everywhere was written by:" > AUTHORS
12 echo "$AUTHORS" >> AUTHORS
14 CURRENT_YEAR=`date +"%Y"`
15 FILES=`grep -rc "# Copyright" . | grep -v ':0$' | cut -d: -f1`
16 TMP=`mktemp BE_update_copyright.XXXXXXX`
21 if [ "${file:0:5}" == "./.be" ]; then
24 if [ "${file:0:6}" == "./.bzr" ]; then
27 if [ "${file:0:7}" == "./build" ]; then
30 if [ "$file" == "./COPYING" ]; then
33 if [ "$file" == "./update_copyright.sh" ]; then
36 if [ "$file" == "./xml/catmutt" ]; then
39 echo "Processing $file"
41 # Get author history from bzr
42 AUTHORS=`bzr log "$file" | grep "^ *author: \|^ *committer: " | cut -d: -f2 | sed 's/^ *//;s/ *$//' | sort | uniq`
44 continue # bzr doesn't version that file
46 ORIG_YEAR=`bzr log "$file" | grep "^ *timestamp: " | tail -n1 | sed 's/^ *//;' | cut -b 16-19`
48 # Tweak the author list to make up for problems in the bzr
49 # history, change of email address, etc.
51 # Consolidate Aaron Bentley
52 AUTHORS=`echo "$AUTHORS" | sed 's/<abentley@panoramicfeedback.com>/and Panometrics, Inc./'`
53 GREP_OUT=`echo "$AUTHORS" | grep 'Aaron Bentley and Panometrics, Inc.'`
54 if [ -n "$GREP_OUT" ]; then
55 AUTHORS=`echo "$AUTHORS" | grep -v '^Aaron Bentley <aaron.bentley@utoronto.ca>$'`
58 # Consolidate Ben Finney
59 AUTHORS=`echo "$AUTHORS" | sed 's/John Doe <jdoe@example.com>/Ben Finney <ben+python@benfinney.id.au>/'`
60 GREP_OUt=`echo "$AUTHORS" | grep 'Ben Finney <ben+python@benfinney.id.au>'`
61 if [ -n "$GREP_OUT" ]; then
62 AUTHORS=`echo "$AUTHORS" | grep -v '^Ben Finney <benf@cybersource.com.au>$'`
65 # Consolidate Chris Ball
66 GREP_OUT=`echo "$AUTHORS" | grep 'Chris Ball <cjb@laptop.org>'`
67 if [ -n "$GREP_OUT" ]; then
68 AUTHORS=`echo "$AUTHORS" | grep -v '^Chris Ball <cjb@thunk.printf.net>$'`
71 # Consolidate Trevor King
72 AUTHORS=`echo "$AUTHORS" | grep -v "wking <wking@mjolnir>"`
75 AUTHORS=`echo "$AUTHORS" | sort | uniq`
77 # Generate new Copyright string
78 if [ "$ORIG_YEAR" == "$CURRENT_YEAR" ]; then
79 DATE_RANGE="$CURRENT_YEAR"
82 DATE_RANGE="${ORIG_YEAR}-${CURRENT_YEAR}"
85 NUM_AUTHORS=`echo "$AUTHORS" | wc -l`
86 FIRST_AUTHOR=`echo "$AUTHORS" | head -n 1`
87 COPYRIGHT="# Copyright (C) $DATE_RANGE $FIRST_AUTHOR"
88 if [ $NUM_AUTHORS -gt 1 ]; then
89 OTHER_AUTHORS=`echo "$AUTHORS" | tail -n +2`
91 COPYRIGHT=`echo "$COPYRIGHT\\n# $DATE_SPACE $AUTHOR"`
92 done < <(echo "$OTHER_AUTHORS")
96 # Strip old copyright info and replace with tag
97 awk 'BEGIN{incopy=0}{if(match($0, "^# Copyright")>0){incopy=1; print "-xyz-COPYRIGHT-zyx-"}else{if(incopy=0){print $0}else{if(match($0, "^# ")==0){incopy=0; print $0}}}}' "$file" > "$TMP"
99 # Replace tag in with new string
100 sed -i "s/^-xyz-COPYRIGHT-zyx-$/$COPYRIGHT/" "$TMP"