git_spelunk 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzAyMWIwY2EzMjU2NWM1YTFmMDE3NDFkOTQzODg2ZmEwYzBiZDM5MQ==
5
+ data.tar.gz: !binary |-
6
+ Zjg4Nzg3ZDhkN2QwODAzOTQxY2Y2YTYzMWE0NWQ3NjE2ZjFiYjg1OQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ M2M4MjljMTM1ODMwMjZlZGY1YTFjOGNiODYxNWRjMGNmOTM2ZmFjZTU0NDc1
10
+ MDNlYWQxMzJlOTc2Njg1Y2EyMDMxNzI1YjZlYTVhODNhMjY4Yjg4ZDQyOGIy
11
+ OWUwODI5YzI2Mjg5N2E4YWI2ZWQxZWE2ZmExMDIxYzkwNzZlZmY=
12
+ data.tar.gz: !binary |-
13
+ NTUxYTYwZGZlNGM3MTIzMDIyY2EzMTI4ZTkwMzJjZWY2NjRlNTlhYzJmZGVm
14
+ OWQwMmVhYzZjYTAxNTRmMmJmZGFmMmNhYmE1NjY1YzYyMGY0M2NmOTU0YjFm
15
+ YWU5ZTc0M2YzYTlhYTk2ODIzMTI0NzU0NWYzOTNjMDUzMDA2MDg=
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  module GitSpelunk
5
5
  class FileContext
6
6
  attr_accessor :line_number
7
- attr_reader :repo
7
+ attr_reader :repo, :sha, :file
8
8
 
9
9
  def initialize(file, options = {})
10
10
  @sha = options[:sha] || 'HEAD'
@@ -27,8 +27,17 @@ module GitSpelunk
27
27
  end
28
28
 
29
29
  def get_line_for_sha_parent(line_number)
30
- o = GitSpelunk::Offset.new(@repo, @file, sha_for_line(line_number))
31
- o.line_number_to_parent(@new_to_old[line_number])
30
+ o = GitSpelunk::Offset.new(@repo, @file, sha_for_line(line_number), @new_to_old[line_number])
31
+ line = o.line_number_to_parent
32
+ if line
33
+ line
34
+ else
35
+ if o.at_beginning_of_time?
36
+ :at_beginning_of_time
37
+ elsif o.unable_to_trace_lineage?
38
+ :unable_to_trace
39
+ end
40
+ end
32
41
  end
33
42
 
34
43
  def find_repo_from_file(file)
@@ -0,0 +1,9 @@
1
+ require 'grit'
2
+
3
+ if RUBY_VERSION >= "2.0.0"
4
+ class String
5
+ def getord(offset); self[offset].ord; end
6
+ end
7
+
8
+ PACK_IDX_SIGNATURE = "\377tOc".force_encoding(Encoding::ASCII_8BIT)
9
+ end
@@ -38,33 +38,49 @@ module GitSpelunk
38
38
  class Offset
39
39
  attr_reader :repo, :file_name, :sha, :chunks
40
40
 
41
- def initialize(repo, file_name, sha)
41
+ def initialize(repo, file_name, sha, line_number)
42
42
  @repo = repo
43
43
  @file_name = file_name
44
44
  @sha = sha
45
- parent_sha = @repo.commits(@sha)[0].parents[0].id
46
- @chunks = diff_chunks(@repo.diff(parent_sha, @sha, @file_name))
45
+ @line_number = line_number
46
+ @parent = @repo.commits(@sha)[0].parents[0]
47
+ true
47
48
  end
48
49
 
49
- def diff_chunks(diffs)
50
- return nil if diffs.empty?
51
- # split it into chunks: [["@@ -10,13 +10,18 @@", diffs], ["@@ -20,13 +20,18 @@", diffs, diff]]
52
- multiple_chunks = diffs[0].diff.split(/(@@ \-\d+,\d+ \+\d+,\d+ @@.*?\n)/)
53
- # Discard file name line
54
- multiple_chunks[1..multiple_chunks.length].each_slice(2).to_a
50
+ def chunks
51
+ @chunks ||= diff_chunks(@repo.diff(@parent.id, @sha, @file_name))
52
+ end
53
+
54
+ def at_beginning_of_time?
55
+ @parent.nil?
56
+ end
57
+
58
+ def unable_to_trace_lineage?
59
+ @parent && (@chunks.nil? || target_chunk.nil?)
55
60
  end
