git-branch_stats 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module BranchStats
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -80,46 +80,56 @@ module Git
80
80
 
81
81
  # Using the list of independent commits, gather stats
82
82
 
83
- # Start analysis before the last independent commit
84
- diff_origin = independent_commits.last + "~"
85
- commit_count = independent_commits.length
86
- # Fallback if last independent commit is the first commit of the repository
87
- # NOTE: Running the analyzer on a branch that has independent commits up to the first commit
88
- # will give weird results since it will omit this first commit in the numstats and language analysis.
89
- `git rev-parse --verify --quiet #{diff_origin}`
90
- if $?.to_i > 0
91
- diff_origin = independent_commits.last
92
-
93
- 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)"
94
- # In this case, exclude the last commit (since it won't be included in the stats)
95
- commit_count = commit_count - 1
96
- end
97
-
98
- # Numstats (files, +/-)
99
- numstats = `git diff --numstat #{diff_origin}`.split(/\n/)
100
- stats_by_file = numstats.collect do |numstat|
101
- additions, deletions, filename = numstat.split(/\t/)
102
- {:additions => additions.to_i, :deletions => deletions.to_i, :filename => filename}
103
- end
104
-
105
- # Extract content from diffs to generate language stats (only consider diffs that contain added/changed stuff)
106
- stats_by_file.select {|numstat| numstat[:additions] > 0}.each do |numstat|
107
- # Since first independent commit
108
- diff = `git diff #{diff_origin} -- #{numstat[:filename]}`
109
- # Collect lines prefixed with a single +
110
- new_content = diff.lines.select {|line| line =~ /^\+[^\+]/}.collect {|line| line[1..-1]}.join("\n")
111
- # Store in the stats for later language analysis
112
- numstat[:content] = new_content
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.2
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-05-17 00:00:00.000000000 Z
12
+ date: 2013-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github-linguist