[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] add_c_file: handle adding to the end of a list correctly.
commit ef1744e2c938517220e8f27370c134efb78cdd0c
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Jan 15 12:54:47 2020 -0500
add_c_file: handle adding to the end of a list correctly.
Fixes bug 32962.
---
scripts/maint/add_c_file.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/scripts/maint/add_c_file.py b/scripts/maint/add_c_file.py
index 9ec182efc..6656d0d42 100755
--- a/scripts/maint/add_c_file.py
+++ b/scripts/maint/add_c_file.py
@@ -99,10 +99,14 @@ class AutomakeChunk:
def __init__(self):
self.lines = []
self.kind = ""
+ self.hasBlank = False # true if we end with a blank line.
def addLine(self, line):
"""
Insert a line into this chunk while parsing the automake file.
+
+ Return True if we have just read the last line in the chunk, and
+ False otherwise.
"""
m = self.pat.match(line)
if m:
@@ -110,10 +114,12 @@ class AutomakeChunk:
raise ValueError("control line not preceded by a blank line")
self.kind = m.group(1)
- self.lines.append(line)
if line.strip() == "":
+ self.hasBlank = True
return True
+ self.lines.append(line)
+
return False
def insertMember(self, member):
@@ -145,8 +151,8 @@ class AutomakeChunk:
"{}{}{}\\\n".format(prespace, member, postspace))
def insert_at_end(self, member, prespace, postspace):
- lastline = self.lines[-1]
- self.lines[-1] += '{}\\\n'.format(postspace)
+ lastline = self.lines[-1].strip()
+ self.lines[-1] = '{}{}{}\\\n'.format(prespace, lastline, postspace)
self.lines.append("{}{}\n".format(prespace, member))
def dump(self, f):
@@ -156,6 +162,9 @@ class AutomakeChunk:
if not line.endswith("\n"):
f.write("\n")
+ if self.hasBlank:
+ f.write("\n")
+
class ParsedAutomake:
"""A sort-of-parsed automake file, with identified chunks into which
headers and c files can be inserted.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits