aboutsummaryrefslogtreecommitdiff
path: root/contrib/gcc-changelog/git_email.py
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-05-13 14:27:30 +0200
committerMartin Liska <mliska@suse.cz>2020-05-13 14:27:30 +0200
commitc10aa1f07366732b22a8dc1cb0c63914e91b0434 (patch)
treeda7a74d1d2b274d68a1657308fc9e6f83bcda5a4 /contrib/gcc-changelog/git_email.py
parent18edc195442291525e04f0fa4d5ef972155117da (diff)
downloadgcc-c10aa1f07366732b22a8dc1cb0c63914e91b0434.zip
gcc-c10aa1f07366732b22a8dc1cb0c63914e91b0434.tar.gz
gcc-c10aa1f07366732b22a8dc1cb0c63914e91b0434.tar.bz2
Add gcc-changelog related scripts.
* gcc-changelog/git_check_commit.py: New file. * gcc-changelog/git_commit.py: New file. * gcc-changelog/git_email.py: New file. * gcc-changelog/git_repository.py: New file. * gcc-changelog/git_update_version.py: New file.
Diffstat (limited to 'contrib/gcc-changelog/git_email.py')
-rwxr-xr-xcontrib/gcc-changelog/git_email.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py
new file mode 100755
index 0000000..e1d6b70
--- /dev/null
+++ b/contrib/gcc-changelog/git_email.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 3, or (at your option) any later
+# version.
+#
+# GCC 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
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>. */
+
+import os
+import sys
+from itertools import takewhile
+
+from dateutil.parser import parse
+
+from git_commit import GitCommit
+
+from unidiff import PatchSet
+
+DATE_PREFIX = 'Date: '
+FROM_PREFIX = 'From: '
+
+
+class GitEmail(GitCommit):
+ def __init__(self, filename, strict=False):
+ self.filename = filename
+ diff = PatchSet.from_filename(filename)
+ date = None
+ author = None
+
+ lines = open(self.filename).read().splitlines()
+ lines = list(takewhile(lambda line: line != '---', lines))
+ for line in lines:
+ if line.startswith(DATE_PREFIX):
+ date = parse(line[len(DATE_PREFIX):])
+ elif line.startswith(FROM_PREFIX):
+ author = GitCommit.format_git_author(line[len(FROM_PREFIX):])
+ header = list(takewhile(lambda line: line != '', lines))
+ body = lines[len(header) + 1:]
+
+ modified_files = []
+ for f in diff:
+ if f.is_added_file:
+ t = 'A'
+ elif f.is_removed_file:
+ t = 'D'
+ else:
+ t = 'M'
+ modified_files.append((f.path, t))
+ super().__init__(None, date, author, body, modified_files,
+ strict=strict)
+
+
+if __name__ == '__main__':
+ if len(sys.argv) == 1:
+ allfiles = []
+ for root, _dirs, files in os.walk('patches'):
+ for f in files:
+ full = os.path.join(root, f)
+ allfiles.append(full)
+
+ success = 0
+ for full in sorted(allfiles):
+ email = GitEmail(full, False)
+ print(email.filename)
+ if email.success:
+ success += 1
+ print(' OK')
+ else:
+ for error in email.errors:
+ print(' ERR: %s' % error)
+
+ print()
+ print('Successfully parsed: %d/%d' % (success, len(allfiles)))
+ else:
+ email = GitEmail(sys.argv[1], False)
+ if email.success:
+ print('OK')
+ email.print_output()
+ else:
+ if not email.lines:
+ print('Error: patch contains no parsed lines', file=sys.stderr)
+ email.print_errors()