Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Mass edits: commits that moved, renamed or reformatted code across many files.
# git blame skips them with: git config blame.ignoreRevsFile .git-blame-ignore-revs
# GitHub skips them in its blame view, and scripts/update-copyright.py does not count
# them as contributions to a file.

# 2016-03-16 Integrate all code inside a namespace
b3753678110ef9e0758fc953bedb75e44d536a50

# 2016-11-29 Explicitely wrote namespace in file instead of using MM_*_NAMESPACE (related to #278).
557227ac89e97a258bf19bffb61fc4fc62b90838

# 2017-04-16 Move files to src/mapmap
bbdb002af2a7f1a2feeb68a0d3199e97b40bcf90

# 2017-08-01 Ignore mocs, obj and qrc directory
58ae7b474df27cc5a2bb3c7a20d3c0adead264e7

# 2017-08-01 Ignore mocs, obj and qrc directory (reverted from commit 58ae7b474df27cc5a2bb3c7a20d3c0adead264e7)
e328d4e1b467981ff93a9116233e585102d0ef2a

# 2017-08-01 The core of the app reorganized
a7ce024842f0519c55798fe45bee2b081870de29

# 2017-08-01 Reorganisation of Gui source files
8d72b2117e30082ac112e9cbb7c7e81df292cdfa

# 2017-08-01 Third part of Gui rearranged
499b730905c0bfc6c4913b80061a0b4b3f6e63e3

# 2026-05-22 Rename Paint to Source and Mapping to Layer throughout codebase
b687db3dbbf6a6a3dd7b78bb24f8a6949fdadeea
11 changes: 11 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# One name for each person who committed to MapMap under several names or addresses.
# git log, git shortlog and git blame read it, and so does scripts/update-copyright.py.
Sofian Audry <info@sofianaudry.com> Tats <info@sofianaudry.com>
Sofian Audry <info@sofianaudry.com> Sofian <info@sofianaudry.com>
Dame Diongue <baydamd@gmail.com> baydam <baydamd@gmail.com>
Dame Diongue <baydamd@gmail.com> Bay Dam <baydamd@gmail.com>
Alexandre Quessy <alexandre@quessy.net> <alexandre.quessy@collabora.com>
Vasilis Liaskovitis <vliaskov@gmail.com> <vasilis.liaskovitis@profitbricks.com>
Lucas Adair <33071958+ltsadair@users.noreply.github.com> ltsAdair <33071958+ltsadair@users.noreply.github.com>
Jonathan Roman Bland <jonathan.bland@maine.edu> jonathan <jonathan.bland@maine.edu>
Sylvain Cormier <sylvain@jin-motion.com> sylvain <sylvain@jin-motion.com>
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ The command `/mm:open-pr` of the `mm` plugin does all of this.

- A change of the project format updates `docs/project-format.md` in the same commit, and follows its principles and naming styles: keys in snake_case, types `<provider>:<name>` with names in kebab-case.

- A new source file starts with the licence header of the others, with one line per author and no email address: ` * (c) 2026 Firstname Lastname`. `scripts/update-copyright.py` writes these lines from the history of git: every person who changed the file, with the years of their commits, by first contribution. It takes the names from `.mailmap` and leaves out the mass edits listed in `.git-blame-ignore-revs` (moves, namespaces, renamings across the code); add a mass edit there once it is in `dev`, since its hash changes when it is integrated. Run the script before a release; `--check` lists the files that are not up to date.

- Follow the existing style: Qt coding style, two-space indentation, code and comments in English.

- Document every public class and function. Give every number used in a calculation a named constant.
Expand Down
232 changes: 232 additions & 0 deletions scripts/update-copyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
#!/usr/bin/env python3
"""Write the authors of each source file of MapMap in its header, from the history of git.

Usage: python3 scripts/update-copyright.py [--check] [file ...]

Each person who changed a file gets one line, with the years of their commits on it,
in the order of their first contribution:

* (c) 2013-2026 Sofian Audry
* (c) 2014-2018 Dame Diongue

What is not a contribution: a commit that only changes spaces or blank lines, only the
lines of the authors, only renames the file, or that .git-blame-ignore-revs lists (the
mass edits: moves, namespaces, renamings across the code). The names of people come
from .mailmap, which gives each person one name. An author of the header that the
history does not know, such as the authors of code older than MapMap, is kept, with its
notes; the line of "MapMap contributors" is dropped. A file without the licence header
is left as it is. Requires git and the Python 3 standard library.
"""

