diff options
author | Martin Liska <mliska@suse.cz> | 2022-12-11 17:18:12 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2022-12-11 17:22:25 +0100 |
commit | b045179973161115c7ea029b2788f5156fc55cda (patch) | |
tree | fa6e261f5badad137e27f1589c0b4d5b4bfb44b0 | |
parent | 6d799f0aed18be25a5c908499b6411ab6d06b78c (diff) | |
download | gcc-b045179973161115c7ea029b2788f5156fc55cda.zip gcc-b045179973161115c7ea029b2788f5156fc55cda.tar.gz gcc-b045179973161115c7ea029b2788f5156fc55cda.tar.bz2 |
unidiff: use newline='\n' argument
In order to support CR on a line, we need to open files
with newline='\n' as our line endings supposed to be of UNIX style.
contrib/ChangeLog:
* check_GNU_style.py: Use newline=\n.
* check_GNU_style_lib.py: Simplify.
* gcc-changelog/git_commit.py: Fix issues seen
Rust patchset.
* gcc-changelog/git_email.py: Use newline argument.
* gcc-changelog/test_email.py: New test.
* gcc-changelog/test_patches.txt: New test.
* mklog.py: Use newline argument.
-rwxr-xr-x | contrib/check_GNU_style.py | 6 | ||||
-rwxr-xr-x | contrib/check_GNU_style_lib.py | 4 | ||||
-rwxr-xr-x | contrib/gcc-changelog/git_commit.py | 11 | ||||
-rwxr-xr-x | contrib/gcc-changelog/git_email.py | 2 | ||||
-rwxr-xr-x | contrib/gcc-changelog/test_email.py | 6 | ||||
-rw-r--r-- | contrib/gcc-changelog/test_patches.txt | 26 | ||||
-rwxr-xr-x | contrib/mklog.py | 2 |
7 files changed, 44 insertions, 13 deletions
diff --git a/contrib/check_GNU_style.py b/contrib/check_GNU_style.py index 61faa29..969534a 100755 --- a/contrib/check_GNU_style.py +++ b/contrib/check_GNU_style.py @@ -35,9 +35,9 @@ def main(): format = args.format if filename == '-': - check_GNU_style_file(sys.stdin, None, format) + check_GNU_style_file(sys.stdin, format) else: - with open(filename, 'rb') as diff_file: - check_GNU_style_file(diff_file, 'utf-8', format) + with open(filename, newline='\n') as diff_file: + check_GNU_style_file(diff_file, format) main() diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py index b5ab67e..b3db4fb 100755 --- a/contrib/check_GNU_style_lib.py +++ b/contrib/check_GNU_style_lib.py @@ -262,7 +262,7 @@ class SpacesAndTabsMixedTest(unittest.TestCase): r = self.check.check('foo', 123, '\t a = 123;') self.assertIsNone(r) -def check_GNU_style_file(file, file_encoding, format): +def check_GNU_style_file(file, format): checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(), SentenceSeparatorCheck(), SentenceEndOfCommentCheck(), SentenceDotEndCheck(), FunctionParenthesisCheck(), @@ -271,7 +271,7 @@ def check_GNU_style_file(file, file_encoding, format): SpacesAndTabsMixedCheck()] errors = [] - patch = PatchSet(file, encoding=file_encoding) + patch = PatchSet(file) for pfile in patch.added_files + patch.modified_files: t = pfile.target_file.lstrip('b/') diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index aae3416..d90e6c1 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -718,11 +718,12 @@ class GitCommit: if not prs: # if all ChangeLog entries have identical PRs # then use them - prs = self.changelog_entries[0].prs - for entry in self.changelog_entries: - if entry.prs != prs: - prs = [] - break + if self.changelog_entries: + prs = self.changelog_entries[0].prs + for entry in self.changelog_entries: + if entry.prs != prs: + prs = [] + break entry = ChangeLogEntry(changelog_location, self.top_level_authors, prs) diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py index 87b419c..2566d41 100755 --- a/contrib/gcc-changelog/git_email.py +++ b/contrib/gcc-changelog/git_email.py @@ -37,7 +37,7 @@ unidiff_supports_renaming = hasattr(PatchedFile(), 'is_rename') class GitEmail(GitCommit): def __init__(self, filename): self.filename = filename - diff = PatchSet.from_filename(filename) + diff = PatchSet.from_filename(filename, newline='\n') date = None author = None subject = '' diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py index d0de88c..b9d0cb4 100755 --- a/contrib/gcc-changelog/test_email.py +++ b/contrib/gcc-changelog/test_email.py @@ -44,7 +44,7 @@ class TestGccChangelog(unittest.TestCase): filename = None patch_lines = [] - with open(os.path.join(script_path, 'test_patches.txt')) as f: + with open(os.path.join(script_path, 'test_patches.txt'), newline='\n') as f: lines = f.read() for line in lines.split('\n'): if line.startswith('==='): @@ -455,3 +455,7 @@ class TestGccChangelog(unittest.TestCase): def test_space_after_tab(self): email = self.from_patch_glob('0001-Use-Value_Range-when-applying-inferred-ranges.patch') assert (email.errors[0].message == 'extra space after tab') + + def test_CR_in_patch(self): + email = self.from_patch_glob('0001-Add-M-character.patch') + assert (email.errors[0].message == 'cannot find a ChangeLog location in message') diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt index b28de7d..c378c32 100644 --- a/contrib/gcc-changelog/test_patches.txt +++ b/contrib/gcc-changelog/test_patches.txt @@ -3610,3 +3610,29 @@ index 0b9aa3639c5..f279371948a 100644 if (r.intersect (infer.range (x))) -- 2.38.0 + +=== 0001-Add-M-character.patch ==== +From 71ab4c18f279dc0fa0172ffe8cfac5fabcde953d Mon Sep 17 00:00:00 2001 +From: Martin Liska <mliska@suse.cz> +Date: Fri, 9 Dec 2022 11:55:21 +0100 +Subject: [PATCH] Add ^M character + +--- + demo.txt | 5 +++++ + 1 file changed, 5 insertions(+) + create mode 100644 demo.txt + +diff --git a/demo.txt b/demo.txt +new file mode 100644 +index 0000000..d75da75 +--- /dev/null ++++ b/demo.txt +@@ -0,0 +1,5 @@ ++pub fn main () ++{ ++// { dg-error "Isolated CR" "" { target *-*-* } .+1 } ++ //! doc cr
comment ++} +-- +2.38.1 + diff --git a/contrib/mklog.py b/contrib/mklog.py index 91c0dcd..3a6ec68 100755 --- a/contrib/mklog.py +++ b/contrib/mklog.py @@ -361,7 +361,7 @@ if __name__ == '__main__': if args.directory: root = args.directory - data = open(args.input) if args.input else sys.stdin + data = open(args.input, newline='\n') if args.input else sys.stdin if args.update_copyright: update_copyright(data) else: |