Skip to content

Commit 350c39c

Browse files
sickpiggandrewstone
authored andcommitted
Port copyright tool from Core repo. (bitcoin#895)
* [devtools] script support for managing source file copyright headers This is a port of Core bitcoin#8674 Three subcommands to this script: 1) ./copyright_header.py report Examines git-tracked files with extensions that match: INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.py'] Helps to: -> Identify source files without copyright -> Identify source files added with something other than "The Bitcoin Core developers" holder so we can be sure it is appropriate -> Identify unintentional typos in the copyright line 2) ./copyright_header.py update Replaces fix-copyright-headers.py. It does file editing in native python rather than subprocessing out to perl as was the case with fix-copyright-headers.py. It also shares code with the 'report' functions. 3) ./copyright_header.py insert Inserts a copyright header into a source file with the proper format and dates. * [scripts] Add missing univalue file to copyright_header.py * Adapt copyright_header.py to the BU repo - add a new set of expected copyright holders - define "The Bitcoin Unlimited developers" as the default copyright holder
1 parent 3da975b commit 350c39c

File tree

3 files changed

+677
-62
lines changed

3 files changed

+677
-62
lines changed

contrib/devtools/README.md

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,64 @@ clang-format.py
77

88
A script to format cpp source code according to [.clang-format](../../src/.clang-format). This should only be applied to new files or files which are currently not actively developed on. Also, git subtrees are not subject to formatting.
99

10-
fix-copyright-headers.py
11-
========================
12-
13-
Every year newly updated files need to have its copyright headers updated to reflect the current year.
14-
If you run this script from the root folder it will automatically update the year on the copyright header for all
15-
source files if these have a git commit from the current year.
16-
17-
For example a file changed in 2015 (with 2015 being the current year):
18-
19-
```// Copyright (c) 2009-2013 The Bitcoin Unlimited developers```
20-
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
21-
22-
would be changed to:
10+
copyright\_header.py
11+
====================
2312

24-
```// Copyright (c) 2009-2015 The Bitcoin Unlimited developers```
25-
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
13+
Provides utilities for managing copyright headers of `The Bitcoin Unlimited
14+
developers` in repository source files. It has three subcommands:
15+
16+
```
17+
$ ./copyright_header.py report <base_directory> [verbose]
18+
$ ./copyright_header.py update <base_directory>
19+
$ ./copyright_header.py insert <file>
20+
```
21+
Running these subcommands without arguments displays a usage string.
22+
23+
copyright\_header.py report \<base\_directory\> [verbose]
24+
---------------------------------------------------------
25+
26+
Produces a report of all copyright header notices found inside the source files
27+
of a repository. Useful to quickly visualize the state of the headers.
28+
Specifying `verbose` will list the full filenames of files of each category.
29+
30+
copyright\_header.py update \<base\_directory\> [verbose]
31+
---------------------------------------------------------
32+
Updates all the copyright headers of `The Bitcoin Unlimited developers` which were
33+
changed in a year more recent than is listed. For example:
34+
```
35+
// Copyright (c) <firstYear>-<lastYear> The Bitcoin Unlimited developers
36+
```
37+
will be updated to:
38+
```
39+
// Copyright (c) <firstYear>-<lastModifiedYear> The Bitcoin Unlimited developers
40+
```
41+
where `<lastModifiedYear>` is obtained from the `git log` history.
42+
43+
This subcommand also handles copyright headers that have only a single year. In
44+
those cases:
45+
```
46+
// Copyright (c) <year> The Bitcoin Unlimited developers
47+
```
48+
will be updated to:
49+
```
50+
// Copyright (c) <year>-<lastModifiedYear> The Bitcoin Unlimited developers
51+
```
52+
where the update is appropriate.
53+
54+
copyright\_header.py insert \<file\>
55+
------------------------------------
56+
Inserts a copyright header for `The Bitcoin Unlimited developers` at the top of the
57+
file in either Python or C++ style as determined by the file extension. If the
58+
file is a Python file and it has `#!` starting the first line, the header is
59+
inserted in the line below it.
60+
61+
The copyright dates will be set to be `<year_introduced>-<current_year>` where
62+
`<year_introduced>` is according to the `git log` history. If
63+
`<year_introduced>` is equal to `<current_year>`, it will be set as a single
64+
year rather than two hyphenated years.
65+
66+
If the file already has a copyright for `The Bitcoin Unlimited developers`, the
67+
script will exit.
2668

2769
git-subtree-check.sh
2870
====================

0 commit comments

Comments
 (0)