git_miner 0.2.2 → 0.2.3

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: f0189bf9c342c04a3575700876f73dc9132eeab57ecd5127619ed591d4a9486a
4
- data.tar.gz: 01db41129cc22cd8c4fd2ba3251603925613fe23ab028fa4b57cb88d05151b15
3
+ metadata.gz: 6a915c54b13e195ecbe3b95b74e4244702fd9bec71a984a87e59a02080ebddef
4
+ data.tar.gz: 4661c7660d691af5e236064a7da19460d5adbad3f44881b3268d955e2e59f0ea
5
5
  SHA512:
6
- metadata.gz: a1d345cc49d44ef896a5875b7b4ab12679e72ed581301d9d5ef1500b84eb2a707af14e3d632da8d5e8a3b5654d54c2adc81e66a01b1454ffde2b16f2b8b3664d
7
- data.tar.gz: f1ace38aefce766c9265269888b1c6f625461095ef5327a35723af392879d8c21e1c56a4c6d908b7f8eeda077bf5750e714b11477355b879449cce3d706aea13
6
+ metadata.gz: 5ed7b15ee18e8662845858310b5eaab75ad9e719f43c5f190dbaaf465905ab7b66261f4cea721f706b54fb41a7768a0da55ddd8282c284b12dd6d3aeb32a5ded
7
+ data.tar.gz: 0a143498f08746fcb3fa71f69988209284ef65f7e5aec5aae2e1c952f599bcc25d93735102076d988b3ab4a8d5169e493c04a8738b42c04686a686a503557c10
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_miner (0.2.1)
4
+ git_miner (0.2.2)
5
5
  concurrent-ruby (~> 1.1)
6
6
  parallel (~> 1.17)
7
7
 
data/README.md CHANGED
@@ -4,28 +4,29 @@ Pet project I built to experiment with different concepts.
4
4
 
5
5
  GitMiner allow "mining" of vanity Git SHA1 prefixes.
6
6
 
7
- This gem is a work in progress (core functionality is working).
7
+ The HEAD commit is altered via variations over committer and author timestamp adjustments. Other commit metadata such as commit message or description are left as their original.
8
8
 
9
9
 
10
10
  ## Installation
11
11
 
12
- Rubygem:
12
+ These options will add the `git-mine` binary which act as a Git custom command: `git mine`.
13
+
14
+ ### Rubygem
15
+
13
16
  ```ruby
14
17
  gem 'git_miner'
15
18
  ```
16
19
 
17
- Development:
20
+ ### Manual
21
+
18
22
  ```
19
23
  gem build git_miner.gemspec
20
24
  gem install --local git_miner-*.gem
21
25
  ```
22
26
 
23
- The installation will add the `git-mine` binary which act as a Git custom command: `git mine`.
24
-
25
-
26
27
  ## Usage
27
28
 
28
- Though `git`, using `git mine [DESIRED_PREFIX]` will invoke the required logic.
29
+ `git mine [DESIRED_PREFIX]` will amend the current HEAD commit with a new mined SHA.
29
30
 
30
31
  Eg.:
31
32
  ```
@@ -34,9 +35,19 @@ git mine c0ffee
34
35
 
35
36
  Some extra options are available (experimental):
36
37
  ```
37
- $ git-mine -h
38
- Usage: example.rb [options]
38
+ $ git mine -h
39
+ Usage: git mine [options]
39
40
  --engine [ruby|c] Set the engine (default: ruby)
40
41
  --dispatch [simple|parallel] Set the dispatch (default: parallel)
42
+ --verbose Run verbosely (default: false)
43
+ --register [prefix] Register automated post commit git hook
44
+ -v, --version Returns the current version
41
45
  -h, --help Show this message
