git-age 0.1.6 → 0.1.8

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: 0af8c2ed2b23e1c87fb85a906b68e032870c1b8a196185ac599ac34e97491828
4
- data.tar.gz: 412ecb46c57e359a4f13800f37df589c6e3e38cf078ed2ec8fe17930e4005b14
3
+ metadata.gz: 51555542566fad38ca8c70e69bf5a3d0757a42258f5f6603495c1a143d2889ad
4
+ data.tar.gz: 8dba7887aad69063dc21457988f134ec961ff7e3013b9ec16ebf2a6e39b6d63d
5
5
  SHA512:
6
- metadata.gz: 3642b48474489273d6199776a1a60a4c228d50ddd713f048ee2611c658d7eded9a3a46aa8d331ccbbd874aa1f646f697a310d5f7763ca8b5fddd1661f9febe55
7
- data.tar.gz: dcda04fa314058efb654e2e62e8cb6d8de298418a07d3bb43003d9e4fbe96a99835f5960f97ed26b02747ac050975a63c32b2869ef57684323ce949c46a92e32
6
+ metadata.gz: 51a5902b883b763678e02ed52d0df361a1f79552acb467f40cdf8ce5ef21e553a2214a46b68ed9008fda43b0aff7039b8c1ce49d0ccade784d5eab2bbc4aae0c
7
+ data.tar.gz: f4484ef6332d6ccea5dc6b94dcf2ad296cb5ee30f7b81b7c738b6775af384769be8f70e38d242bff35565f5a5caf45ad860cdf8cb4bc265a34694831b161acca
checksums.yaml.gz.sig CHANGED
Binary file
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git-age (0.1.6)
4
+ git-age (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -32,6 +32,7 @@ Usage: git-age [options]
32
32
  -c, --code=PATTERN Code dir pattern
33
33
  -e, --test=PATTERN Test dir pattern
34
34
  -p, --type=TYPE Graph type, default to bar
35
+ -a, --authors [FILE] Create statistics by author
35
36
  -v, --version Show version
36
37
  ```
37
38
 
data/bin/git-age CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require_relative "../lib/git/age/version.rb"
3
4
  require_relative "../lib/git/age"
4
5
  require 'optparse'
5
6
 
@@ -68,6 +69,11 @@ opts.on('-v', '--version', 'Show version') do
68
69
  return
69
70
  end
70
71
 
72
+ opts.on('-a', '--authors [FILE]', 'Create authors file') do |file|
73
+ STDOUT.puts "Creating authors file"
74
+ options.authors = file.to_s.strip.size > 0 ? file : "git-age-authors.csv"
75
+ end
76
+
71
77
  opts.parse!
72
78
 
73
79
  Git::Age::Main.new.run
data/lib/git/age/main.rb CHANGED
@@ -8,12 +8,15 @@ module Git
8
8
 
9
9
  def initialize
10
10
  STDOUT.puts "Waiting, analysing your repository ..."
11
+ options = Git::Age::Options.instance
11
12
 
12
13
  @dates = Hash.new { |hash, key| hash[key] = { code: 0, test: 0 } }
13
14
  @files = fill_files
14
15
  @winsize = IO.console.winsize
15
- @test = Git::Age::Options.instance.test
16
- @code = Git::Age::Options.instance.code
16
+ @test = options.test
17
+ @code = options.code
18
+ @mapfile = options.map ? File.open("/tmp/git-age.map", 'w') : nil
19
+ @authors = options.authors ? Hash.new(0) : nil
17
20
 
18
21
  @test_regexp = @test ? %r{^#{@test}} : nil
19
22
  @code_regexp = @code ? %r{^#{@code}} : nil
@@ -37,13 +40,12 @@ module Git
37
40
 
38
41
  return :c unless @code_regexp
39
42
 
40
- @code_regexp && file.match(@code_regexp) ? :c : :u
43
+ @code_regexp && file.match(@code_regexp) ? :c : :u
41
44
  end
42
45
 
43
46
  def read_files
44
47
  cnt = 0
45
48
  total = @files.size
46
- mapfile = Git::Age::Options.instance.map ? File.open("/tmp/git-age.map", 'w') : nil
47
49
 
48
50
  @files.each do |file|
49
51
  cnt += 1
@@ -52,28 +54,46 @@ module Git
52
54
  print "Checking [#{cnt}/#{total}] #{file} ...".ljust(@winsize[1]) + "\r"
53
55
 
54
56
  begin
55
- IO.popen("git blame #{file} | iconv -t utf8") do |io|
57
+ IO.popen("git blame #{file} | iconv -t utf8 | cut -c1-150") do |io|
56
58
  io.read.split("\n")
57
59
  end.each do |line|
58
- matches = line.match(/[\w^]+\s\([\w\s]+(?<date>\d{4}-\d{2})-\d{2}/)
60
+ matches = line.match(/[\w^]+\s\((?<author>[\w\s]+)(?<date>\d{4}-\d{2})-\d{2}/)
59
61
  next unless matches
60
62
 
63
+ tokens = line.strip.split(')')
64
+ contents = tokens[1..-1].join.strip.chomp
65
+ next if contents.size == 0
66
+
61
67
  type = file_type(file)
62
- mapfile << "#{file}[#{type}]: #{line}\n" if mapfile
68
+ @mapfile << "#{file}[#{type}]: #{line}\n" if @mapfile
63
69
 
64
70
  @dates[matches[:date]][:test] += 1 if type == :t
65
71
  @dates[matches[:date]][:code] += 1 if type == :c
72
+
73
+ @authors[matches[:author].strip.chomp] += 1 if @authors
66
74
  end
67
75
  rescue => exc
68
76
  print "Error on file: #{file}: #{exc}\r"
69
77
  end
70
78
  end
71
79
 
72
- mapfile.close if mapfile
80
+ @mapfile.close if @mapfile
81
+ write_authors if @authors
73
82
  rescue => e
74
83
  STDERR.puts "Error reading files: #{e}"
75
84
  end
76
85
 
86
+ def write_authors
87
+ path = Git::Age::Options.instance.authors
88
+ STDOUT.puts "\nWriting authors file #{path} ..."
89
+
90
+ File.open(path, 'w') do |file|
91
+ @authors.each do |author, lines|
92
+ file << "#{author}: #{lines}\n"
93
+ end
94
+ end
95
+ end
96
+
77
97
  def sort_dates
78
98
  @dates = @dates.sort_by { |k, v| k }
79
99
  end
@@ -128,9 +148,13 @@ module Git
128
148
  end
129
149
 
130
150
  def text?(file)
131
- IO.popen("file -i -b #{file}") do |io|
151
+ return false unless File.exist?(file)
152
+
153
+ IO.popen("file -i -b \"#{file}\" 2> /dev/null") do |io|
132
154
  io.read
133
155
  end.match?(/\Atext/)
156
+ rescue
157
+ false
134
158
  end
135
159
 
136
160
  def show_stats
@@ -4,7 +4,8 @@ module Git
4
4
  module Age
5
5
  class Options
6
6
  include Singleton
7
- attr_accessor :branch, :output, :title, :processor, :image, :xtitle, :ytitle, :map, :test, :code, :type
7
+ attr_accessor :branch, :output, :title, :processor, :image, :xtitle,
8
+ :ytitle, :map, :test, :code, :type, :authors
8
9
 
9
10
  def initialize
10
11
  @branch = 'master'
@@ -18,6 +19,7 @@ module Git
18
19
  @code = nil
19
20
  @type = 'bar'
20
21
  @map = false
22
+ @authors = nil
21
23
  end
22
24
  end
23
25
  end
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Age
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eustaquio Rangel
@@ -36,7 +36,7 @@ cert_chain:
36
36
  7NRJmY9c84Zb3sCf0DV6UH+d2id9Dndp9ewchgDOSwGznt+oJmjDFZ9gYd8IP2Ol
37
37
  1eLrW8x4LHV+EVEIaiVTvmKt
38
38
  -----END CERTIFICATE-----
39
- date: 2022-12-22 00:00:00.000000000 Z
39
+ date: 2023-01-12 00:00:00.000000000 Z
40
40
  dependencies: []
41
41
  description: Check all the repository files lines dates and group it by year and month,
42
42
  allowing check how old code is still in use
metadata.gz.sig CHANGED
Binary file