56
61
 
57
- def line_number_to_parent(src_line_number)
58
- return nil unless @chunks
59
- chunk = target_chunk(src_line_number)
62
+ def line_number_to_parent
63
+ return nil unless @parent && chunks
64
+ chunk = target_chunk(@line_number)
65
+ return nil unless chunk
66
+
60
67
  chunk_starting_line, chunk_total_lines = src_start_and_total(stats_line(chunk))
61
68
  parent_starting_line = parent_start_and_total(stats_line(chunk))[0]
62
- parent_line_offset = find_parent_line_number(diff_lines(chunk), src_line_number, chunk_starting_line, chunk_total_lines)
69
+ parent_line_offset = find_parent_line_number(diff_lines(chunk), @line_number, chunk_starting_line, chunk_total_lines)
63
70
  parent_starting_line + parent_line_offset
64
71
  end
65
72
 
66
73
  private
67
74
 
75
+ def diff_chunks(diffs)
76
+ return nil if diffs.empty?
77
+ # split it into chunks: [["@@ -10,13 +10,18 @@", diffs], ["@@ -20,13 +20,18 @@", diffs, diff]]
78
+ multiple_chunks = diffs[0].diff.split(/(@@ \-\d+,\d+ \+\d+,\d+ @@.*?\n)/)
79
+ # Discard file name line
80
+ multiple_chunks[1..multiple_chunks.length].each_slice(2).to_a
81
+ end
82
+
83
+
68
84
  def target_chunk(line_number)
69
85
  chunks.select {|chunk| has_line?(chunk, line_number)}[0]
70
86
  end
@@ -5,9 +5,20 @@ module GitSpelunk
5
5
  @window = Curses::Window.new(height, Curses.cols, offset, 0)
6
6
  @offset = offset
7
7
  @command_buffer = ""
8
+ @status_message = ""
9
+ @onetime_message = nil
8
10
  end
9
11
 
10
- attr_accessor :command_buffer
12
+ attr_accessor :command_buffer, :status_message
13
+
14
+ def clear_onetime_message!
15
+ @onetime_message = nil
16
+ end
17
+
18
+ def set_onetime_message(message)
19
+ @onetime_message = message
20
+ draw
21
+ end
11
22
 
12
23
  def exit_command_mode!
13
24
  self.command_buffer = ""
@@ -26,6 +37,7 @@ module GitSpelunk
26
37
  else
27
38
  Curses.curs_set(0)
28
39
  with_highlighting do
40
+ @window.addstr(@onetime_message || @status_message)
29
41
  @window.addstr(" " * line_remainder + "\n")
30
42
  end
31
43
  end
@@ -19,6 +19,7 @@ module GitSpelunk
19
19
  @repo = RepoWindow.new(@repo_height, @pager_height)
20
20
 
21
21
  @status = StatusWindow.new(1, Curses.lines - 1)
22
+ set_status_message
22
23
  end
23
24
 
24
25
  def init_curses
@@ -49,6 +50,10 @@ module GitSpelunk
49
50
  end while true
50
51
  end
51
52
 
53
+ def set_status_message
54
+ @status.status_message = "#{@file_context.file} @ #{@file_context.sha}"
55
+ end
56
+
52
57
  def pause_thread
53
58
  Thread.abort_on_exception = true
54
59
  Thread.new do
@@ -59,7 +64,6 @@ module GitSpelunk
59
64
  if heartbeat_expired? && @pager.cursor == current_line
60
65
  @repo.content = content
61
66
  @repo.draw
62
- @status.draw
63
67
  @last_line = current_line
64
68
  else
65
69
  @heartbeat = Time.now
