瀏覽代碼

LibDiff: Add Diff::write_context_header

This is used to write a context patch header.
Shannon Booth 2 年之前
父節點
當前提交
44f141dd24
共有 2 個文件被更改,包括 9 次插入0 次删除
  1. 8 0
      Userland/Libraries/LibDiff/Format.cpp
  2. 1 0
      Userland/Libraries/LibDiff/Format.h

+ 8 - 0
Userland/Libraries/LibDiff/Format.cpp

@@ -210,4 +210,12 @@ ErrorOr<void> write_context(Hunk const& hunk, Stream& stream, ColorOutput color_
     return write_hunk_as_context(split_lines.old_lines, split_lines.new_lines, hunk.location, stream, color_output);
 }
 
+ErrorOr<void> write_context_header(StringView old_path, StringView new_path, Stream& stream)
+{
+    TRY(stream.write_formatted("*** {}\n", old_path));
+    TRY(stream.write_formatted("--- {}\n", new_path));
+
+    return stream.write_formatted("***************\n");
+}
+
 }

+ 1 - 0
Userland/Libraries/LibDiff/Format.h

@@ -26,4 +26,5 @@ ErrorOr<void> write_unified_header(StringView old_path, StringView new_path, Str
 ErrorOr<void> write_normal(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
 
 ErrorOr<void> write_context(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
+ErrorOr<void> write_context_header(StringView old_path, StringView new_path, Stream& stream);
 }