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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fb6c2b54bc742cfecb4c07dd77e511fcd288b49cb00155a9ccd8d0054bef48a
4
- data.tar.gz: e85a9d972c1aaa65d912ab4bbf3ba8e88df494e75005bd3e4262e13a79c07600
3
+ metadata.gz: 5233f9bbf3702251a2914d07093caab07a8aeaf5461f970027237c6c6ea0f301
4
+ data.tar.gz: d9171098a6fdc823d91bb7254028f5092ca1c197d14002c69369551554d7c4a1
5
5
  SHA512:
6
- metadata.gz: b6dd97af0de58bf4239d47533665be8104f7b6d88e6f15fee41c7bbf64d073bea145badb5edb4af64d6bfafe10e3635c45e6357c32897169c6038ff41c603036
7
- data.tar.gz: 1b5779debb9f9a3fc5999c3731a15dca9d4e5af93ea611d67a2fc84f4447d58620b3af46ca1dff727d9e443ba53eeb1643b7ecd136bf2562dd18d58b893d4ff0
6
+ metadata.gz: 994ca4fe6a5531b57f22144dfb31eac32be8a05c4fc0b3b14a5ede3de5e15d8e9ab26bb75af6192cf590bc05e9d338a1f70ff295381b6439830344ba14b73a54
7
+ data.tar.gz: 5998dcefbd49b274acd2035e8214ecf1e21fa5b5fd05d8ee24d924fe9be7eb01be05bcfcd8703cbe8d3d940de12a01a5e3d3fffcd0ae3a80dce845ae613e9987
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.0] 2025-03-15
4
+
5
+ - Display progress
6
+ - Automatically clone repo to tmp dir if repo is not a local directory
7
+
3
8
  ## [0.3.1] 2025-03-14
4
9
 
5
10
  - Fix changelog
@@ -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).each do |commit|
14
- db.insert_commit(**commit)
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
- COMMAND = ["git", "log", "--pretty=format:#{LOG_FORMAT}"]
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(*COMMAND, chdir: path) do |input, output, wait_thr|
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
@@ -1,3 +1,3 @@
1
1
  module Octostat
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octostat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis