From 9039bdf7ffd3e08ea1c3610a999a1f8718faaa4b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 18 May 2018 16:39:29 +0200 Subject: Add copyright updating script --- copyright | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 copyright diff --git a/copyright b/copyright new file mode 100755 index 0000000..b9b5aa0 --- /dev/null +++ b/copyright @@ -0,0 +1,78 @@ +#! /usr/bin/env bash + +# Update copyright in a git project. The fact that it is a git project is +# used to avoid submodules as well as generated files. In other words, only +# files tracked by git are updated. +# +# Run from the project root. +# +usage="usage: copyright " + +owd=`pwd` +trap "{ cd $owd; exit 1; }" ERR +set -o errtrace # Trap in functions. + +function info () { echo "$*" 1>&2; } +function error () { info "$*"; exit 1; } + +while [ $# -gt 0 ]; do + case $1 in + *) + break + ;; + esac +done + +old="$1" +new="$2" + +if [ -z "$old" -o -z "$new" ]; then + error "$usage" +fi + +# Load submodules into a map. +# +declare -A submodules +for s in $(git submodule foreach -q 'echo $path'); do + submodules["$s"]=true +done + +# Get the list of files. +# +files=() +while IFS= read -r -d '' f; do + + if [ "${submodules["$f"]}" = true ]; then + info "skipping submodule $f" + continue + fi + + # Exclude symlinks (normally point into a submodule). + # + if test -L "$f"; then + info "skipping symlink $f" + continue + fi + + files+=("$f") + +done < <(git ls-tree -r HEAD -z --name-only ) + +# Process each file. +# +for f in "${files[@]}"; do + + info "processing $f" + + sed -i -re "s/(Copyright \(c\) [0-9]+)-$old (Code Synthesis)/\1-$new \2/" "$f" + + # Grep for matching copyrights that didn't end with $old (or have other + # discrepancies like single year only, etc). + # + grep -vE "Copyright \(c\) [0-9]+-$new (Code Synthesis)" "$f" | \ + grep -iE --color=auto "Copyright.*Code Synthesis" || true + + # Grep for the old year (for review). + # + grep --color=auto --with-filename "$old" "$f" || true +done -- cgit v1.1