git-branch_stats 0.0.2 → 0.0.3
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.
- data/lib/git-branch_stats/version.rb +1 -1
- data/lib/git-branch_stats.rb +48 -38
- metadata +2 -2
data/lib/git-branch_stats.rb
CHANGED
@@ -80,46 +80,56 @@ module Git
|
|
80
80
|
|
81
81
|
# Using the list of independent commits, gather stats
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
83
|
+
if independent_commits.any?
|
84
|
+
# Start analysis before the last independent commit
|
85
|
+
diff_origin = independent_commits.last + "~"
|
86
|
+
commit_count = independent_commits.length
|
87
|
+
# Fallback if last independent commit is the first commit of the repository
|
88
|
+
# NOTE: Running the analyzer on a branch that has independent commits up to the first commit
|
89
|
+
# will give weird results since it will omit this first commit in the numstats and language analysis.
|
90
|
+
`git rev-parse --verify --quiet #{diff_origin}`
|
91
|
+
if $?.to_i > 0
|
92
|
+
diff_origin = independent_commits.last
|
93
|
+
|
94
|
+
warnings.push "WARN: Branch has independent commits since the first commit of the repo, stats will be skewed (can't run stats *before* the first commit)"
|
95
|
+
# In this case, exclude the last commit (since it won't be included in the stats)
|
96
|
+
commit_count = commit_count - 1
|
97
|
+
end
|
98
|
+
|
99
|
+
# Numstats (files, +/-)
|
100
|
+
numstats = `git diff --numstat #{diff_origin}`.split(/\n/)
|
101
|
+
stats_by_file = numstats.collect do |numstat|
|
102
|
+
additions, deletions, filename = numstat.split(/\t/)
|
103
|
+
{:additions => additions.to_i, :deletions => deletions.to_i, :filename => filename}
|
104
|
+
end
|
105
|
+
|
106
|
+
# Extract content from diffs to generate language stats (only consider diffs that contain added/changed stuff)
|
107
|
+
stats_by_file.select {|numstat| numstat[:additions] > 0}.each do |numstat|
|
108
|
+
# Since first independent commit
|
109
|
+
diff = `git diff #{diff_origin} -- #{numstat[:filename]}`
|
110
|
+
# Collect lines prefixed with a single +
|
111
|
+
new_content = diff.lines.select {|line| line =~ /^\+[^\+]/}.collect {|line| line[1..-1]}.join("\n")
|
112
|
+
# Store in the stats for later language analysis
|
113
|
+
numstat[:content] = new_content
|
114
|
+
end
|
115
|
+
|
116
|
+
# Extract language stats using github's linguist gem
|
117
|
+
language_stats = extract_language_stats(stats_by_file)
|
118
|
+
|
119
|
+
# Normalize stats for json REST API
|
120
|
+
change_count = stats_by_file.length
|
121
|
+
total_additions = stats_by_file.inject(0) {|total, numstat| total += numstat[:additions]}
|
122
|
+
total_deletions = stats_by_file.inject(0) {|total, numstat| total += numstat[:deletions]}
|
123
|
+
else
|
124
|
+
commit_count = 0
|
125
|
+
total_additions = 0
|
126
|
+
total_deletions = 0
|
127
|
+
change_count = 0
|
128
|
+
language_stats = []
|
129
|
+
emails = []
|
130
|
+
warnings.push "No independent commits yet, commit something!"
|
113
131
|
end
|
114
132
|
|
115
|
-
# Extract language stats using github's linguist gem
|
116
|
-
language_stats = extract_language_stats(stats_by_file)
|
117
|
-
|
118
|
-
# Normalize stats for json REST API
|
119
|
-
commit_count = commit_count
|
120
|
-
change_count = stats_by_file.length
|
121
|
-
total_additions = stats_by_file.inject(0) {|total, numstat| total += numstat[:additions]}
|
122
|
-
total_deletions = stats_by_file.inject(0) {|total, numstat| total += numstat[:deletions]}
|
123
133
|
{
|
124
134
|
:commits => commit_count,
|
125
135
|
:additions => total_additions,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-branch_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: github-linguist
|