octostat 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/octostat/command.rb +13 -3
- data/lib/octostat/git.rb +16 -3
- data/lib/octostat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5233f9bbf3702251a2914d07093caab07a8aeaf5461f970027237c6c6ea0f301
|
4
|
+
data.tar.gz: d9171098a6fdc823d91bb7254028f5092ca1c197d14002c69369551554d7c4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 994ca4fe6a5531b57f22144dfb31eac32be8a05c4fc0b3b14a5ede3de5e15d8e9ab26bb75af6192cf590bc05e9d338a1f70ff295381b6439830344ba14b73a54
|
7
|
+
data.tar.gz: 5998dcefbd49b274acd2035e8214ecf1e21fa5b5fd05d8ee24d924fe9be7eb01be05bcfcd8703cbe8d3d940de12a01a5e3d3fffcd0ae3a80dce845ae613e9987
|
data/CHANGELOG.md
CHANGED
data/lib/octostat/command.rb
CHANGED
@@ -6,18 +6,28 @@ module Octostat
|
|
6
6
|
@db_path = "octostat.sqlite"
|
7
7
|
args = parser.parse!(args)
|
8
8
|
@path = args.first || Dir.pwd
|
9
|
+
@batch_size = 1000
|
9
10
|
end
|
10
11
|
|
11
12
|
def call
|
12
13
|
db = Database.new(db_path)
|
13
|
-
Git.new(path)
|
14
|
-
|
14
|
+
@git = Git.new(path)
|
15
|
+
git.each_slice(batch_size).with_index do |commits, batch|
|
16
|
+
puts_progress batch * batch_size
|
17
|
+
commits.each { |commit| db.insert_commit(**commit) }
|
15
18
|
end
|
19
|
+
puts_progress git.count
|
20
|
+
puts "\nDone!"
|
16
21
|
end
|
17
22
|
|
18
23
|
private
|
19
24
|
|
20
|
-
attr_reader :db_path, :path
|
25
|
+
attr_reader :db_path, :path, :batch_size, :git
|
26
|
+
|
27
|
+
def puts_progress processed
|
28
|
+
print "\r#{(processed.to_f / git.count.to_f * 100).ceil}%"
|
29
|
+
$stdout.flush
|
30
|
+
end
|
21
31
|
|
22
32
|
def parser
|
23
33
|
OptionParser.new do |opts|
|
data/lib/octostat/git.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "open3"
|
2
|
+
require "tmpdir"
|
2
3
|
|
3
4
|
module Octostat
|
4
5
|
class Git
|
@@ -15,19 +16,25 @@ module Octostat
|
|
15
16
|
|
16
17
|
ENTRY_LENGTH = LOG_FORMAT.lines.size
|
17
18
|
|
18
|
-
|
19
|
+
LIST_COMMAND = ["git", "log", "--pretty=format:#{LOG_FORMAT}"]
|
20
|
+
COUNT_COMMAND = ["git", "rev-list", "--count", "HEAD"]
|
21
|
+
CLONE_COMMAND = ["git", "clone"]
|
19
22
|
|
20
23
|
def initialize path
|
21
|
-
@path = path
|
24
|
+
@path = Dir.exist?(path) ? path : clone_repo(path)
|
22
25
|
end
|
23
26
|
|
24
27
|
def env
|
25
28
|
{"GIT_DIR" => path}
|
26
29
|
end
|
27
30
|
|
31
|
+
def count
|
32
|
+
@count ||= Open3.capture2(*COUNT_COMMAND, chdir: path).first.to_i
|
33
|
+
end
|
34
|
+
|
28
35
|
def each
|
29
36
|
return enum_for(:each) unless block_given?
|
30
|
-
Open3.popen2e(*
|
37
|
+
Open3.popen2e(*LIST_COMMAND, chdir: path) do |input, output, wait_thr|
|
31
38
|
output.each_slice(ENTRY_LENGTH) do |commit|
|
32
39
|
commit.each(&:strip!)
|
33
40
|
hash, email, name, date, parents, subject = commit
|
@@ -46,6 +53,12 @@ module Octostat
|
|
46
53
|
|
47
54
|
private
|
48
55
|
|
56
|
+
def clone_repo upstream
|
57
|
+
repo_path = Dir.mktmpdir
|
58
|
+
Open3.capture2(*CLONE_COMMAND, upstream, repo_path)
|
59
|
+
repo_path
|
60
|
+
end
|
61
|
+
|
49
62
|
attr_reader :path
|
50
63
|
end
|
51
64
|
end
|
data/lib/octostat/version.rb
CHANGED