avm-tools 0.10.0 → 0.11.0

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: 9b9966433679b8b863a82239dad178559c9868141db3d4f1ca2f6669d5131824
4
- data.tar.gz: 78ac90fef0632e9e465ed85cbf07d05da8ec42ac2bb67e44d4ca38bbcabac6de
3
+ metadata.gz: 44a28c913e5e4937ae791ffa209f3bbff9313d20672cb75dc73463def7800544
4
+ data.tar.gz: bc91631f9845c1b9e04279b05143447d7f387a257c492c4d7a234445254ffc3c
5
5
  SHA512:
6
- metadata.gz: 1fca490fd5d4a8b3035b047bf0fcff7a7218e51c311c5cbb1fd7d1f2c7bdf4bbe89b9f81687181c47574b08d8b11d68205e31a84fee93271ba47a1e44dec0d2f
7
- data.tar.gz: e77ce5f6750d8163224233afce0f78080e461955642a1f31c782c99c853cf27fcfb87cb35689ae8e1fddc3aa23271bf3bc8cb7a69b319f2645401e1dc492c764
6
+ metadata.gz: 45051d0661ae702fdd778a07902fae0830b4b24bfebbf5b73a7634f0b05885908505777e3e8fabdcb1599ff3a8550ef78a6f64440ef7cc374cde456cd32ae3ab
7
+ data.tar.gz: 6bb53ccac22daee1b2640ffc1c7a5e1cebe93c9313db59002668ca85902d5654b6ca4526ff8dedbf08b7a2467fbad07f0cb1519b1711b8c1cd2e6f3b2fd26c84
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/simple_cache'
4
+ require 'eac_ruby_utils/require_sub'
5
+ ::EacRubyUtils.require_sub(__FILE__)
6
+
7
+ module Avm
8
+ module Git
9
+ class Commit
10
+ include ::EacRubyUtils::SimpleCache
11
+
12
+ FIELDS = {
13
+ author_name: '%an', author_email: '%ae', author_date: '%ai',
14
+ subject: '%s',
15
+ author_all: '%an <%ae>, %ai',
16
+ commiter_name: '%cn', commiter_email: '%ce', commiter_date: '%ci',
17
+ commiter_all: '%cn <%ce>, %ci'
18
+ }.freeze
19
+
20
+ attr_reader :git, :sha1
21
+
22
+ def initialize(git, sha1)
23
+ @git = git
24
+ @sha1 = sha1
25
+ end
26
+
27
+ def format(format)
28
+ git.execute!('--no-pager', 'log', '-1', "--pretty=format:#{format}", sha1).strip
29
+ end
30
+
31
+ FIELDS.each do |field, format|
32
+ define_method field do
33
+ format(format)
34
+ end
35
+ end
36
+
37
+ def files_uncached
38
+ diff_tree_execute.each_line.map { |line| ::Avm::Git::Commit::File.new(git, line) }
39
+ end
40
+
41
+ def files_size_uncached
42
+ files.inject(0) { |a, e| a + e.dst_size }
43
+ end
44
+
45
+ def root_child?
46
+ format('%P').blank?
47
+ end
48
+
49
+ private
50
+
51
+ def diff_tree_execute
52
+ args = []
53
+ args << '--root' if root_child?
54
+ args << sha1
55
+ git.execute!(*::Avm::Git::Commit::DiffTreeLine::GIT_COMMAND_ARGS, *args)
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Avm
4
+ module Git
5
+ class Commit
6
+ class DiffTreeLine
7
+ DIFF_TREE_PATTERN = /\A:(\d{6}) (\d{6}) (\S+) (\S+) (\S+)\t(\S.*)\z/.freeze
8
+ FIELDS = %w[src_mode dst_mode src_sha1 dst_sha1 status path].freeze
9
+ GIT_COMMAND_ARGS = %w[diff-tree --no-commit-id -r --full-index].freeze
10
+
11
+ attr_reader(*FIELDS)
12
+
13
+ # line: a line of command "git [GIT_COMMAND_ARGS]"'s output.
14
+ # Reference: https://git-scm.com/docs/git-diff-tree
15
+ def initialize(line)
16
+ m = DIFF_TREE_PATTERN.match(line.strip)
17
+ raise "\"#{line}\" did not match pattern" unless m
18
+
19
+ FIELDS.count.times { |i| send("#{FIELDS[i]}=", m[i + 1]) }
20
+ end
21
+
22
+ def fields
23
+ FIELDS.map { |field| [field, send(field)] }.to_h
24
+ end
25
+
26
+ private
27
+
28
+ attr_writer(*FIELDS)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/module/delegation'
4
+ require 'eac_ruby_utils/simple_cache'
5
+ require 'avm/git/commit/diff_tree_line'
6
+
7
+ module Avm
8
+ module Git
9
+ class Commit
10
+ class File
11
+ include ::EacRubyUtils::SimpleCache
12
+
13
+ attr_reader :git, :diff_tree
14
+
15
+ # git: [EacLauncher::Git::Base]
16
+ # diff_tree_tree: a line of command "git diff-tree --no-commit-id -r --full-index"'s output
17
+ def initialize(git, diff_tree_line)
18
+ @git = git
19
+ @diff_tree = ::Avm::Git::Commit::DiffTreeLine.new(diff_tree_line)
20
+ end
21
+
22
+ delegate(*::Avm::Git::Commit::DiffTreeLine::FIELDS, to: :diff_tree)
23
+
24
+ def to_s
25
+ "#{path}|#{status}"
26
+ end
27
+
28
+ def src_size_uncached
29
+ size(src_sha1)
30
+ end
31
+
32
+ def dst_size_uncached
33
+ size(dst_sha1)
34
+ end
35
+
36
+ private
37
+
38
+ def size(sha1)
39
+ return 0 if /\A0+\z/.match(sha1)
40
+
41
+ git.execute!('cat-file', '-s', sha1).strip.to_i
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/console/docopt_runner'
4
+ require 'eac_ruby_utils/console/speaker'
5
+ require 'eac_ruby_utils/simple_cache'
6
+ require 'eac_launcher/git/base'
7
+ require 'filesize'
8
+ require 'avm/git/commit'
9
+
10
+ module Avm
11
+ module Tools
12
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
13
+ class Git < ::EacRubyUtils::Console::DocoptRunner
14
+ class Commit < ::EacRubyUtils::Console::DocoptRunner
15
+ include ::EacRubyUtils::SimpleCache
16
+ include ::EacRubyUtils::Console::Speaker
17
+
18
+ DOC = <<~DOCOPT
19
+ Mostra informações de um commit.
20
+
21
+ Usage:
22
+ __PROGRAM__ [options] <ref>
23
+ __PROGRAM__ -h | --help
24
+
25
+ Options:
26
+ -h --help Mostra esta ajuda.
27
+ -C <git-local> Caminho do repositório local [default: .].
28
+ -f --files Mostra os arquivos.
29
+ -s --size Mostra o tamanho de arquivos.
30
+ DOCOPT
31
+
32
+ def run
33
+ input_banner
34
+ validate
35
+ main_info_banner
36
+ files_banner
37
+ size_banner
38
+ end
39
+
40
+ private
41
+
42
+ def input_banner
43
+ infov 'Repository', git
44
+ infov 'Reference', reference
45
+ end
46
+
47
+ def validate
48
+ return if reference_id.present?
49
+
50
+ fatal_error "Object ID not found for reference \"#{reference}\""
51
+ end
52
+
53
+ def main_info_banner
54
+ infov 'Reference ID', reference_id
55
+ infov 'Subject', commit.subject
56
+ infov 'Author', commit.author_all
57
+ infov 'Commiter', commit.commiter_all
58
+ infov 'Files', commit.files.count
59
+ end
60
+
61
+ def size_banner
62
+ return unless options.fetch('--sizes')
63
+
64
+ infov 'Total files size', bytes_size(commit.files_size)
65
+ end
66
+
67
+ def files_banner
68
+ return unless options.fetch('--files')
69
+
70
+ commit.files.each do |file|
71
+ infov " #{file.path}", file_value(file)
72
+ end
73
+ end
74
+
75
+ def file_value(file)
76
+ s = "status: #{file.status}"
77
+ s += ", size: #{bytes_size(file.dst_size)}" if options.fetch('--sizes')
78
+ s
79
+ end
80
+
81
+ def reference_id
82
+ git.rev_parse(reference)
83
+ end
84
+
85
+ def reference
86
+ options.fetch('<ref>')
87
+ end
88
+
89
+ def git_uncached
90
+ ::EacLauncher::Git::Base.new(options.fetch('-C'))
91
+ end
92
+
93
+ def commit_uncached
94
+ ::Avm::Git::Commit.new(git, reference_id)
95
+ end
96
+
97
+ def human_files_size
98
+ ::Filesize.from("#{commit.files_size} B").pretty
99
+ end
100
+
101
+ def bytes_size(size)
102
+ b = "#{size} B"
103
+ "#{::Filesize.from(b).pretty} (#{b})"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.10.0'
5
+ VERSION = '0.11.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-11 00:00:00.000000000 Z
11
+ date: 2019-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aranha-parsers
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.1.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.1
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: clipboard
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +84,20 @@ dependencies:
64
84
  - - "~>"
