MISS_HIT 0.9.45-dev Copyright Tool
MISS_HIT includes a small utility to help maintain copyright notices in your codebase (mh_copyright).
Gear icon

Copyright maintenance

Purpose

This tool aims assist developers with some common but annoying maintenance tasks relating to copyright notices in large projects. A simple search and replace is often not actually that simple, or changes something in e.g. a string that should not be changed. MH Copyright can perform some of these tasks for you.
Note: this tool must not be run in CI. It is a tool that assists you in one-off tasks, that must be reviewed (as copyright notices are generally considered to be important things).

Usage

The tool is configured and run from the command-line. It does respect the usual MISS_HIT configuration files: in directories where MISS_HIT is disabled, or directories that are excluded no changes are made. If you want to just consider all files, then use the --ignore-config common to all MISS_HIT tools.
The general usage is this:
$ mh_copyright ACTION {OPTION} [FILES|DIRS]
At least one action must be specified, and most likely you will want to provide one or more options.

Options

The following options are specific to MH Copyright.

--primary-entity

Defines the (primary) copyright holder. Depending on the action this has different effects. For example for the update year action, this identifies which notice to change; but for the change entity action this identifies what the final result should be.
If you use a configuration file, then MH Copyright will use the copyright_primary_entity if set, or copyright_entity set, if there is precisely one.

--year

Defines the year to which copyright notices should be updated to. By default this is the current year.

--template

A string that will be used to create new or modify existing copyright notices with a single year. By default this matches the copyright_regex. We highly recommend to never change or touch this. By default this is:
%(copy)s %(yend)u %(org)s

--template-range

A string that will be used to create new or modify existing copyright notices with a year range. By default this matches the copyright_regex. We highly recommend to never change or touch this. By default this is:
%(copy)s %(ystart)-%(yend)u %(org)s

--style

When adding a new copyright notice, then this flag determines if we start the notice with "(c) Copyright" or "Copyright (c)". There are three choices:
  • dynamic - The default. Choses c_last for code where Octave mode is enabled, and c_last otherwise.
  • c_first - Always chooses "(c) Copyright".
  • c_last - Always chooses "Copyright (c)".
Note this setting has no effect if a notice is changed: there we always keep the existing style (i.e. we use whatever is matched in the copy subgroup of the copyright regex).

Actions

Note that only a single action can be performed. If you want to do more, just invoke the tool twice.

--update-year

Updates the year for the primary copyright holder. For example it might change this notice
% (c) Copyright 2020 Potato Inc.
% (c) Copyright 2020 Florian Schanda
% (c) Copyright 2010-2019 ACME GmbH
To this:
% (c) Copyright 2020 Potato Inc.
% (c) Copyright 2020-2021 Florian Schanda
% (c) Copyright 2010-2019 ACME GmbH

--change-entity=OLD_ENTITY

Replaces the old entity with the primary copyright holder. Leaves year ranges unchanged. For example:
% (c) Copyright 1998-2020 Old Company GmbH
Will be changed to this:
% (c) Copyright 1998-2020 New Company GmbH

--merge

A more complex operation that merged multiple copyright notices into a single one that spans the entire range of all merged entities. The use case here is a company renaming itself multiple times; and nobody having updated notices.
All copyright_entity entries from the configuration are considered as candidates, except for copyright_3rd_party_entity. All copyright_entity entries will be rewritten to the primary copyright entity.
For example consider this miss_hit.cfg file:
copyright_entity: "Florian Schanda"
copyright_entity: "Potato GmbH"
copyright_entity: "Kitten GmbH"
copyright_3rd_party_entity: "Feature not a Bug Consulting Inc."
And now consider this set of copyright notices:
% (c) Copyright 2020 Potato GmbH
% (c) Copyright 1998-1999 Feature not a Bug Consulting Inc.
% (c) Copyright 2021 Florian Schanda
If we run the tool, setting the primary copyright holder to "Florian Schanda", we should get this:
% (c) Copyright 1998-1999 Feature not a Bug Consulting Inc.
% (c) Copyright 2020-2021 Florian Schanda

--add-notice

Adds a new copyright notice with the current year and primary copyright holder to files without a notice. We do not attempt to insert this into the docstring (if any) of the primary entity, but instead this notice is added to the top of the file (or at the end of the file docstring, if it exists).
Please take special care when using this option, and very carefully review; as adding copyright notices to files that you cannot claim copyright over might have interesting legal implications later on.