* [PATCH] gcc-changelog: show correct line when complaining about unclosed paren
@ 2021-06-30 15:03 David Malcolm
2021-07-16 21:58 ` PING " David Malcolm
0 siblings, 1 reply; 2+ messages in thread
From: David Malcolm @ 2021-06-30 15:03 UTC (permalink / raw)
To: gcc-patches
Successfully tested via:
pytest contrib/gcc-changelog/
contrib/ChangeLog:
* gcc-changelog/git_commit.py (ChangeLogEntry.__init__): Convert
ChangeLogEntry.opened_parentheses from an integer to a stack of
line strings.
(ChangeLogEntry.parse_changelog): Likewise.
(ChangeLogEntry.process_parentheses): Likewise.
(GitCommit.check_for_broken_parentheses): Update for above change.
Use line containing most recently opened parenthesis as line for
error.
* gcc-changelog/test_email.py
(TestGccChangelog.test_multiline_bad_parentheses): Verify that the
error uses the line containing the unclosed parenthesis, rather
than the first line.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
contrib/gcc-changelog/git_commit.py | 14 +++++++-------
contrib/gcc-changelog/test_email.py | 1 +
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index d1646bdc0cd..4aac4389a0d 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -217,7 +217,7 @@ class ChangeLogEntry:
self.lines = []
self.files = []
self.file_patterns = []
- self.opened_parentheses = 0
+ self.opened_parentheses = [] # stack of lines
def parse_file_names(self):
# Whether the content currently processed is between a star prefix the
@@ -549,7 +549,7 @@ class GitCommit:
m = star_prefix_regex.match(line)
if m:
if (len(m.group('spaces')) != 1 and
- last_entry.opened_parentheses == 0):
+ last_entry.opened_parentheses == []):
msg = 'one space should follow asterisk'
self.errors.append(Error(msg, line))
else:
@@ -574,13 +574,13 @@ class GitCommit:
def process_parentheses(self, last_entry, line):
for c in line:
if c == '(':
- last_entry.opened_parentheses += 1
+ last_entry.opened_parentheses.append(line)
elif c == ')':
- if last_entry.opened_parentheses == 0:
+ if last_entry.opened_parentheses == []:
msg = 'bad wrapping of parenthesis'
self.errors.append(Error(msg, line))
else:
- last_entry.opened_parentheses -= 1
+ last_entry.opened_parentheses.pop()
def parse_file_names(self):
for entry in self.changelog_entries:
@@ -606,9 +606,9 @@ class GitCommit:
def check_for_broken_parentheses(self):
for entry in self.changelog_entries:
- if entry.opened_parentheses != 0:
+ if entry.opened_parentheses != []:
msg = 'bad parentheses wrapping'
- self.errors.append(Error(msg, entry.lines[0]))
+ self.errors.append(Error(msg, entry.opened_parentheses[-1]))
def get_file_changelog_location(self, changelog_file):
for file in self.info.modified_files:
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index 319e065ca55..2f8e69fcdc0 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -415,6 +415,7 @@ class TestGccChangelog(unittest.TestCase):
def test_multiline_bad_parentheses(self):
email = self.from_patch_glob('0002-Wrong-macro-changelog.patch')
assert email.errors[0].message == 'bad parentheses wrapping'
+ assert email.errors[0].line == '\t* config/i386/i386.md (*fix_trunc<mode>_i387_1,'
def test_changelog_removal(self):
email = self.from_patch_glob('0001-ChangeLog-removal.patch')
--
2.26.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* PING Re: [PATCH] gcc-changelog: show correct line when complaining about unclosed paren
2021-06-30 15:03 [PATCH] gcc-changelog: show correct line when complaining about unclosed paren David Malcolm
@ 2021-07-16 21:58 ` David Malcolm
0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2021-07-16 21:58 UTC (permalink / raw)
To: gcc-patches
Ping re:
https://gcc.gnu.org/pipermail/gcc-patches/2021-June/574057.html
On Wed, 2021-06-30 at 11:03 -0400, David Malcolm wrote:
Successfully tested via:
pytest contrib/gcc-changelog/
contrib/ChangeLog:
* gcc-changelog/git_commit.py (ChangeLogEntry.__init__):
Convert
ChangeLogEntry.opened_parentheses from an integer to a stack of
line strings.
(ChangeLogEntry.parse_changelog): Likewise.
(ChangeLogEntry.process_parentheses): Likewise.
(GitCommit.check_for_broken_parentheses): Update for above
change.
Use line containing most recently opened parenthesis as line
for
error.
* gcc-changelog/test_email.py
(TestGccChangelog.test_multiline_bad_parentheses): Verify that
the
error uses the line containing the unclosed parenthesis, rather
than the first line.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
contrib/gcc-changelog/git_commit.py | 14 +++++++-------
contrib/gcc-changelog/test_email.py | 1 +
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-
changelog/git_commit.py
index d1646bdc0cd..4aac4389a0d 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -217,7 +217,7 @@ class ChangeLogEntry:
self.lines = []
self.files = []
self.file_patterns = []
- self.opened_parentheses = 0
+ self.opened_parentheses = [] # stack of lines
def parse_file_names(self):
# Whether the content currently processed is between a star
prefix the
@@ -549,7 +549,7 @@ class GitCommit:
m = star_prefix_regex.match(line)
if m:
if (len(m.group('spaces')) != 1 and
- last_entry.opened_parentheses == 0):
+ last_entry.opened_parentheses == []):
msg = 'one space should follow asterisk'
self.errors.append(Error(msg, line))
else:
@@ -574,13 +574,13 @@ class GitCommit:
def process_parentheses(self, last_entry, line):
for c in line:
if c == '(':
- last_entry.opened_parentheses += 1
+ last_entry.opened_parentheses.append(line)
elif c == ')':
- if last_entry.opened_parentheses == 0:
+ if last_entry.opened_parentheses == []:
msg = 'bad wrapping of parenthesis'
self.errors.append(Error(msg, line))
else:
- last_entry.opened_parentheses -= 1
+ last_entry.opened_parentheses.pop()
def parse_file_names(self):
for entry in self.changelog_entries:
@@ -606,9 +606,9 @@ class GitCommit:
def check_for_broken_parentheses(self):
for entry in self.changelog_entries:
- if entry.opened_parentheses != 0:
+ if entry.opened_parentheses != []:
msg = 'bad parentheses wrapping'
- self.errors.append(Error(msg, entry.lines[0]))
+ self.errors.append(Error(msg,
entry.opened_parentheses[-1]))
def get_file_changelog_location(self, changelog_file):
for file in self.info.modified_files:
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-
changelog/test_email.py
index 319e065ca55..2f8e69fcdc0 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -415,6 +415,7 @@ class TestGccChangelog(unittest.TestCase):
def test_multiline_bad_parentheses(self):
email = self.from_patch_glob('0002-Wrong-macro-
changelog.patch')
assert email.errors[0].message == 'bad parentheses wrapping'
+ assert email.errors[0].line == '\t* config/i386/i386.md
(*fix_trunc<mode>_i387_1,'
def test_changelog_removal(self):
email = self.from_patch_glob('0001-ChangeLog-removal.patch')
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-07-16 21:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-30 15:03 [PATCH] gcc-changelog: show correct line when complaining about unclosed paren David Malcolm
2021-07-16 21:58 ` PING " David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).