42
46
  ```
47
+
48
+
49
+ ### Development
50
+
51
+ ```
52
+ [path]/git_miner/bin/git-mine ...
53
+ ```
data/bin/git-mine CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  STDOUT.sync = true
4
4
 
5
- require 'git_miner'
5
+ require File.join(__dir__, '..', 'lib', 'git_miner')
6
6
 
7
7
  require 'optparse'
8
8
 
@@ -12,21 +12,31 @@ options = {
12
12
  }
13
13
 
14
14
  parser = OptionParser.new do |opts|
15
- opts.banner = "Usage: example.rb [options]"
15
+ opts.banner = "Usage: git mine [options]"
16
16
 
17
- opts.on("--engine [ruby|c]", [:ruby, :c], "Set the engine (default: ruby)") do |x|
18
- options[:engine] = x
17
+ opts.on("--engine [ruby|c]", [:ruby, :c], "Set the engine (default: ruby)") do |engine|
18
+ options[:engine] = engine
19
19
  end
20
20
 
21
- opts.on("--dispatch [simple|parallel]", [:simple, :parallel], "Set the dispatch (default: parallel)") do |x|
22
- options[:dispatch] = x
21
+ opts.on("--dispatch [simple|parallel]", [:simple, :parallel], "Set the dispatch (default: parallel)") do |dispatch|
22
+ options[:dispatch] = dispatch
23
23
  end
24
24
 
25
- opts.on("-v", "--[no-]verbose", "Run verbosely (default: false)") do |v|
26
- options[:verbose] = v
25
+ opts.on("--verbose", "Run verbosely (default: false)") do |verbose|
26
+ options[:verbose] = verbose
27
27
  end
28
28
 
29
- opts.on_tail("--version", "Returns the current version") do |v|
29
+ opts.on("--register [prefix]", "Register automated post commit git hook") do |prefix|
30
+ if prefix.nil?
31
+ puts parser
32
+ exit 1
33
+ end
34
+
35
+ GitMiner::RegisterHook.register(prefix: prefix)
36
+ exit
37
+ end
38
+
39
+ opts.on_tail("-v", "--version", "Returns the current version") do
30
40
  puts "GitMiner #{GitMiner::VERSION}"
31
41
  exit
32
42
  end
@@ -1,10 +1,11 @@
1
1
  module GitMiner
2
2
  class Core
3
3
  def initialize(engine:, dispatch:, prefix:)
4
- GitMiner.logger.info("Initializing git miner.")
5
- GitMiner.logger.info("Prefix: #{prefix}")
6
- GitMiner.logger.debug("Engine: #{engine::IDENTIFIER}")
7
- GitMiner.logger.debug("Dispatch: #{dispatch::IDENTIFIER}")
4
+ GitMiner.logger.info("Initializing")
5
+
6
+ GitMiner.logger.debug("- Prefix: #{prefix}")
7
+ GitMiner.logger.debug("- Engine: #{engine::IDENTIFIER}")
8
+ GitMiner.logger.debug("- Dispatch: #{dispatch::IDENTIFIER}")
8
9
 
9
10
  @prefix = prefix
10
11
 
@@ -38,10 +39,10 @@ module GitMiner
38
39
  end
39
40
 
40
41
  unless @prefix[/^[0-9a-f]{1,32}$/]
41
- raise "Invalid prefix, expected '^[0-9a-f]{1,32}$'"
42
+ raise(UserError, "Invalid prefix, expected '^[0-9a-f]{1,32}$'")
42
43
  end
43
44
 
44
- GitMiner.logger.debug("Validations: Successful")
45
+ GitMiner.logger.debug("Prefix validation: Accepted")
45
46
  end
46
47
 
47
48
  def mine
@@ -56,8 +57,6 @@ module GitMiner
56
57
  GitMiner.logger.debug("Mining completed.")
57
58
  GitMiner.logger.debug("Author offset: #{@mining_result.author_offset}")
58
59
  GitMiner.logger.debug("Committer offset: #{@mining_result.committer_offset}")
59
-
60
- GitMiner.logger.info("New SHA: #{@mining_result.sha}")
61
60
  end
62
61
 
63
62
  def alter
@@ -66,7 +65,10 @@ module GitMiner
66
65
  author_date = @now - @mining_result.author_offset
67
66
  committer_date = @now - @mining_result.committer_offset
68
67
 
68
+ GitMiner.logger.debug("Amending git")
69
69
  GitUtil.update_current_ref(author_date, committer_date)
70
+
71
+ GitMiner.logger.info("New SHA: #{@mining_result.sha}")
70
72
  end
71
73
  end
72
74
  end
@@ -34,9 +34,10 @@ module GitMiner
34
34
  private
35
35
 
36
36
  def shell(cmd, environment: {}, stdin_data: nil)
37
- GitMiner.logger.debug("System call: #{cmd}")
38
- GitMiner.logger.debug("environment: #{environment.inspect}") unless environment.empty?
39
- GitMiner.logger.debug("stdin_data: #{stdin_data}") if stdin_data
37
+ GitMiner.logger.debug("System call")
38
+ GitMiner.logger.debug("- cmd: #{cmd}")
39
+ GitMiner.logger.debug("- environment: #{environment.inspect}") unless environment.empty?
40
+ GitMiner.logger.debug("- stdin: #{stdin_data}") if stdin_data
40
41
 
41
42
  output, status = Open3.capture2(environment, cmd, stdin_data: stdin_data) #, chdir: @working_directory
42
43
 
@@ -44,7 +45,7 @@ module GitMiner
44
45
  raise "Error on system call: #{output}, #{status}"
45
46
  end
46
47
 
47
- GitMiner.logger.debug("result: #{output.strip}")
48
+ GitMiner.logger.debug("- result => #{output.strip}")
48
49
 
49
50
  output
50
51
  end
@@ -28,22 +28,24 @@ module GitMiner
28
28
  end
29
29
 
30
30
  def report(count)
31
- info = []
32
-
33
31
  percentage = count * 100 / @combinations.to_f
34
- info << "#{'%.2f' % percentage}%"
32
+ info = []
35
33
 
36
34
  historic_count = @historic.last[:count] - @historic.first[:count]
37
35
  historic_delay = @historic.last[:timestamp] - @historic.first[:timestamp]
38
36
  if historic_delay > 0
39
37
  per_sec = historic_count / historic_delay
40
- info << "hash: #{'%.2f' % per_sec}/s"
38
+ info << "hash: #{'%.0f' % per_sec}/s"
41
39
 
42
40
  per_sec = (@historic.last[:batch] - @historic.first[:batch]) / historic_delay
43
41
  info << "batches: #{'%.2f' % per_sec}/s"
44
42
  end
45
43
 
46
- GitMiner.logger.info(info.join(', '))
44
+ if info.empty?
45
+ GitMiner.logger.info("Mining estimate #{'%.2f' % percentage}%")
46
+ else
47
+ GitMiner.logger.info("Mining estimate #{'%.2f' % percentage}% (#{info.join(', ')})")
48
+ end
47
49
  end
48
50
  end
49
51
  end
@@ -0,0 +1,29 @@
1
+ require 'fileutils'
2
+
3
+ module GitMiner
4
+ class RegisterHook
5
+ FILENAME = ".git/hooks/post-commit"
6
+
7
+ class << self
8
+ def register(prefix:)
9
+ GitMiner.logger.info("Writing hook to #{FILENAME}")
10
+
11
+ if File.exists?(FILENAME)
12
+ File.open(FILENAME, 'a') do |file|
13
+ file.puts("")
14
+ end
15
+ else
16
+ FileUtils.touch(FILENAME)
17
+ FileUtils.chmod("+x", FILENAME)
18
+ end
19
+
20
+ File.open(FILENAME, 'a') do |file|
21
+ file.puts(
22
+ "# GitMiner hook",
23
+ "git mine #{prefix}"
24
+ )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module GitMiner
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/git_miner.rb CHANGED
@@ -4,13 +4,25 @@ Dir[File.join(__dir__, 'git_miner', '**', '*.rb')].each do |file|
4
4
  end
5
5
 
6
6
  module GitMiner
7
- class Error < StandardError; end
7
+ class UserError < StandardError; end
8
8
 
9
- def self.logger
10
- @logger ||= Logger.new(STDOUT)
11
- end
9
+ class << self
10
+ def logger
11
+ return @logger if defined?(@logger)
12
+
13
+ @logger = Logger.new(STDOUT)
14
+
15
+ @logger.formatter = proc do |severity, datetime, _progname, msg|
16
+ date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
17
+
18
+ if @logger.level == Logger::INFO
19
+ "[GitMiner] #{msg}\n"
20
+ else
21
+ "[GitMiner] #{date_format} #{severity}: #{msg}\n"
22
+ end
23
+ end
12
24
 
13
- def self.logger=(logger)
14
- @logger = logger
25
+ @logger
26
+ end
15
27
  end
16
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_miner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thierry Joyal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-26 00:00:00.000000000 Z
11
+ date: 2022-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -128,6 +128,7 @@ files:
128
128
  - lib/git_miner/group_manager.rb
129
129
  - lib/git_miner/mining_result.rb
130
130
  - lib/git_miner/progress.rb
131
+ - lib/git_miner/utils/register_hook.rb
131
132
  - lib/git_miner/version.rb
132
133
  homepage: https://github.com/tjoyal/git_miner
133
134
  licenses: []