@@ -77,6 +81,7 @@ module GitSpelunk
77
81
  def after_navigation
78
82
  @pager.highlight_sha = true
79
83
  @status.exit_command_mode!
84
+ @status.clear_onetime_message!
80
85
  end
81
86
 
82
87
  def handle_key(key)
@@ -109,8 +114,9 @@ module GitSpelunk
109
114
  end
110
115
  after_navigation
111
116
  when '['
117
+ @status.set_onetime_message("Rewinding...")
112
118
  goto = @file_context.get_line_for_sha_parent(@pager.cursor)
113
- if goto
119
+ if goto.is_a?(Fixnum)
114
120
  @file_context.line_number = @pager.cursor
115
121
  @history.push(@file_context)
116
122
 
@@ -119,15 +125,22 @@ module GitSpelunk
119
125
  @pager.go_to(goto)
120
126
 
121
127
  # force commit info update
128
+ @status.clear_onetime_message!
129
+ set_status_message
122
130
  @last_line = nil
131
+ elsif goto == :at_beginning_of_time
132
+ @status.set_onetime_message("At beginning of repository history!")
133
+ elsif goto == :unable_to_trace
134
+ @status.set_onetime_message("Unable to trace lineage of file line")
123
135
  end
124
136
  when ']'
125
137
  if @history.last
126
138
  @file_context = @history.pop
127
139
  @pager.data = @file_context.get_blame
128
140
  @pager.go_to(@file_context.line_number)
129
- @pager.draw
130
- @status.draw
141
+
142
+ @status.clear_onetime_message!
143
+ set_status_message
131
144
 
132
145
  # force commit info update
133
146
  @last_line = nil
@@ -138,7 +151,6 @@ module GitSpelunk
138
151
  Curses.close_screen
139
152
  system("git -p --git-dir='#{@file_context.repo.path}' show #{sha} | less")
140
153
  Curses.stdscr.refresh
141
- [@pager, @repo, @status].each(&:draw)
142
154
  when '/', '?'
143
155
  @heartbeat = nil
144
156
  @status.command_buffer = key
data/lib/git_spelunk.rb CHANGED
@@ -2,3 +2,5 @@ require 'debugger'
2
2
  require 'git_spelunk/ui'
3
3
  require 'git_spelunk/file_context'
4
4
  require 'git_spelunk/offset'
5
+ require 'git_spelunk/grit_patches'
6
+
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_spelunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ben Osheroff
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-11-19 00:00:00.000000000 Z
12
+ date: 2013-12-12 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: grit
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ! '>='
29
26
  - !ruby/object:Gem::Version
@@ -40,6 +37,7 @@ extra_rdoc_files: []
40
37
  files:
41
38
  - lib/git_spelunk/file.rb
42
39
  - lib/git_spelunk/file_context.rb
40
+ - lib/git_spelunk/grit_patches.rb
43
41
  - lib/git_spelunk/offset.rb
44
42
  - lib/git_spelunk/ui/pager.rb
45
43
  - lib/git_spelunk/ui/repo.rb
@@ -50,27 +48,25 @@ files:
50
48
  - bin/git-spelunk
51
49
  homepage: https://github.com/osheroff/git-spelunk
52
50
  licenses: []
51
+ metadata: {}
53
52
  post_install_message:
54
53
  rdoc_options: []
55
54
  require_paths:
56
55
  - lib
57
56
  required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
57
  requirements:
60
58
  - - ! '>='
61
59
  - !ruby/object:Gem::Version
62
60
  version: '0'
63
61
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
62
  requirements:
66
63
  - - ! '>='
67
64
  - !ruby/object:Gem::Version
68
65
  version: 1.3.6
69
66
  requirements: []
70
67
  rubyforge_project:
71
- rubygems_version: 1.8.25
68
+ rubygems_version: 2.1.11
72
69
  signing_key:
73
- specification_version: 3
70
+ specification_version: 4
74
71
  summary: A git tool for exploring history and blame
75
72
  test_files: []
76
- has_rdoc: