Skip to content

Conversation

@franzpoeschel
Copy link
Contributor

The license headers have often been forgotten in PRs. This PR uses a little script to update this info in the C++ files.

The script:

#!/usr/bin/env bash

get_copyright_banner() {
    grep --color=never -zPo '/\*[\s\S]*?Copyright[\s\S]*?\*/'
}

author_names() {
    local name="$1"
    if [[ "$name" = "Axel Huebl" ]]; then
        echo "$name"
    elif [[ "$name" = "Ben Wibking" ]]; then
        echo "$name"
    elif [[ "$name" = "C0nsultant" ]]; then
        echo "Fabian Koller"
    elif [[ "$name" = "Carsten Fortmann-Grote" ]]; then
        echo "$name"
    elif [[ "$name" = "David Grote" ]]; then
        echo "$name"
    elif [[ "$name" = "Franz Pöschel" ]]; then
        echo "Franz Poeschel"
    elif [[ "$name" = "guj" ]]; then
        echo "Junmin Gu"
    elif [[ "$name" = "Ilian Kara-Mostefa" ]]; then
        echo "$name"
    elif [[ "$name" = "Jean Luca Bez" ]]; then
        echo "$name"
    elif [[ "$name" = "Junmin Gu" ]]; then
        echo "$name"
    elif [[ "$name" = "L. Diana Amorim" ]]; then
        echo "$name"
    elif [[ "$name" = "Luca Fedeli" ]]; then
        echo "$name"
    elif [[ "$name" = "Paweł Ordyna" ]]; then
        echo "Pawel Ordyna"
    elif [[ "$name" = "Richard Pausch" ]]; then
        echo "$name"
    elif [[ "$name" = "Ulrik Günther" ]]; then
        echo "Ulrik Guenther"
    fi
}

get_authors() {
    local file="$1"
    local authors
    mapfile -t authors < <(
        git blame -p "$file" |
            grep -E '^[^[:space:]]' |
            awk '$1 == "author"' |
            sort |
            uniq |
            sed 's|^author ||'
    )
    for name in "${authors[@]}"; do
        author_names "$name"
    done
}

include_author() {
    local copyright_banner="$1"
    local author="$2"
    if grep "$author" <<<"$copyright_banner" >/dev/null 2>&1; then
        echo "$copyright_banner"
        return
    fi
    echo "$copyright_banner" |
        sed -E "s|(Copyright .*)|\1, $author|" |
        sed -E 's|([0-9]{4}-)[0-9]{4}|\12025|' |
        sed -E 's| ([0-9]{4}) | \1-2025 |'
}

make_banner() {
    local authorstring="$(
        printf '%s\n' "$(
            IFS=,
            echo "${authors[*]}"
        )" | sed 's|,|, |g'
    )"
    cat <<EOF
/* Copyright 2025 ${authorstring}
 *
 * This file is part of openPMD-api.
 *
 * openPMD-api is free software: you can redistribute it and/or modify
 * it under the terms of of either the GNU General Public License or
 * the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * openPMD-api is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License and the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * and the GNU Lesser General Public License along with openPMD-api.
 * If not, see <http://www.gnu.org/licenses/>.
 */
EOF
}

fix_file() {
    local filename="$1"
    local banner="$(get_copyright_banner <"$filename")"
    local authors
    mapfile -t authors < <(get_authors "$filename")
    if [[ -z "$banner" ]]; then
        local new_banner="$(
            make_banner "${authors[@]}" |
                sed -z 's|\n|\\n|g'
        )"
        sed -zi "s|^|$new_banner|" "$filename"
        return
    fi
    local original_banner="$banner"
    for author in "${authors[@]}"; do
        banner="$(include_author "$banner" "$author")"
    done
    old_single_line="$(
        grep Copyright <<<"$original_banner" |
            sed 's|\*|\\*|'
    )"
    new_single_line="$(grep Copyright <<<"$banner")"
    sed -i "s|${old_single_line}|${new_single_line}|" "$filename"
}

@franzpoeschel franzpoeschel requested a review from ax3l December 10, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant