Class MergeBlocks

java.lang.Object
fr.paris.lutece.plugins.wiki.service.merge.MergeBlocks

public final class MergeBlocks extends Object
Runs a JGit line-based three-way merge between a base, an "ours" and a "theirs" content and reshapes the resulting chunks into a flat list of MergeBlock objects suitable for UI rendering. The intent is to keep the JGit dependency local to this class.
  • Method Details

    • stats

      public static int[] stats(String base, String head)
      Computes line-level additions and deletions between two contents, mirroring the way a git diff would count + and - lines.
      Parameters:
      base - the content before the change (may be null)
      head - the content after the change (may be null)
      Returns:
      a two-element array: [additions, deletions]
    • containsConflictMarker

      public static boolean containsConflictMarker(String content)
      Detects whether a content string still carries a leftover conflict marker (i.e. the "<<<<<<<" opening line emitted by the underlying three-way merge). Used to refuse a reviewer's resolution that wasn't fully cleaned up.
      Parameters:
      content - the content to inspect (may be null)
      Returns:
      true when at least one conflict marker is still present
    • compute

      public static List<MergeBlock> compute(String base, String ours, String theirs)
      Computes the merge blocks for a three-way merge.
      Parameters:
      base - the common ancestor content
      ours - the current revision content
      theirs - the proposed content
      Returns:
      the ordered list of CONTEXT and CONFLICT blocks
    • hasConflict

      public static boolean hasConflict(List<MergeBlock> blocks)
      Checks whether the computed merge contains at least one CONFLICT block.
      Parameters:
      blocks - the parsed merge blocks
      Returns:
      true when a conflict was detected
    • flatten

      public static String flatten(List<MergeBlock> blocks)
      Flattens a list of merge blocks into the merged content, joining CONTEXT lines and keeping only the "ours" side of CONFLICT blocks. Used when no conflict is present to produce the auto-merged content.
      Parameters:
      blocks - the parsed merge blocks
      Returns:
      the flattened content