import argparse
from pathlib import Path
import re
import subprocess
import sys

# The source files whose headers the script writes, and those it leaves alone.
SOURCE_PATTERNS = ("src/*.h", "src/*.cpp", "src/*.mm", "tests/*.h", "tests/*.cpp")
THIRD_PARTY_PREFIXES = ("src/control/qosc/",)
GENERATED_PREFIX = "moc_"

# The list of the mass edits, which is also the list that git blame and GitHub ignore.
IGNORED_REVISIONS_FILE = ".git-blame-ignore-revs"

# A line of an author: " * (c) 2013 Name", " * (c) 2013-2026 Name", " * Copyright (c) 2013 Name".
AUTHOR_LINE = re.compile(r"^ \* (?:Copyright )?\([cC]\) (\d{4})(?:-(\d{4}))? (.+?)\s*$")
# A note under the line of an author, indented: " Based on code from Drone".
NOTE_LINE = re.compile(r"^ \*\s{2,}\S")
# A blank line of a comment.
BLANK_LINE = re.compile(r"^ \*?\s*$")
# What follows a name: " -- info(@)example(.)org" or " <info@example.org>".
CONTACT = re.compile(r"\s+(?:--\s.*|<[^>]*>)$")
# The first line of the licence, which says that a header is there.
LICENCE_START = " * This program is free software"
# The name that says nothing of who wrote the file.
VAGUE_NAME = "MapMap contributors"

# What git log writes before each commit (%x00 in its format).
COMMIT_MARK = "\x00"


def author_name(text):
"""Return the name of an author line, without the address that may follow it."""
return CONTACT.sub("", text).strip()


def author_line(first, last, name):
"""Return the line of an author for the given years."""
years = str(first) if first == last else "{}-{}".format(first, last)
return " * (c) {} {}".format(years, name)


def read_header_authors(lines):
"""Return where the lines of the authors are, and the authors with their years and notes.

The result is (start, end, entries): lines[start:end] hold the authors; each entry is
[first, last, name, notes]. With no author, start and end are where to insert them, or
None when the file has no licence header.
"""
if not lines or not lines[0].startswith("/*"):
return None, None, []
closing = next((i for i, line in enumerate(lines) if "*/" in line), None)
licence = next((i for i, line in enumerate(lines[:closing]) if line.startswith(LICENCE_START)), None)
if closing is None or licence is None:
return None, None, []

start = next((i for i in range(licence) if AUTHOR_LINE.match(lines[i])), None)
if start is None:
return licence, licence, []
entries = []
end = start
while end < licence and (AUTHOR_LINE.match(lines[end]) or (entries and NOTE_LINE.match(lines[end]))):
match = AUTHOR_LINE.match(lines[end])
if match:
first = int(match.group(1))
entries.append([first, int(match.group(2) or first), author_name(match.group(3)), []])
else:
entries[-1][3].append(lines[end])
end += 1
return start, end, entries


def rewrite(text, history):
"""Return the text of a file with the authors of its header and of its history.

history maps the name of each person who contributed to the file to the first and the
last years of their commits. Returns None for a file without the licence header.
"""
lines = text.split("\n")
start, end, entries = read_header_authors(lines)
if start is None:
return None

# The authors of the header first, in their order, each once, then the others, by name.
authors = []
known = {}
for first, last, name, notes in entries:
if name == VAGUE_NAME:
continue
if name in known:
known[name][0] = min(known[name][0], first)
known[name][1] = max(known[name][1], last)
known[name][3].extend(notes)
else:
known[name] = [first, last, name, list(notes)]
authors.append(known[name])
for name in sorted(history):
first, last = history[name]
if name in known:
known[name][0] = min(known[name][0], first)
known[name][1] = max(known[name][1], last)
else:
entry = [first, last, name, []]
authors.append(entry)
known[name] = entry
if not authors:
return text
order = sorted(range(len(authors)), key=lambda index: (authors[index][0], index))

block = []
for index in order:
first, last, name, notes = authors[index]
block.append(author_line(first, last, name))
block.extend(notes)
if start == end:
# A header without authors: they go before the licence, after a blank line.
if start > 0 and not BLANK_LINE.match(lines[start - 1]):
block.insert(0, " *")
block.append(" *")
return "\n".join(lines[:start] + block + lines[end:])


