fix_tsv_conflict 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93f8545e521c8c3a0b91d53a8dc35eb2414d1da1a7bb8fc673e0a9697ec2d1b2
4
- data.tar.gz: e410a589bfd588143133abc59092e2ccf820f01636424f43ea168db0e02680f7
3
+ metadata.gz: 4dabd984b3240e512b940afbf709307460a67cd44eb2eebb664d6529491e30b0
4
+ data.tar.gz: 70996a3970ec15d951b7a933a54793321abbaa2aab52d3acb49c8903815cfec6
5
5
  SHA512:
6
- metadata.gz: f79e153a54393de55d5bba7f1bb985f12f7d4235081e54e588173d7b6063752ac19d49d21bc59f579e1668be005c766524087ff082657c82eaed3a7a3d424204
7
- data.tar.gz: f259d5bc68b0ca3ff4359f53082b4edd180df68c29c5319b6d9384e3264c6869aea804c22a73c56c88fad594c4fd333ab9b40c78ee29e73b556c3882dd66e84d
6
+ metadata.gz: 4d13b237f98344c21a4390ea2a4781dd681ca4a8fb125e728475214f7c72356e091e23427f1def23ea117ea46b363592c5dc05ff79eafd29f6c9426b6e24d232
7
+ data.tar.gz: f006c0262ab4f1088e2f1d66b15957a8dc8832d8440d3ed19ce5a24aea084902571fc38b1104d75b1789675f33990df880d6acef3f3854a2fd582122a956fa23
data/.travis.yml CHANGED
@@ -3,3 +3,5 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5.0
5
5
  before_install: gem install bundler -v 1.16.1
6
+ notifications:
7
+ email: false
@@ -1,5 +1,11 @@
1
+ require "fix_tsv_conflict/logging"
2
+
1
3
  module FixTSVConflict
2
4
  class DiffPrinter
5
+ include Logging
6
+
7
+ attr_reader :stderr
8
+
3
9
  def initialize(stderr: $stderr)
4
10
  @stderr = stderr
5
11
  @left, @right = {}, {}
@@ -15,7 +21,7 @@ module FixTSVConflict
15
21
  l, r = left[i], right[i]
16
22
  if l == r
17
23
  flush_conflicts if in_conflict?
18
- print_col_and_value(col, l)
24
+ dump [col, l].join(TAB)
19
25
  else
20
26
  @left[col] = l
21
27
  @right[col] = r
@@ -26,15 +32,11 @@ module FixTSVConflict
26
32
  end
27
33
 
28
34
  def flush_conflicts
29
- @stderr.puts "#{LEFT} #{@lbranch}"
30
- @left.each do |c, v|
31
- print_col_and_value(c, v)
32
- end
33
- @stderr.puts SEP
34
- @right.each do |c, v|
35
- print_col_and_value(c, v)
36
- end
37
- @stderr.puts "#{RIGHT} #{@rbranch}"
35
+ dump "#{LEFT} #{@lbranch}"
36
+ dump @left.map { |c, v| [c, v].join(TAB) }
37
+ dump SEP
38
+ dump @right.map { |c, v| [c, v].join(TAB) }
39
+ dump "#{RIGHT} #{@rbranch}"
38
40
 
39
41
  @left.clear
40
42
  @right.clear
@@ -0,0 +1,45 @@
1
+ module FixTSVConflict
2
+ module Logging
3
+ using Module.new {
4
+ refine String do
5
+ def red; "\e[31m#{self}\e[0m"; end
6
+ def green; "\e[32m#{self}\e[0m"; end
7
+ def yellow; "\e[33m#{self}\e[0m"; end
8
+ end
9
+ }
10
+
11
+ def log(message, **options)
12
+ if options[:no_newline]
13
+ stderr.print message.chomp
14
+ else
15
+ stderr.puts message
16
+ end
17
+ end
18
+
19
+ def info(message, **options)
20
+ log message, options
21
+ end
22
+
23
+ def error(message, **options)
24
+ log message.to_s.red
25
+ end
26
+
27
+ def warn(message, **options)
28
+ log message.to_s.yellow
29
+ end
30
+
31
+ def notice(message, **options)
32
+ log message.to_s.green
33
+ end
34
+
35
+ def dump(lines, **options)
36
+ Array(lines).each do |line|
37
+ log line.gsub(/^/, " "), options
38
+ end
39
+ end
40
+
41
+ def blank
42
+ stderr.puts
43
+ end
44
+ end
45
+ end
@@ -1,4 +1,5 @@
1
1
  require "fix_tsv_conflict/diff_printer"
