# HG changeset patch
# User Felipe Contreras <felipe.contreras@gmail.com>
# Date 2023-03-09 19:02:13
# Node ID dd42156b6441f6b8356100b4228fa16fbf95f669
# Parent  95acba2c29f6e90a7c19da0585a7b52efb416082

fastexport: rework newline logic

Newlines should only be added when otherwise the stream would look weird
without them (on blobs), therefore they are the exception.

Flip the logic so they are added, not skipped.

diff --git a/hgext/fastexport.py b/hgext/fastexport.py
--- a/hgext/fastexport.py
+++ b/hgext/fastexport.py
@@ -69,10 +69,10 @@ def convert_to_git_ref(branch):
     return b"refs/heads/" + branch
 
 
-def write_data(buf, data, skip_newline):
+def write_data(buf, data, add_newline=False):
     buf.append(b"data %d\n" % len(data))
     buf.append(data)
-    if not skip_newline or data[-1:] != b"\n":
+    if add_newline or data[-1:] != b"\n":
         buf.append(b"\n")
 
 
@@ -103,7 +103,7 @@ def export_commit(ui, repo, rev, marks, 
             marks[filerev] = mark
             data = filectx.data()
             buf = [b"blob\n", b"mark :%d\n" % mark]
-            write_data(buf, data, False)
+            write_data(buf, data, True)
             ui.write(*buf, keepprogressbar=True)
             del buf
 
@@ -122,7 +122,7 @@ def export_commit(ui, repo, rev, marks, 
             convert_to_git_date(ctx.date()),
         ),
     ]
-    write_data(buf, ctx.description(), True)
+    write_data(buf, ctx.description())
     if parents:
         buf.append(b"from :%d\n" % marks[parents[0].hex()])
     if len(parents) == 2: