vcs2json 1.0.0 → 1.0.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
  SHA1:
3
- metadata.gz: 2800a945a5ca9ced91f1dc9b6e7dfeea9dd035d2
4
- data.tar.gz: dec9e8a47a8a76d552d13a7946afc8050a863249
3
+ metadata.gz: 13238e079776d7f77e6f301c9778f1cd93383e7c
4
+ data.tar.gz: ad0e55fbe2d9b7bba56d343fb51c8e2a4d08ed6c
5
5
  SHA512:
6
- metadata.gz: 1491d0a803e27febfe7e2cc04e569e5ebc02af45b104be8812ae6bc4d44ced3008ab3944b27557c78ff22d4e54b212c8ffb36276b57eb113aec0291fd0d36b93
7
- data.tar.gz: 30df5f5ffc7f6973a03d0be6ca7bcf7f9f9b48a9bb3c2b666b2c0ac2f63bd96e8e27dc19e33e52534194b8159d4ba4aa7b345ee24bf6a912022284a94933911c
6
+ metadata.gz: 77ad00f756a282c3b97fd471f1628bf78048f9fa2416ac0ae5b09e8ea430706d1edd67a97f2e19c7d6a88152446b5acde560135076d8c399b4d62386be083c95
7
+ data.tar.gz: 0ecea201b2eecbeae823c4a3fb3d31e37de37a07cd5b4d602efc7bd631f33c8bccf58e18e303e372a64641c28088e57d03bac1f3fcb8f3aeaa53c50ea926564b
@@ -0,0 +1,2 @@
1
+ class EncodingError < StandardError
2
+ end
data/lib/vcs2json/git.rb CHANGED
@@ -20,22 +20,26 @@ module Vcs2Json
20
20
 
21
21
  def execute
22
22
  # recursively add commits as long as we have less than :number and there are still more commits to search
23
- add_commits(@opts)
24
- add_integer_mapping
23
+ begin
24
+ add_commits(@opts)
25
+ add_integer_mapping
25
26
 
26
- # sort on date and prune excessive commits
27
- sorted_and_pruned = @commits.sort_by {|id,commit| commit[:date]}.reverse.map {|(_,commit)| commit}.first(@opts[:number])
27
+ # sort on date and prune excessive commits
28
+ sorted_and_pruned = @commits.sort_by {|id,commit| commit[:date]}.reverse.map {|(_,commit)| commit}.first(@opts[:number])
28
29
 
29
- # print commits to stdout as json
30
- $stdout.puts JSON.pretty_generate(sorted_and_pruned)
30
+ # print commits to stdout as json
31
+ $stdout.puts JSON.pretty_generate(sorted_and_pruned)
31
32
 
32
- # print ids of empty commits to stderr
33
- if !@empty_commits.empty?
34
- STDERR.puts "EMPTY COMMITS"
35
- STDERR.puts @empty_commits
33
+ # print ids of empty commits to stderr
34
+ if !@empty_commits.empty?
35
+ STDERR.puts "EMPTY COMMITS"
36
+ STDERR.puts @empty_commits
37
+ end
38
+ # print additional info to stderr
39
+ STDERR.puts "\n\nExtracted #{sorted_and_pruned.size} commits."
40
+ rescue EncodingError => e
41
+ puts e
36
42
  end
37
- # print additional info to stderr
38
- STDERR.puts "\n\nExtracted #{sorted_and_pruned.size} commits."
39
43
  end
40
44
 
41
45
  def ignore
@@ -115,7 +119,24 @@ module Vcs2Json
115
119
 
116
120
  def add_meta_information(opts)
117
121
  raw_commits = `git log #{hash_2_gitoptions(opts)} --pretty=format:'%H#{FIELD_SEP}%cn#{FIELD_SEP}%ce#{FIELD_SEP}%cd#{FIELD_SEP}%ad#{FIELD_SEP}%B#{COMMIT_SEP}'`
118
- commits_info = raw_commits.encode('UTF-8', :invalid => :replace).split(COMMIT_SEP)
122
+
123
+ begin
124
+ encoded = ''
125
+ # try encoding to utf8
126
+ encoded = raw_commits.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
127
+ # need to expliceitely check if the encoding is valid for ruby <= 2.0
128
+ # utf8 -> utf8 will not do anything even with invalid bytes
129
+ # http://stackoverflow.com/questions/24036821/ruby-2-0-0-stringmatch-argumenterror-invalid-byte-sequence-in-utf-8
130
+ if !encoded.valid_encoding?
131
+ # encode to utf16 first and then back to utf8
132
+ encoded.encode!("UTF-16be", invalid: :replace, undef: :replace, :replace=>'')
133
+ encoded.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
134
+ end
135
+ # split into individual commits
136
+ commits_info = encoded.split(COMMIT_SEP)
137
+ rescue ArgumentError
138
+ raise EncodingError.new, "Unable to encode input as UTF-8"
139
+ end
119
140
 
120
141
  commits_info.each do |commit|
121
142
  fields = commit.split(FIELD_SEP)
@@ -1,3 +1,3 @@
1
1
  module Vcs2Json
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcs2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Rolfsnes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-08 00:00:00.000000000 Z
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/exceptions/ambigious_date.rb
132
132
  - lib/exceptions/could_not_find_format_of_date.rb
133
133
  - lib/exceptions/could_not_parse_date.rb
134
+ - lib/exceptions/encoding_error.rb
134
135
  - lib/exceptions/no_base_path.rb
135
136
  - lib/exceptions/no_date_field.rb
136
137
  - lib/exceptions/no_file_section.rb