octostat 0.3.1 → 0.4.1

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: da2005b56adfaf8ca9bb935014dc81652541e6ec5d95b61797dd21e19cb2932a
4
+ data.tar.gz: d308b1fcda48af4006a4d69e6282af158273c852e0c7b9a8090e34a316140dfe
5
5
  SHA512:
6
- metadata.gz: b6dd97af0de58bf4239d47533665be8104f7b6d88e6f15fee41c7bbf64d073bea145badb5edb4af64d6bfafe10e3635c45e6357c32897169c6038ff41c603036
7
- data.tar.gz: 1b5779debb9f9a3fc5999c3731a15dca9d4e5af93ea611d67a2fc84f4447d58620b3af46ca1dff727d9e443ba53eeb1643b7ecd136bf2562dd18d58b893d4ff0
6
+ metadata.gz: 90eb0b7bd727dd300c3329b28f58f70c5e5dcc3460e0c8b36476212fad4112c14753a3e1a6a3b8761ac15fa0baac5b4a9bba368814981452846ed414af5038ef
7
+ data.tar.gz: 71bef1bcad902a94e879b6cec4345557578b5a9b266ff6bc6c529f94ac5000dde42b0fa64347c8665f23b43020b3fb4232d7f079d118889fbdf2553d147ad247
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.1] 2025-03-15
4
+
5
+ - Better error on missing repo
6
+
7
+ ## [0.4.0] 2025-03-15
8
+
9
+ - Display progress
10
+ - Automatically clone repo to tmp dir if repo is not a local directory
11
+
3
12
  ## [0.3.1] 2025-03-14
4
13
 
5
14
  - Fix changelog
@@ -6,18 +6,31 @@ 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!"
21
+ rescue Octostat::Error => e
22
+ warn e.message
23
+ exit 1
16
24
  end
17
25
 
18
26
  private
19
27
 
20
- attr_reader :db_path, :path
28
+ attr_reader :db_path, :path, :batch_size, :git
29
+
30
+ def puts_progress processed
31
+ print "\r#{(processed.to_f / git.count.to_f * 100).ceil}%"
32
+ $stdout.flush
33
+ end
21
34
 
22
35
  def parser
23
36
  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,14 @@ module Octostat
46
53
 
47
54
  private
48
55
 
56
+ def clone_repo upstream
57
+ puts "Cloning #{upstream}"
58
+ repo_path = Dir.mktmpdir
59
+ status = Open3.capture2(*CLONE_COMMAND, upstream, repo_path)[1]
60
+ raise Octostat::Error.new("Error cloning '#{upstream}'") unless status.success?
61
+ repo_path
62
+ end
63
+
49
64
  attr_reader :path
50
65
  end
51
66
  end
@@ -1,3 +1,3 @@
1
1
  module Octostat
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.1"
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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joé Dupuis