Class: Bash::Merge::ConflictResolver

Inherits:
Ast::Merge::ConflictResolverBase
  • Object
show all
Defined in:
lib/bash/merge/conflict_resolver.rb

Overview

Resolves conflicts between template and destination Bash content using structural signatures and configurable preferences.

Examples:

Basic usage

resolver = ConflictResolver.new(template_analysis, dest_analysis)
resolver.resolve(result)

Instance Method Summary collapse

Constructor Details

#initialize(template_analysis, dest_analysis, preference: :destination, add_template_only_nodes: false, match_refiner: nil, **options) ⇒ ConflictResolver

Creates a new ConflictResolver



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bash/merge/conflict_resolver.rb', line 23

def initialize(template_analysis, dest_analysis, preference: :destination, add_template_only_nodes: false, match_refiner: nil, **options)
  super(
    strategy: :batch,
    preference: preference,
    template_analysis: template_analysis,
    dest_analysis: dest_analysis,
    add_template_only_nodes: add_template_only_nodes,
    match_refiner: match_refiner,
    **options
  )
  @emitter = Emitter.new
end

Instance Method Details

#resolve(result) ⇒ Object

Resolve conflicts and populate the result



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/bash/merge/conflict_resolver.rb', line 39

def resolve(result)
  DebugLogger.time("ConflictResolver#resolve") do
    template_nodes = @template_analysis.nodes
    dest_nodes = @dest_analysis.nodes

    # Clear emitter for fresh merge
    @emitter.clear

    # Build signature maps
    template_by_sig = build_signature_map(template_nodes, @template_analysis)
    dest_by_sig = build_signature_map(dest_nodes, @dest_analysis)

    # Track which nodes have been processed
    processed_template_sigs = ::Set.new
    processed_dest_sigs = ::Set.new

    # Process nodes via emitter
    merge_nodes_to_emitter(
      template_nodes,
      dest_nodes,
      template_by_sig,
      dest_by_sig,
      processed_template_sigs,
      processed_dest_sigs,
    )

    # Transfer emitter output to result
    emitted_content = @emitter.to_s
    unless emitted_content.empty?
      emitted_content.lines.each do |line|
        result.add_line(line.chomp, decision: MergeResult::DECISION_MERGED, source: :merged)
      end
    end

    DebugLogger.debug("Conflict resolution complete", {
      template_nodes: template_nodes.size,
      dest_nodes: dest_nodes.size,
      result_lines: result.line_count,
    })
  end
end