65
85
  - !ruby/object:Gem::Version
66
86
  version: '0.11'
87
+ - !ruby/object:Gem::Dependency
88
+ name: filesize
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
67
101
  - !ruby/object:Gem::Dependency
68
102
  name: rspec
69
103
  requirement: !ruby/object:Gem::Requirement
@@ -126,6 +160,9 @@ files:
126
160
  - lib/avm/files.rb
127
161
  - lib/avm/files/rotate.rb
128
162
  - lib/avm/git.rb
163
+ - lib/avm/git/commit.rb
164
+ - lib/avm/git/commit/diff_tree_line.rb
165
+ - lib/avm/git/commit/file.rb
129
166
  - lib/avm/git/issue.rb
130
167
  - lib/avm/git/issue/complete.rb
131
168
  - lib/avm/git/issue/complete/_commits.rb
@@ -157,6 +194,7 @@ files:
157
194
  - lib/avm/tools/runner/files.rb
158
195
  - lib/avm/tools/runner/files/rotate.rb
159
196
  - lib/avm/tools/runner/git.rb
197
+ - lib/avm/tools/runner/git/commit.rb
160
198
  - lib/avm/tools/runner/git/issue.rb
161
199
  - lib/avm/tools/runner/git/issue/complete.rb
162
200
  - lib/avm/tools/version.rb