git_spelunk 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a7fa06da8d61e779a69fb28667bf618cf067a15
4
- data.tar.gz: 0e60161a7aea4de66fec9a6f64d7a164be6a4aba
3
+ metadata.gz: 1b01cdc9019c68eea06ac6c29c082825ca79fe38
4
+ data.tar.gz: 3b735af021fb4cc09e22ee3f27658094bf87c70f
5
5
  SHA512:
6
- metadata.gz: 52d04a313b56ea8297514a270d62af51c10985cbc600361ad5e4ecf1ed603f312c41da7fd97a0e54fe7be2c2c1b1a52fe1253479ccb882b51ea0d8aad3af4424
7
- data.tar.gz: 9841ab6897ab0bfbc3abbbee1cf59331591393cfc6a13f0d9ac60d2af3711cf8c25a4623b5b8a34d66d273d1160d01ed0120f12a5c4eaaf23cd7e3d054ebe153
6
+ metadata.gz: 977b086900391210e36e91eda889a68c9327ca0e84cab598dcc51ca071658f30163ac797f650e096fbd2e410e25f767d5a9b2cf13d24b53a912b9f1ccffc5a8a
7
+ data.tar.gz: 30d809b6d384b71491be31d48501f435ad2de9f8dd61cbdba87ca4ac80c7e016a7e5f832cd565316ae7d99724d289d01aa593293d99ac47683322612bbb38421
@@ -25,7 +25,8 @@ end
25
25
 
26
26
  options = parse_options(ARGV)
27
27
 
28
- raise "Too many arguments" if ARGV.size != 1
28
+ raise "No filename specified. You must provide a file to blame-on." if ARGV.size == 0
29
+ raise "Too many arguments" if ARGV.size > 1
29
30
 
30
31
  file = ARGV[0]
31
32
 
@@ -36,6 +37,14 @@ def log(stuff)
36
37
  File.open('spelunk.log','ab'){|f| f.puts stuff }
37
38
  end
38
39
 
39
- file_context = GitSpelunk::FileContext.new(file, options)
40
- ui = GitSpelunk::UI.new(file_context)
40
+ begin
41
+ file_context = GitSpelunk::FileContext.new(file, options)
42
+
43
+ ui = GitSpelunk::UI.new(file_context)
44
+ rescue GitSpelunk::EmptyBlame => e
45
+ $stderr.puts("No git information found for '#{file}'")
46
+ exit 1
47
+ end
48
+
49
+
41
50
  #ui.run
@@ -1,35 +1,42 @@
1
1
  module GitSpelunk
2
2
  BlameLine = Struct.new(:line_number, :old_line_number, :sha, :commit, :filename, :content)
3
+ class EmptyBlame < StandardError ; end
3
4
  class Blame < Grit::Blame
4
5
  def process_raw_blame(output)
5
- lines, final = [], []
6
- info, commits = {}, {}
7
-
8
- current_filename = nil
9
- # process the output
10
- output.split("\n").each do |line|
11
- if line[0, 1] == "\t"
12
- lines << line[1, line.size]
13
- elsif m = /^(\w{40}) (\d+) (\d+)/.match(line)
14
- commit_id, old_lineno, lineno = m[1], m[2].to_i, m[3].to_i
15
- commits[commit_id] = nil
16
- info[lineno] = [commit_id, old_lineno, current_filename]
17
- elsif line =~ /^filename (.*)/
18
- current_filename = $1
19
- end
6
+ lines = []
7
+ commits = {}
8
+ commit_file_map = {}
9
+
10
+ raise EmptyBlame.new if output.empty?
11
+
12
+ split_output = output.split(/^(\w{40} \d+ \d+(?: \d+)?\n)/m)
13
+ split_output.shift if split_output.first.empty?
14
+
15
+ lines = split_output.each_slice(2).map do |sha_line, rest|
16
+ sha_split = sha_line.split(' ')
17
+
18
+ sha, old_lineno, lineno = sha_split[0], sha_split[1].to_i, sha_split[2].to_i
19
+
20
+ # indicate we need to fetch this sha in the bulk-fetch
21
+ commits[sha] = nil
22
+
23
+ if rest =~ /^filename (.*)$/
24
+ commit_file_map[sha] = $1
25
+ end
26
+
27
+ data = rest.split("\n").detect { |l| l[0] == "\t" }[1..-1]
28
+ { :data => data, :sha => sha, :filename => commit_file_map[sha], :old_line_number => old_lineno, :line_number => lineno }
20
29
  end
21
30
 
31
+
22
32
  # load all commits in single call
23
33
  @repo.batch(*commits.keys).each do |commit|
24
34
  commits[commit.id] = commit
25
35
  end
26
36
 
27
- # get it together
28
- info.sort.each do |lineno, (commit_id, old_lineno, filename)|
29
- commit = commits[commit_id]
30
- final << GitSpelunk::BlameLine.new(lineno, old_lineno, commit_id, commit, filename, lines[lineno - 1])
37
+ @lines = lines.map do |hash|
38
+ GitSpelunk::BlameLine.new(hash[:line_number], hash[:old_line_number], hash[:sha], commits[hash[:sha]], hash[:filename], hash[:data])
31
39
  end
32
- @lines = final
33
40
  end
34
41
  end
35
42
  end
@@ -113,9 +113,10 @@ module GitSpelunk
113
113
  last_old_block = blocks.last
114
114
 
115
115
  if last_old_block.type == " "
116
+ # if the previous context existed in both, just go to the end of that.
116
117
  last_old_block.offset + (last_old_block.size - 1)
117
118
  else
118
- # offset N lines into last block, but don't go beyond the edge of it.
119
+ # offset N lines into the block that was removed to create the target block, but don't go beyond the edge of it.
119
120
  last_old_block.offset + [addition_block.size - 1, last_old_block.size].min
120
121
  end
121
122
  end
@@ -1,3 +1,3 @@
1
1
  module GitSpelunk
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_spelunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-11 00:00:00.000000000 Z
12
+ date: 2016-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grit
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.3
98
+ rubygems_version: 2.4.5.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: A git tool for exploring history and blame