-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
clones |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "async", "~> 2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
async (2.0.3) | ||
console (~> 1.10) | ||
io-event (~> 1.0.0) | ||
timers (~> 4.1) | ||
console (1.15.3) | ||
fiber-local | ||
fiber-local (1.0.0) | ||
io-event (1.0.9) | ||
timers (4.3.3) | ||
|
||
PLATFORMS | ||
x86_64-darwin-20 | ||
|
||
DEPENDENCIES | ||
async (~> 2.0) | ||
|
||
BUNDLED WITH | ||
2.3.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
require 'async' | ||
require 'fileutils' | ||
|
||
CHARACTERS = ('0'..'9').to_a + ('a'..'f').to_a | ||
NUM_WORKERS = ENV.fetch('NUM_WORKERS', 1) | ||
CHARACTERS = (('0'..'9').to_a + ('a'..'f').to_a).freeze | ||
|
||
def random_hex_char | ||
CHARACTERS.sample | ||
end | ||
start_time = Time.now | ||
|
||
def random_short_sha | ||
Array.new(7) { random_hex_char }.join | ||
end | ||
Async do |task| | ||
NUM_WORKERS.times do |worker| | ||
task.async do | ||
repo_path = File.join('clones', start_time.to_i.to_s, "#{worker}-self-referential-commit") | ||
FileUtils.mkdir_p(repo_path) | ||
|
||
if __FILE__ == $0 | ||
counter = 0 | ||
loop do | ||
attempt = counter + 1 | ||
short_sha = random_short_sha | ||
puts "attempt #{attempt}, short sha is #{short_sha}" if (counter % 1000).zero? | ||
puts `git clone https://github.com/broothie/self-referential-commit.git #{repo_path}` | ||
|
||
message = "attempt #{attempt}: #{short_sha}" | ||
output = `git commit --allow-empty -m '#{message}'`.chomp | ||
loop do | ||
short_sha = Array.new(7) { CHARACTERS.sample }.join | ||
puts "attempt with short sha #{short_sha}" | ||
|
||
if output == "[main #{short_sha}] #{message}" | ||
puts "success! the lucky short sha is #{short_sha}" | ||
break | ||
else | ||
`git reset --hard HEAD~` | ||
end | ||
message = "short sha: #{short_sha}" | ||
puts output = `git -C #{repo_path} commit --allow-empty -m '#{message}'`.chomp | ||
|
||
counter += 1 | ||
if output == "[main #{short_sha}] #{message}" | ||
File.write('short.sha', short_sha) | ||
puts "success! the lucky short sha is #{short_sha}, under #{repo_path}" | ||
task.stop | ||
else | ||
puts `git -C #{repo_path} reset --hard HEAD~` | ||
puts `git -C #{repo_path} gc` | ||
end | ||
end | ||
end | ||
end | ||
end |