2
+ require "fix_tsv_conflict/logging"
2
3
 
3
4
  module StringExt
4
5
  BLANK_RE = /\A[[:space:]]*\z/
@@ -11,8 +12,12 @@ end
11
12
 
12
13
  module FixTSVConflict
13
14
  class Repairman
15
+ include Logging
14
16
  using StringExt
15
17
 
18
+
19
+ attr_reader :stderr
20
+
16
21
  def initialize(stdin: $stdin, stderr: $stderr)
17
22
  @stdin = stdin
18
23
  @stderr = stderr
@@ -29,6 +34,8 @@ module FixTSVConflict
29
34
  @rbranch = line.chomp.split(" ").last
30
35
  result += resolve(left, right)
31
36
  branch = nil
37
+ left.clear
38
+ right.clear
32
39
  elsif line.start_with?(SEP)
33
40
  branch = right
34
41
  else
@@ -47,6 +54,32 @@ module FixTSVConflict
47
54
  end
48
55
 
49
56
  def resolve(left, right)
57
+ print_conflicts(left, right)
58
+ result = resolve_conflicts(left, right)
59
+ print_result(result)
60
+ result
61
+ end
62
+
63
+ def print_conflicts(left, right)
64
+ warn "A conflict found:"
65
+ blank
66
+ dump "#{LEFT} #{@lbranch}"
67
+ dump left
68
+ dump SEP
69
+ dump right
70
+ dump "#{RIGHT} #{@rbranch}"
71
+ blank
72
+ end
73
+
74
+ def print_result(result)
75
+ notice "The conflict was fixed to:"
76
+ blank
77
+ dump result
78
+ blank
79
+ blank
80
+ end
81
+
82
+ def resolve_conflicts(left, right)
50
83
  left = index_by_id(left.reject(&:blank?))
51
84
  right = index_by_id(right.reject(&:blank?))
52
85
  (left.keys + right.keys).uniq.sort.map do |id|
@@ -74,22 +107,25 @@ module FixTSVConflict
74
107
  end
75
108
 
76
109
  def print_diff(l, r)
110
+ log "Diff by columns:"
111
+ blank
77
112
  printer = DiffPrinter.new(stderr: @stderr)
78
113
  printer.print(@cols, l, @lbranch, r, @rbranch)
79
114
  end
80
115
 
81
116
  def prompt_select(l, r)
82
117
  text = <<-TEXT
118
+
83
119
  Which do you want keep?
84
120
 
85
- 1) #{@lbranch}
86
- 2) #{@rbranch}
87
- 3) both of them
121
+ 1) #{@lbranch}
122
+ 2) #{@rbranch}
123
+ k) keep as is
88
124
 
89
- Please enter 1, 2, or 3:
125
+ Please enter 1, 2, or k:
90
126
  TEXT
91
127
 
92
- @stderr.print text.chomp
128
+ info text.chomp, no_newline: true
93
129
 
94
130
  loop do
95
131
  case selected = @stdin.gets.strip
@@ -97,12 +133,12 @@ Please enter 1, 2, or 3:
97
133
  break l
98
134
  when "2"
99
135
  break r
100
- when "3"
136
+ when "k"
101
137
  break "#{LEFT} #{@lbranch}\n#{l}#{SEP}\n#{r}#{RIGHT} #{@rbranch}\n"
102
138
  else
103
139
  text = <<-TEXT
104
140
  Invalid input: #{selected}
105
- Please enter 1, 2, or 3:
141
+ Please enter 1, 2, or k:
106
142
  TEXT
107
143
  @stderr.print text.chomp
108
144
  end
@@ -127,6 +163,8 @@ Please enter 1, 2, or 3:
127
163
  end
128
164
 
129
165
  def pick_by_trailing_tabs(l, r)
166
+ info "Trailing tab conflicts were fixed automatically."
167
+
130
168
  ltabs = l.count(TAB)
131
169
  rtabs = r.count(TAB)
132
170
 
@@ -1,3 +1,3 @@
1
1
  module FixTSVConflict
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fix_tsv_conflict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato Ikeda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-18 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - lib/fix_tsv_conflict.rb
101
101
  - lib/fix_tsv_conflict/cli.rb
102
102
  - lib/fix_tsv_conflict/diff_printer.rb
103
+ - lib/fix_tsv_conflict/logging.rb
103
104
  - lib/fix_tsv_conflict/repairman.rb
104
105
  - lib/fix_tsv_conflict/version.rb
105
106
  homepage: https://github.com/a2ikm/fix_tsv_conflict