octostat 0.3.0 → 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: d6c0ebd758965992e92891eab5bc84a686faee4febe56824d7caaa4cefccd683
4
- data.tar.gz: 2ace567260f96559ab9650037ac72402e26381922ee1a301a8349cfdbf7e988c
3
+ metadata.gz: 5233f9bbf3702251a2914d07093caab07a8aeaf5461f970027237c6c6ea0f301
4
+ data.tar.gz: d9171098a6fdc823d91bb7254028f5092ca1c197d14002c69369551554d7c4a1
5
5
  SHA512:
6
- metadata.gz: 71eac438522c71bcd0c85c60d5f8b9f7a19392e011c75261e27aee675b4302ec5d93bff863c3aa2c0d72bfd9273bfe51c81c835ee75132aa54028ac8d56b8233
7
- data.tar.gz: 1645d6dbb6fa2a655759d8ef18a613f1670cbcbd0bf3c90a79585d43007a9f3d88f8375a17d168a30ee448eec775f402de51c047cca240f23a20abdd381caa50
6
+ metadata.gz: 994ca4fe6a5531b57f22144dfb31eac32be8a05c4fc0b3b14a5ede3de5e15d8e9ab26bb75af6192cf590bc05e9d338a1f70ff295381b6439830344ba14b73a54
7
+ data.tar.gz: 5998dcefbd49b274acd2035e8214ecf1e21fa5b5fd05d8ee24d924fe9be7eb01be05bcfcd8703cbe8d3d940de12a01a5e3d3fffcd0ae3a80dce845ae613e9987
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ ## [Unreleased]
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
+
8
+ ## [0.3.1] 2025-03-14
9
+
10
+ - Fix changelog
11
+
12
+ ## [0.3.0] 2025-03-14
13
+
14
+ - First working release.
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
7
7
  t.test_files = FileList["test/**/*_test.rb"]
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
data/exe/octostat CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'octostat'
3
+ require "octostat"
4
4
 
5
- Octostat::Command.new(*ARGV).call
5
+ Octostat::Command.new(*ARGV).call
@@ -1,5 +1,4 @@
1
- require 'optparse'
2
-
1
+ require "optparse"
3
2
 
4
3
  module Octostat
5
4
  class Command
@@ -7,18 +6,28 @@ module Octostat
7
6
  @db_path = "octostat.sqlite"
8
7
  args = parser.parse!(args)
9
8
  @path = args.first || Dir.pwd
9
+ @batch_size = 1000
10
10
  end
11
11
 
12
12
  def call
13
13
  db = Database.new(db_path)
14
- Git.new(path).each do |commit|
15
- 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) }
16
18
  end
19
+ puts_progress git.count
20
+ puts "\nDone!"
17
21
  end
18
22
 
19
23
  private
20
24
 
21
- 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
22
31
 
23
32
  def parser
24
33
  OptionParser.new do |opts|
@@ -1,4 +1,4 @@
1
- require 'forwardable'
1
+ require "forwardable"
2
2
  require "sqlite3"
3
3
 
4
4
  module Octostat
@@ -6,12 +6,12 @@ module Octostat
6
6
  extend Forwardable
7
7
 
8
8
  PRAGMAS = {
9
- "foreign_keys" => true,
10
- "journal_mode" => :wal,
11
- "synchronous" => :normal,
12
- "mmap_size" => 134217728, # 128 megabytes
13
- "journal_size_limit" => 67108864, # 64 megabytes
14
- "cache_size" => 2000
9
+ "foreign_keys" => true,
10
+ "journal_mode" => :wal,
11
+ "synchronous" => :normal,
12
+ "mmap_size" => 134217728, # 128 megabytes
13
+ "journal_size_limit" => 67108864, # 64 megabytes
14
+ "cache_size" => 2000
15
15
  }
16
16
 
17
17
  COMMIT_INSERT = "INSERT OR IGNORE INTO commits (hash, email, name, date, merge_commit, subject) VALUES (?, ?, ?, ?, ?, ?)"
@@ -56,7 +56,7 @@ module Octostat
56
56
 
57
57
  def apply_pragma
58
58
  PRAGMAS.each do |pragma, value|
59
- db.public_send("#{pragma}=", value)
59
+ db.public_send(:"#{pragma}=", value)
60
60
  end
61
61
  end
62
62
 
data/lib/octostat/git.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "open3"
2
-
2
+ require "tmpdir"
3
3
 
4
4
  module Octostat
5
5
  class Git
@@ -16,19 +16,25 @@ module Octostat
16
16
 
17
17
  ENTRY_LENGTH = LOG_FORMAT.lines.size
18
18
 
19
- 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"]
20
22
 
21
23
  def initialize path
22
- @path = path
24
+ @path = Dir.exist?(path) ? path : clone_repo(path)
23
25
  end
24
26
 
25
27
  def env
26
28
  {"GIT_DIR" => path}
27
29
  end
28
30
 
31
+ def count
32
+ @count ||= Open3.capture2(*COUNT_COMMAND, chdir: path).first.to_i
33
+ end
34
+
29
35
  def each
30
36
  return enum_for(:each) unless block_given?
31
- Open3.popen2e(*COMMAND, chdir: path) do |input, output, wait_thr|
37
+ Open3.popen2e(*LIST_COMMAND, chdir: path) do |input, output, wait_thr|
32
38
  output.each_slice(ENTRY_LENGTH) do |commit|
33
39
  commit.each(&:strip!)
34
40
  hash, email, name, date, parents, subject = commit
@@ -47,6 +53,12 @@ module Octostat
47
53
 
48
54
  private
49
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
+
50
62
  attr_reader :path
51
63
  end
52
64
  end
@@ -1,3 +1,3 @@
1
1
  module Octostat
2
- VERSION = "0.3.0"
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.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis
@@ -24,48 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: debug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
27
  description:
70
28
  email:
71
29
  - joe@dupuis.io
@@ -74,6 +32,7 @@ executables:
74
32
  extensions: []
75
33
  extra_rdoc_files: []
76
34
  files:
35
+ - CHANGELOG.md
77
36
  - LICENSE.txt
78
37
  - README.md
79
38
  - Rakefile
@@ -89,7 +48,7 @@ licenses:
89
48
  metadata:
90
49
  homepage_uri: https://github.com/testdouble/octostat
91
50
  source_code_uri: https://github.com/testdouble/octostat
92
- changelog_uri: https://github.com/testdouble/octostat/main/CHANGELOG.md
51
+ changelog_uri: https://github.com/testdouble/octostat/blob/main/CHANGELOG.md
93
52
  post_install_message:
94
53
  rdoc_options: []
95
54
  require_paths: