git_spelunk 0.4.0 → 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 +4 -4
- data/bin/git-spelunk +12 -3
- data/lib/git_spelunk/blame.rb +27 -20
- data/lib/git_spelunk/offset.rb +2 -1
- data/lib/git_spelunk/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b01cdc9019c68eea06ac6c29c082825ca79fe38
|
4
|
+
data.tar.gz: 3b735af021fb4cc09e22ee3f27658094bf87c70f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 977b086900391210e36e91eda889a68c9327ca0e84cab598dcc51ca071658f30163ac797f650e096fbd2e410e25f767d5a9b2cf13d24b53a912b9f1ccffc5a8a
|
7
|
+
data.tar.gz: 30d809b6d384b71491be31d48501f435ad2de9f8dd61cbdba87ca4ac80c7e016a7e5f832cd565316ae7d99724d289d01aa593293d99ac47683322612bbb38421
|
data/bin/git-spelunk
CHANGED
@@ -25,7 +25,8 @@ end
|
|
25
25
|
|
26
26
|
options = parse_options(ARGV)
|
27
27
|
|
28
|
-
raise "
|
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
|
-
|
40
|
-
|
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
|
data/lib/git_spelunk/blame.rb
CHANGED
@@ -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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
28
|
-
|
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
|
data/lib/git_spelunk/offset.rb
CHANGED
@@ -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
|
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
|
data/lib/git_spelunk/version.rb
CHANGED
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.
|
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:
|
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.
|
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
|