فهرست منبع

LibDiff: Add Diff::write_unified_header

This is used to write a unified patch header.
Shannon Booth 2 سال پیش
والد
کامیت
f528aedc85
2فایلهای تغییر یافته به همراه10 افزوده شده و 0 حذف شده
  1. 8 0
      Userland/Libraries/LibDiff/Format.cpp
  2. 2 0
      Userland/Libraries/LibDiff/Format.h

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

@@ -24,6 +24,14 @@ DeprecatedString generate_only_additions(StringView text)
     return builder.to_deprecated_string();
     return builder.to_deprecated_string();
 }
 }
 
 
+ErrorOr<void> write_unified_header(StringView old_path, StringView new_path, Stream& stream)
+{
+    TRY(stream.write_formatted("--- {}\n", old_path));
+    TRY(stream.write_formatted("+++ {}\n", new_path));
+
+    return {};
+}
+
 ErrorOr<void> write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output)
 ErrorOr<void> write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output)
 {
 {
     TRY(stream.write_formatted("{}\n", hunk.location));
     TRY(stream.write_formatted("{}\n", hunk.location));

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

@@ -21,6 +21,8 @@ enum class ColorOutput {
 };
 };
 
 
 ErrorOr<void> write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
 ErrorOr<void> write_unified(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
+ErrorOr<void> write_unified_header(StringView old_path, StringView new_path, Stream& stream);
+
 ErrorOr<void> write_normal(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
 ErrorOr<void> write_normal(Hunk const& hunk, Stream& stream, ColorOutput color_output = ColorOutput::No);
 
 
 }
 }