git_spelunk 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,7 +49,7 @@ module GitSpelunk
49
49
  def diff_chunks(diffs)
50
50
  return nil if diffs.empty?
51
51
  # split it into chunks: [["@@ -10,13 +10,18 @@", diffs], ["@@ -20,13 +20,18 @@", diffs, diff]]
52
- multiple_chunks = diffs[0].diff.split(/(@@.*?@@.*?\n)/)
52
+ multiple_chunks = diffs[0].diff.split(/(@@ \-\d+,\d+ \+\d+,\d+ @@.*?\n)/)
53
53
  # Discard file name line
54
54
  multiple_chunks[1..multiple_chunks.length].each_slice(2).to_a
55
55
  end
@@ -57,25 +57,34 @@ module GitSpelunk
57
57
 
58
58
  attr_accessor :top
59
59
 
60
- def search(term, skip_current_line)
61
- @search_term = term
62
- return unless term
63
- save_cursor = @cursor
64
- search_data = data.map { |d| d[1] }
65
- initial_position = save_cursor - (skip_current_line ? 0 : 1)
66
- search_data[initial_position..-1].each_with_index do |d, i|
67
- if d =~ /#{term}/
68
- go_to(initial_position + i + 1)
69
- return
60
+ #returns position in data set, not cursor position
61
+ def find_next_index(term, start, reverse)
62
+ i = start
63
+ while i < data.size && i >= 0
64
+ if data[i][1] =~ /#{term}/
65
+ return i
70
66
  end
67
+ i += reverse ? -1 : 1
71
68
  end
69
+ nil
70
+ end
72
71
 
73
- search_data[0..initial_position].each_with_index do |d, i|
74
- if d =~ /#{term}/
75
- go_to(i + 1)
76
- return
77
- end
72
+ def search(term, skip_current_line, reverse)
73
+ if term
74
+ @search_term = term
75
+ else
76
+ term = @search_term # nil indicates 'use-last-term'
77
+ end
78
+
79
+ search_from = @cursor - 1
80
+ if skip_current_line
81
+ search_from += reverse ? -1 : 1
78
82
  end
83
+
84
+ p = find_next_index(term, search_from, reverse) ||
85
+ find_next_index(term, reverse ? data.size - 1 : 0, reverse)
86
+
87
+ go_to(p + 1) if p
79
88
  end
80
89
 
81
90
  def bufbottom
@@ -121,6 +130,12 @@ module GitSpelunk
121
130
  end
122
131
 
123
132
  def go_to(l)
133
+ if l > @data.size
134
+ l = @data.size
135
+ elsif l < 1
136
+ l = 1
137
+ end
138
+
124
139
  previous_offset = @cursor - @top
125
140
  @cursor = l
126
141
  @top = @cursor - previous_offset
@@ -139,19 +139,21 @@ module GitSpelunk
139
139
  system("git -p --git-dir='#{@file_context.repo.path}' show #{sha} | less")
140
140
  Curses.stdscr.refresh
141
141
  [@pager, @repo, @status].each(&:draw)
142
- when '/'
142
+ when '/', '?'
143
143
  @heartbeat = nil
144
- @status.command_buffer = '/'
144
+ @status.command_buffer = key
145
145
  @status.draw
146
146
 
147
147
  line = getline
148
148
  if line
149
- @search_string = line
150
- @pager.search(@search_string, false)
149
+ @pager.search(line, false, key == '?')
151
150
  end
152
151
  @status.exit_command_mode!
153
152
  when 'n'
154
- @pager.search(@search_string, true)
153
+ @pager.search(nil, true, false)
154
+ after_navigation
155
+ when 'N'
156
+ @pager.search(nil, true, true)
155
157
  after_navigation
156
158
  when 'q'
157
159
  exit
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.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-15 00:00:00.000000000 Z
13
+ date: 2013-11-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: grit
@@ -28,7 +28,8 @@ dependencies:
28
28
  - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
- description: ''
31
+ description: git-spelunk is a terminal based exploration tool for git blame and history,
32
+ based on the notion of moving in history based on file context
32
33
  email:
33
34
  - ben@zendesk.com
34
35
  - saroj@zendesk.com
@@ -47,7 +48,7 @@ files:
47
48
  - lib/git_spelunk/ui.rb
48
49
  - lib/git_spelunk.rb
49
50
  - bin/git-spelunk
50
- homepage: ''
51
+ homepage: https://github.com/osheroff/git-spelunk
51
52
  licenses: []
52
53
  post_install_message:
53
54
  rdoc_options: []
@@ -70,6 +71,6 @@ rubyforge_project:
70
71
  rubygems_version: 1.8.25
71
72
  signing_key:
72
73
  specification_version: 3
73
- summary: ''
74
+ summary: A git tool for exploring history and blame
74
75
  test_files: []
75
76
  has_rdoc: