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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +20 -9
- data/bin/git-mine +19 -9
- data/lib/git_miner/core.rb +10 -8
- data/lib/git_miner/git_util.rb +5 -4
- data/lib/git_miner/progress.rb +7 -5
- data/lib/git_miner/utils/register_hook.rb +29 -0
- data/lib/git_miner/version.rb +1 -1
- data/lib/git_miner.rb +18 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a915c54b13e195ecbe3b95b74e4244702fd9bec71a984a87e59a02080ebddef
|
4
|
+
data.tar.gz: 4661c7660d691af5e236064a7da19460d5adbad3f44881b3268d955e2e59f0ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ed7b15ee18e8662845858310b5eaab75ad9e719f43c5f190dbaaf465905ab7b66261f4cea721f706b54fb41a7768a0da55ddd8282c284b12dd6d3aeb32a5ded
|
7
|
+
data.tar.gz: 0a143498f08746fcb3fa71f69988209284ef65f7e5aec5aae2e1c952f599bcc25d93735102076d988b3ab4a8d5169e493c04a8738b42c04686a686a503557c10
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
38
|
-
Usage:
|
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:
|
15
|
+
opts.banner = "Usage: git mine [options]"
|
16
16
|
|
17
|
-
opts.on("--engine [ruby|c]", [:ruby, :c], "Set the engine (default: ruby)") do |
|
18
|
-
options[:engine] =
|
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 |
|
22
|
-
options[:dispatch] =
|
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("
|
26
|
-
options[:verbose] =
|
25
|
+
opts.on("--verbose", "Run verbosely (default: false)") do |verbose|
|
26
|
+
options[:verbose] = verbose
|
27
27
|
end
|
28
28
|
|
29
|
-
opts.
|
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
|
data/lib/git_miner/core.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
module GitMiner
|
2
2
|
class Core
|
3
3
|
def initialize(engine:, dispatch:, prefix:)
|
4
|
-
GitMiner.logger.info("Initializing
|
5
|
-
|
6
|
-
GitMiner.logger.debug("
|
7
|
-
GitMiner.logger.debug("
|
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("
|
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
|
data/lib/git_miner/git_util.rb
CHANGED
@@ -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
|
38
|
-
GitMiner.logger.debug("
|
39
|
-
GitMiner.logger.debug("
|
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
|
48
|
+
GitMiner.logger.debug("- result => #{output.strip}")
|
48
49
|
|
49
50
|
output
|
50
51
|
end
|
data/lib/git_miner/progress.rb
CHANGED
@@ -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
|
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: #{'%.
|
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
|
-
|
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
|
data/lib/git_miner/version.rb
CHANGED
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
|
7
|
+
class UserError < StandardError; end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
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.
|
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:
|
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: []
|