vcs2json 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/exceptions/encoding_error.rb +2 -0
- data/lib/vcs2json/git.rb +34 -13
- data/lib/vcs2json/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13238e079776d7f77e6f301c9778f1cd93383e7c
|
4
|
+
data.tar.gz: ad0e55fbe2d9b7bba56d343fb51c8e2a4d08ed6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77ad00f756a282c3b97fd471f1628bf78048f9fa2416ac0ae5b09e8ea430706d1edd67a97f2e19c7d6a88152446b5acde560135076d8c399b4d62386be083c95
|
7
|
+
data.tar.gz: 0ecea201b2eecbeae823c4a3fb3d31e37de37a07cd5b4d602efc7bd631f33c8bccf58e18e303e372a64641c28088e57d03bac1f3fcb8f3aeaa53c50ea926564b
|
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
|
-
|
24
|
-
|
23
|
+
begin
|
24
|
+
add_commits(@opts)
|
25
|
+
add_integer_mapping
|
25
26
|
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
30
|
+
# print commits to stdout as json
|
31
|
+
$stdout.puts JSON.pretty_generate(sorted_and_pruned)
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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)
|
data/lib/vcs2json/version.rb
CHANGED
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.
|
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-
|
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
|