git_miner 0.2.2 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -17
- data/README.md +20 -9
- data/bin/git-mine +19 -9
- data/ext/git_miner_ext/GitMinerExt.c +19 -13
- data/ext/git_miner_ext/extconf.rb +3 -0
- 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 +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19036e9a860b64229bdf5abee8d489b155e325c2520b709707a4417821b93f92
|
4
|
+
data.tar.gz: 1b79a6eeab4b439777646ce8763a3c35cc9c3f776794cf0d828871c6609ebae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be3d54581beda0968cc66199a8d67de09633f7fa4af3073c590fe18990c1e51419deb14cd2a49e3e792ab47160368f907eac17372154659d1de2b0c9935eafe4
|
7
|
+
data.tar.gz: 185f6efc588f2aed729856911a5bd34af54e3b3a01c5018354440ad3ce560cd662e5dfbcb4147af49ce2bb80c8a4996674b82d2886cf6693aa89e44a9ed987d7
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_miner (0.2.
|
4
|
+
git_miner (0.2.4)
|
5
5
|
concurrent-ruby (~> 1.1)
|
6
6
|
parallel (~> 1.17)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
concurrent-ruby (1.1.
|
12
|
-
diff-lcs (1.
|
13
|
-
parallel (1.
|
14
|
-
rake (13.0.
|
15
|
-
rake-compiler (1.
|
11
|
+
concurrent-ruby (1.1.10)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
parallel (1.22.1)
|
14
|
+
rake (13.0.6)
|
15
|
+
rake-compiler (1.2.1)
|
16
16
|
rake
|
17
|
-
rspec (3.
|
18
|
-
rspec-core (~> 3.
|
19
|
-
rspec-expectations (~> 3.
|
20
|
-
rspec-mocks (~> 3.
|
21
|
-
rspec-core (3.
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-expectations (3.
|
17
|
+
rspec (3.12.0)
|
18
|
+
rspec-core (~> 3.12.0)
|
19
|
+
rspec-expectations (~> 3.12.0)
|
20
|
+
rspec-mocks (~> 3.12.0)
|
21
|
+
rspec-core (3.12.0)
|
22
|
+
rspec-support (~> 3.12.0)
|
23
|
+
rspec-expectations (3.12.1)
|
24
24
|
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.
|
26
|
-
rspec-mocks (3.
|
25
|
+
rspec-support (~> 3.12.0)
|
26
|
+
rspec-mocks (3.12.1)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-support (3.
|
28
|
+
rspec-support (~> 3.12.0)
|
29
|
+
rspec-support (3.12.0)
|
30
30
|
|
31
31
|
PLATFORMS
|
32
32
|
ruby
|
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
|
@@ -1,14 +1,15 @@
|
|
1
1
|
#include "ruby.h"
|
2
|
-
|
2
|
+
|
3
3
|
#include <stdio.h>
|
4
4
|
#include <stdbool.h>
|
5
|
+
#include <openssl/sha.h>
|
5
6
|
|
6
7
|
VALUE GitMinerExt = Qnil;
|
7
8
|
|
8
9
|
void Init_git_miner_ext();
|
9
10
|
|
10
11
|
VALUE rb_sha1_hexdigest(VALUE self, VALUE rbString);
|
11
|
-
VALUE rb_sha1_mine(VALUE self,
|
12
|
+
VALUE rb_sha1_mine(VALUE self, VALUE vAuthorOffset, VALUE vCommitterOffset, VALUE vQty);
|
12
13
|
|
13
14
|
void Init_git_miner_ext() {
|
14
15
|
GitMinerExt = rb_define_module("GitMinerExt");
|
@@ -18,9 +19,9 @@ void Init_git_miner_ext() {
|
|
18
19
|
|
19
20
|
VALUE rb_sha1_hexdigest(VALUE self, VALUE rbString) {
|
20
21
|
unsigned char result[SHA_DIGEST_LENGTH];
|
21
|
-
const char
|
22
|
+
const char* string = StringValueCStr(rbString);
|
22
23
|
|
23
|
-
SHA1(string, strlen(string), result);
|
24
|
+
SHA1( (unsigned char*) string, strlen(string), result);
|
24
25
|
|
25
26
|
unsigned char resultHex[SHA_DIGEST_LENGTH*2 + 1];
|
26
27
|
int i = 0;
|
@@ -28,11 +29,15 @@ VALUE rb_sha1_hexdigest(VALUE self, VALUE rbString) {
|
|
28
29
|
sprintf((char*)&(resultHex[i*2]), "%02x", result[i]);
|
29
30
|
}
|
30
31
|
|
31
|
-
printf("ShaGenDebug: %s\n", resultHex);
|
32
|
-
return rb_str_new_cstr(resultHex);
|
32
|
+
printf("ShaGenDebug: %s\n",(char*) resultHex);
|
33
|
+
return rb_str_new_cstr((char*) resultHex);
|
33
34
|
}
|
34
35
|
|
35
|
-
VALUE rb_sha1_mine(VALUE self,
|
36
|
+
VALUE rb_sha1_mine(VALUE self, VALUE vAuthorOffset, VALUE vCommitterOffset, VALUE vQty) {
|
37
|
+
long authorOffset = FIX2LONG(vAuthorOffset);
|
38
|
+
long committerOffset = FIX2LONG(vCommitterOffset);
|
39
|
+
int qty = FIX2INT(vQty);
|
40
|
+
|
36
41
|
VALUE rbPrefix = rb_iv_get(self, "@prefix");
|
37
42
|
char* prefix = StringValueCStr(rbPrefix);
|
38
43
|
|
@@ -75,24 +80,25 @@ VALUE rb_sha1_mine(VALUE self, int authorOffset, int committerOffset, int qty) {
|
|
75
80
|
gitHeadTree,
|
76
81
|
gitHeadParent,
|
77
82
|
gitHeadAuthorPrefix,
|
78
|
-
timestamp - authorOffset,
|
83
|
+
(int) (timestamp - authorOffset),
|
79
84
|
gitHeadCommitterPrefix,
|
80
|
-
timestamp - committerOffset,
|
85
|
+
(int) (timestamp - committerOffset),
|
81
86
|
gitHeadMessage
|
82
87
|
);
|
83
88
|
|
84
|
-
sprintf(commitPrefix, "commit %d", strlen(currentHead));
|
89
|
+
sprintf(commitPrefix, "commit %d", (int) strlen(currentHead));
|
85
90
|
sprintf(currentCommit, "%s_%s", commitPrefix, currentHead);
|
86
91
|
currentCommit[strlen(commitPrefix)] = '\0';
|
87
92
|
|
88
|
-
shaLen = strlen(commitPrefix) + 1 + strlen(currentHead);
|
89
|
-
|
93
|
+
shaLen = (int) strlen(commitPrefix) + 1 + (int) strlen(currentHead);
|
94
|
+
|
95
|
+
SHA1( (unsigned char*) currentCommit, shaLen, currentSha);
|
90
96
|
|
91
97
|
for (int j = 0; j < SHA_DIGEST_LENGTH; j++) {
|
92
98
|
sprintf((char*)&(currentHex[j*2]), "%02x", currentSha[j]);
|
93
99
|
}
|
94
100
|
|
95
|
-
int prefixLen = strlen(prefix);
|
101
|
+
int prefixLen = (int) strlen(prefix);
|
96
102
|
bool match = true;
|
97
103
|
for(int j = 0; j < prefixLen; j++) {
|
98
104
|
match = match && (prefix[j] == currentHex[j]);
|
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.4
|
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-12-21 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: []
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
- !ruby/object:Gem::Version
|
150
151
|
version: '0'
|
151
152
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
153
|
+
rubygems_version: 3.3.26
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
156
|
summary: git-mine shell executable
|