mgit 0.4.1 → 0.4.2

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: 556e8ba86002bf2296aa9a64b22c832e0ffe6b7d
4
- data.tar.gz: cfef22c03019ddab0475023c09b83380e17921fa
3
+ metadata.gz: 0bb3bdcd576ecd50f3d7d8a184f5bc58d8834562
4
+ data.tar.gz: 22d8aac580b7b69cf884120b9005c9bff8e8135b
5
5
  SHA512:
6
- metadata.gz: 0d4b7e77396c509b701a5338906fad08c40d97a222dcf7e1bd22131a7e8a888cc3ff197641979b12e8a9e98114d3c7fc1720b8129dd3508607a0598c46c87117
7
- data.tar.gz: d81f3c80978f0532014dff8fb51ca1ee39acecb47c3537e264037d8e1a95f8fb5edae7d58cdabd217e29050ec8589e2d4a91c0a4cb3e48e4588d082c9ce1824b
6
+ metadata.gz: b6a82916b544e654920d4c63da49bff65ceaa88bbbf40330499a97d1b8e1fbca7cb8654ae67a365a42a03661801fa81be05ef1df5c0a48092df7b26b05352df2
7
+ data.tar.gz: e9d9dbb58cd51a1cab081e07637c19c299ab714ecab5feab47faec7889366b397dcc2126b80267bd330b1d5b551b6c57f9e6116078364e4581e98a4645cd9128
data/lib/mgit/cli.rb CHANGED
@@ -8,6 +8,9 @@ module MGit
8
8
  # Initialize AppData and migrate if necessary.
9
9
  AppData.update
10
10
 
11
+ # Initialize Commands.
12
+ Command.load_commands
13
+
11
14
  # Run command, consuming its name from the list of arguments.
12
15
  command = Command.execute(ARGV.shift, ARGV)
13
16
  rescue UsageError => e
data/lib/mgit/command.rb CHANGED
@@ -5,6 +5,11 @@ module MGit
5
5
  @@commands = {}
6
6
  @@aliases = {}
7
7
 
8
+ def self.load_commands
9
+ require_commands_from_directory File.expand_path('../commands', __FILE__)
10
+ require_commands_from_directory Configuration.plugindir
11
+ end
12
+
8
13
  def self.execute(name, args)
9
14
  cmd = self.create(name)
10
15
  cmd.check_arity(args)
@@ -52,5 +57,9 @@ module MGit
52
57
  raise UnknownCommandError.new(cmd)
53
58
  end
54
59
  end
60
+
61
+ def self.require_commands_from_directory(dir)
62
+ Dir["#{dir}/*.rb"].each { |file| require file }
63
+ end
55
64
  end
56
65
  end
@@ -4,6 +4,11 @@ module MGit
4
4
  :threads => {
5
5
  :default => true,
6
6
  :description => 'set to true if you want the fetch command to be threaded'
7
+ },
8
+
9
+ :plugindir => {
10
+ :default => File.join(AppData::AppDataVersion.latest.send(:config_dir), 'plugins'),
11
+ :description => 'directory from where plugin commands are loaded'
7
12
  }
8
13
  }
9
14
 
@@ -12,6 +17,12 @@ module MGit
12
17
  define_method(k.to_s) do
13
18
  AppData.load(k, v[:default])
14
19
  end
20
+
21
+ define_method("#{k.to_s}=") do |value|
22
+ AppData.save!(k, value)
23
+ end
24
+
25
+ private "#{k.to_s}="
15
26
  end
16
27
  end
17
28
 
@@ -31,15 +42,5 @@ module MGit
31
42
  raise ConfigurationError.new("Unknown key: #{key}.")
32
43
  end
33
44
  end
34
-
35
- private
36
-
37
- class << self
38
- KEYS.each do |k, v|
39
- define_method("#{k.to_s}=") do |value|
40
- AppData.save!(k, value)
41
- end
42
- end
43
- end
44
45
  end
45
46
  end
data/lib/mgit/output.rb CHANGED
@@ -24,6 +24,7 @@ module MGit
24
24
  def initialize(table, options)
25
25
  @table = table
26
26
  @options = options
27
+ @options[:columns] = []
27
28
  raise ImplementationError.new('ptable called with invalid table') unless valid_table?
28
29
  end
29
30
 
@@ -31,11 +32,6 @@ module MGit
31
32
  return '' if table.empty?
32
33
 
33
34
  cw = column_widths