def is_contribution(changed_lines):
"""Return true when the lines a commit changed in a file are more than its authors.

A note line counts as a line of the authors only next to them, so that a commit that
changes an indented list of a comment elsewhere in the file still counts.
"""
touches_authors = any(AUTHOR_LINE.match(line) for line in changed_lines)
for line in changed_lines:
if AUTHOR_LINE.match(line) or BLANK_LINE.match(line):
continue
if touches_authors and NOTE_LINE.match(line):
continue
return True
return False


def ignored_revisions(path):
"""Return the commits that the list of mass edits names."""
if not path.exists():
return set()
revisions = set()
for line in path.read_text().splitlines():
line = line.split("#", 1)[0].strip()
if line:
revisions.add(line)
return revisions


def file_history(path, ignored):
"""Return the people who contributed to a file, with the first and last years of their commits."""
output = subprocess.run(
["git", "log", "--follow", "-w", "--ignore-blank-lines", "--no-color", "-p",
"--format=%x00%H%x09%aN%x09%ad", "--date=format:%Y", "--", str(path)],
check=True, capture_output=True, text=True, encoding="utf-8", errors="replace").stdout
history = {}
for chunk in output.split(COMMIT_MARK)[1:]:
heading, _, diff = chunk.partition("\n")
revision, name, year = heading.split("\t")
if revision in ignored:
continue
changed = [line[1:] for line in diff.split("\n")
if line[:1] in "+-" and line and not line.startswith(("+++", "---"))]
if not is_contribution(changed):
continue
first, last = history.get(name, (int(year), int(year)))
history[name] = (min(first, int(year)), max(last, int(year)))
return history


def source_files():
"""Return the source files of MapMap that git knows, third-party and generated code left out."""
output = subprocess.run(["git", "ls-files", "--", *SOURCE_PATTERNS],
check=True, capture_output=True, text=True).stdout
return [Path(name) for name in output.splitlines()
if not name.startswith(THIRD_PARTY_PREFIXES) and not Path(name).name.startswith(GENERATED_PREFIX)]


def main():
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0],
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("files", nargs="*", type=Path,
help="files to update; every source file when none is given")
parser.add_argument("--check", action="store_true",
help="change nothing; list the files whose authors are not up to date, and fail if there are any")
parser.add_argument("--ignore-revs-file", type=Path, default=Path(IGNORED_REVISIONS_FILE),
help="list of the mass edits, which are not contributions")
args = parser.parse_args()

ignored = ignored_revisions(args.ignore_revs_file)
outdated = []
skipped = []
for path in args.files or source_files():
text = path.read_text(encoding="utf-8")
updated = rewrite(text, file_history(path, ignored))
if updated is None:
skipped.append(path)
elif updated != text:
outdated.append(path)
if not args.check:
path.write_text(updated, encoding="utf-8")

for path in skipped:
print("No licence header, left as it is: {}".format(path), file=sys.stderr)
for path in outdated:
print(("Authors not up to date: {}" if args.check else "Updated: {}").format(path))
return 1 if args.check and outdated else 0


if __name__ == "__main__":
sys.exit(main())
6 changes: 3 additions & 3 deletions src/app/MainApplication.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* MainApplication.cpp
*
* (c) 2014 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2014 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2016 Dame Diongue -- baydamd(@)gmail(.)com
* (c) 2013-2014 Sofian Audry
* (c) 2014-2026 Alexandre Quessy
* (c) 2016-2020 Dame Diongue
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
6 changes: 3 additions & 3 deletions src/app/MainApplication.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* MainApplication.h
*
* (c) 2014 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2014 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2016 Dame Diongue -- baydamd(@)gmail(.)com
* (c) 2013-2014 Sofian Audry
* (c) 2014-2026 Alexandre Quessy
* (c) 2016-2020 Dame Diongue
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/AutoMapFrameSource.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AutoMapFrameSource.cpp
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/AutoMapFrameSource.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AutoMapFrameSource.h
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/AutoMapScan.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AutoMapScan.cpp
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/AutoMapScan.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* AutoMapScan.h
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/Correspondence.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Correspondence.cpp
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/Correspondence.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Correspondence.h
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/GrayCodeDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GrayCodeDecoder.cpp
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/GrayCodeDecoder.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GrayCodeDecoder.h
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion src/automap/GrayCodePattern.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* GrayCodePattern.cpp
*
* (c) 2026 MapMap contributors
* (c) 2026 Alexandre Quessy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down
Loading
Loading