Skip to content

Commit b78f6c6

Browse files
author
MarcoFalke
committed
Merge #15258: Scripts and tools: Fix devtools/copyright_header.py to always honor exclusions
ad5e5a1 Scripts and tools: Drop no-longer-relevant copyright holder names (Ben Woosley) 2434ab5 Scripts and tools: Fix devtools/copyright_header.py to always honor exclusions (Ben Woosley) Pull request description: This script compared paths relative to the report directory to test for exclusion, meaning the `EXCLUDE_DIRS` directory exclusions did not work properly, as they were relative to the project root. Fix this by creating absolute paths through the combination of: 'git ls-files --full-name' and 'git rev-parse --show-toplevel' Once this is done, we can stop testing for the names that would otherwise appear when exclusion of leveldb, secp256k1, etc., did not work as intended. Tree-SHA512: 0fa9b0a627e8ddb2d899eedee927ea8a809cb2ceee87c0920c151e5ca2103f7d8c463e3b379d5e2eb925fc3d7d8003082ffd9cbc03907ca0c448e8238e3a2684
2 parents ab46fe6 + ad5e5a1 commit b78f6c6

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

contrib/devtools/copyright_header.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@ def applies_to_file(filename):
4848
# obtain list of files in repo according to INCLUDE and EXCLUDE
4949
################################################################################
5050

51-
GIT_LS_CMD = 'git ls-files'
51+
GIT_LS_CMD = 'git ls-files --full-name'.split(' ')
52+
GIT_TOPLEVEL_CMD = 'git rev-parse --show-toplevel'.split(' ')
5253

53-
def call_git_ls():
54-
out = subprocess.check_output(GIT_LS_CMD.split(' '))
54+
def call_git_ls(base_directory):
55+
out = subprocess.check_output([*GIT_LS_CMD, base_directory])
5556
return [f for f in out.decode("utf-8").split('\n') if f != '']
5657

57-
def get_filenames_to_examine():
58-
filenames = call_git_ls()
59-
return sorted([filename for filename in filenames if
58+
def call_git_toplevel():
59+
"Returns the absolute path to the project root"
60+
return subprocess.check_output(GIT_TOPLEVEL_CMD).strip().decode("utf-8")
61+
62+
def get_filenames_to_examine(base_directory):
63+
"Returns an array of absolute paths to any project files in the base_directory that pass the include/exclude filters"
64+
root = call_git_toplevel()
65+
filenames = call_git_ls(base_directory)
66+
return sorted([os.path.join(root, filename) for filename in filenames if
6067
applies_to_file(filename)])
6168

6269
################################################################################
@@ -83,24 +90,12 @@ def compile_copyright_regex(copyright_style, year_style, name):
8390
EXPECTED_HOLDER_NAMES = [
8491
"Satoshi Nakamoto\n",
8592
"The Bitcoin Core developers\n",
86-
"The Bitcoin Core developers \n",
8793
"Bitcoin Core Developers\n",
88-
"the Bitcoin Core developers\n",
89-
"The Bitcoin developers\n",
90-
"The LevelDB Authors\. All rights reserved\.\n",
9194
"BitPay Inc\.\n",
92-
"BitPay, Inc\.\n",
9395
"University of Illinois at Urbana-Champaign\.\n",
94-
"MarcoFalke\n",
9596
"Pieter Wuille\n",
96-
"Pieter Wuille +\*\n",
97-
"Pieter Wuille, Gregory Maxwell +\*\n",
98-
"Pieter Wuille, Andrew Poelstra +\*\n",
99-
"Andrew Poelstra +\*\n",
10097
"Wladimir J. van der Laan\n",
10198
"Jeff Garzik\n",
102-
"Diederik Huys, Pieter Wuille +\*\n",
103-
"Thomas Daede, Cory Fields +\*\n",
10499
"Jan-Klaas Kollhof\n",
105100
"Sam Rushing\n",
106101
"ArtForz -- public domain half-a-node\n",
@@ -146,7 +141,7 @@ def file_has_without_c_style_copyright_for_holder(contents, holder_name):
146141
################################################################################
147142

148143
def read_file(filename):
149-
return open(os.path.abspath(filename), 'r', encoding="utf8").read()
144+
return open(filename, 'r', encoding="utf8").read()
150145

151146
def gather_file_info(filename):
152147
info = {}
@@ -260,12 +255,9 @@ def print_report(file_infos, verbose):
260255
print(SEPARATOR)
261256

262257
def exec_report(base_directory, verbose):
263-
original_cwd = os.getcwd()
264-
os.chdir(base_directory)
265-
filenames = get_filenames_to_examine()
258+
filenames = get_filenames_to_examine(base_directory)
266259
file_infos = [gather_file_info(f) for f in filenames]
267260
print_report(file_infos, verbose)
268-
os.chdir(original_cwd)
269261

270262
################################################################################
271263
# report cmd
@@ -325,13 +317,13 @@ def get_most_recent_git_change_year(filename):
325317
################################################################################
326318

327319
def read_file_lines(filename):
328-
f = open(os.path.abspath(filename), 'r', encoding="utf8")
320+
f = open(filename, 'r', encoding="utf8")
329321
file_lines = f.readlines()
330322
f.close()
331323
return file_lines
332324

333325
def write_file_lines(filename, file_lines):
334-
f = open(os.path.abspath(filename), 'w', encoding="utf8")
326+
f = open(filename, 'w', encoding="utf8")
335327
f.write(''.join(file_lines))
336328
f.close()
337329

@@ -399,11 +391,8 @@ def update_updatable_copyright(filename):
399391
"Copyright updated! -> %s" % last_git_change_year)
400392

401393
def exec_update_header_year(base_directory):
402-
original_cwd = os.getcwd()
403-
os.chdir(base_directory)
404-
for filename in get_filenames_to_examine():
394+
for filename in get_filenames_to_examine(base_directory):
405395
update_updatable_copyright(filename)
406-
os.chdir(original_cwd)
407396

408397
################################################################################
409398
# update cmd

0 commit comments

Comments
 (0)