34
- if options[:columns]
35
- options[:columns].each_with_index do |c, i|
36
- cw[i] = c if c
37
- end
38
- end
39
35
 
40
36
  table.map do |row|
41
37
  row.map.with_index do |cell, i|
@@ -65,6 +61,12 @@ module MGit
65
61
  end
66
62
 
67
63
  def column_widths
64
+ column_max_widths.each_with_index.map do |c, i|
65
+ (options[:columns].size > i && options[:columns][i]) ? options[:columns][i] : c
66
+ end
67
+ end
68
+
69
+ def column_max_widths
68
70
  transpose.map do |col|
69
71
  col.map { |cell| cell.size }.max
70
72
  end
data/lib/mgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MGit
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
data/lib/mgit.rb CHANGED
@@ -12,7 +12,6 @@ require 'mgit/repository'
12
12
 
13
13
  require 'mgit/cli'
14
14
  require 'mgit/command'
15
- Dir["#{File.expand_path('../mgit/commands', __FILE__)}/*.rb"].each { |file| require file }
16
15
 
17
16
  module MGit
18
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FlavourSys Technology GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -85,7 +85,6 @@ files:
85
85
  - lib/mgit/commands/grep.rb
86
86
  - lib/mgit/commands/config.rb
87
87
  - lib/mgit/commands/remove_all.rb
88
- - lib/mgit/commands/statistics.rb
89
88
  - lib/mgit/commands/version.rb
90
89
  - lib/mgit/commands/fetch.rb
91
90
  - lib/mgit/commands/head.rb
@@ -1,100 +0,0 @@
1
- require 'set'
2
-
3
- module MGit
4
- class StatisticsCommand < Command
5
- def execute(args)
6
- total_authors = {}
7
- total_punchcard = {}
8
- Registry.chdir_each do |repo|
9
- current_authors = {}
10
- current_punchcard = {}
11
-
12
- collect do |author, time, changes|
13
- current_authors[author] ||= 0
14
- current_authors[author] += changes
15
-
16
- total_punchcard[time.wday] ||= {}
17
- total_punchcard[time.wday][time.hour / 4] ||= 0
18
- total_punchcard[time.wday][time.hour / 4] += changes
19
- end
20
-
21
- print_authors current_authors, repo.name
22
- puts
23
-
24
- current_authors.each do |author, changes|
25
- total_authors[author] ||= 0
26
- total_authors[author] += changes
27
- end
28
- end
29
-
30
- print_authors total_authors, 'TOTAL'
31
- puts
32
- print_punchcard total_punchcard, 'TOTAL'
33
- end
34
-
35
- def arity
36
- [nil, 0]
37
- end
38
-
39
- def usage
40
- 'statistics'
41
- end
42
-
43
- def description
44
- 'display authorship statistics for each repository and in total'
45
- end
46
-
47
- register_command :statistics
48
-
49
- # Too close to :status?
50
- #register_alias :stats
51
-
52
- private
53
-
54
- def collect
55
- log = `git log --format='<><>%ct %aN' --shortstat --all`.strip
56
- commits = log.split('<><>').drop(1)
57
-
58
- commits.each do |c|
59
- lines = c.split("\n")
60
-
61
- time = lines[0].split(' ')[0]
62
- author = lines[0].split(' ')[1..-1].join(' ')
63
-
64
- if lines.size >= 3
65
- m = /changed(?:, (\d+) insertion(?:s)?\(\+\))?(?:, (\d+) deletion(?:s)?\(\-\))?/.match(lines[2])
66
- changes = (m.captures[0] || 0).to_i + (m.captures[1] || 0).to_i
67
- else
68
- changes = 0
69
- end
70
-
71
- yield author, Time.at(time.to_i), changes
72
- end
73
- end
74
-
75
- def print_authors(data, name)
76
- pinfo "Authorship statistics (#{name}):"
77
- ptable (data.to_a.sort_by { |v| v[1] }.reverse), :columns => [24, nil]
78
- end
79
-
80
- def print_punchcard(data, name)
81
- pinfo "Punchcard (#{name}):"
82
-
83
- t = []
84
- t << ['', '0-4', '4-8', '8-12', '12-16', '16-20', '20-24']
85
- ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].each_with_index do |day, wday|
86
- l = [day]
87
- 6.times do |h|
88
- if (data[wday] && data[wday][h])
89
- l << data[wday][h].to_s
90
- else
91
- l << '0'
92
- end
93
- end
94
- t << l
95
- end
96
-
97
- ptable t
98
- end
99
- end
100
- end