-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathgit.rb
More file actions
47 lines (44 loc) · 1.32 KB
/
Copy pathgit.rb
File metadata and controls
47 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-FileCopyrightText: Copyright (c) 2014-2026 Yegor Bugayenko
# SPDX-License-Identifier: MIT
require 'date'
require 'hoc/hits'
module HOC
# Git source code base.
class Git
def initialize(dir, exclude, author, since, before)
@dir = dir
@exclude = exclude
@author = author
@since = since
@before = before
end
def hits
version = `git --version`.split(/ /)[2]
raise(StandardError, "git version #{version} is too old, upgrade it to 2.0+") unless
Gem::Version.new(version) >= Gem::Version.new('2.0')
cmd = [
"cd #{@dir} && git",
'log', '--pretty=tformat:', '--numstat',
'--ignore-space-change', '--ignore-all-space',
'--ignore-submodules', '--no-color',
'--find-copies-harder', '-M', '--diff-filter=ACDM',
"'--author=#{@author}'",
"'--since=#{@since}'",
"'--before=#{@before}'",
'--', '.',
@exclude.map { |e| "':(exclude,glob)#{e}'" }.join(' ')
].join(' ')
[
Hits.new(
Time.now,
`#{cmd}`.split("\n").delete_if(&:empty?).map do |t|
parts = t.split("\t").take(2)
next 0 if parts.any? { |n| n == '-' }
parts.map! { |n| Integer(n) }
parts.inject(:+)
end.inject(:+) || 0
)
]
end
end
end