File: merge.rb

package info (click to toggle)
ruby-grit 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 336 kB
  • sloc: ruby: 3,643; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 920 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Grit

  class Merge

    STATUS_BOTH = 'both'
    STATUS_OURS = 'ours'
    STATUS_THEIRS = 'theirs'

    attr_reader :conflicts, :text, :sections

    def initialize(str)
      status = STATUS_BOTH

      section = 1
      @conflicts = 0
      @text = {}

      lines = str.split("\n")
      lines.each do |line|
        if /^<<<<<<< (.*?)/.match(line)
          status = STATUS_OURS
          @conflicts += 1
          section += 1
        elsif line == '======='
          status = STATUS_THEIRS
        elsif /^>>>>>>> (.*?)/.match(line)
          status = STATUS_BOTH
          section += 1
        else
          @text[section] ||= {}
          @text[section][status] ||= []
          @text[section][status] << line
        end
      end
      @text = @text.values
      @sections = @text.size
    end

    # Pretty object inspection
    def inspect
      %Q{#<Grit::Merge}
    end
  end # Merge

end # Grit