| 1 | #!/bin/bash |
| 2 | # Updates a file's license header to the first year a commit touched it. |
| 3 | # Example: find -name \*.cpp -o -name \*.h|xargs -n1 -P8 /path/to/Tools/update-license-headers.sh |
| 4 | |
| 5 | filename=$1 |
| 6 | echo "Updating $filename..." |
| 7 | year=$(git log --diff-filter=A --follow --format=%ad --date=short "$1"|tail -n1|cut -d- -f1) |
| 8 | if [[ "$(head -n1 "$filename" | grep Copyright)" == "" ]] |
| 9 | then |
| 10 | tmp="$(mktemp)" |
| 11 | echo -e "// Copyright $year Dolphin Emulator Project\n// Licensed under GPLv2+\n// Refer to the license.txt file included.\n"|cat - "$filename" >"$tmp" |
| 12 | mv "$tmp" "$filename" |
| 13 | else |
| 14 | sed -ri "1 s|// Copyright ([0-9-]+) Dolphin Emulator Project|// Copyright $year Dolphin Emulator Project|" "$filename" |
| 15 | fi |