gitlab_git 7.0.0.rc11 → 7.0.0.rc12

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/gitlab_git/repository.rb +54 -4
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01d35bccb72fd1412692b9c65341610f78616595
4
- data.tar.gz: 636bf49e47997552e56cd1af4858632621701283
3
+ metadata.gz: 44a52af0f3a9985bae1ccd85e7cb074682d8b691
4
+ data.tar.gz: 26e8ffbe31ae2baa9880ba82c568baed3188dd98
5
5
  SHA512:
6
- metadata.gz: 5a03878e04c0906780ea36d4852f1e030388c60862ffbbcef6395a8e66f41f0e534be34d8f0079aa938aadbcff909d5d4df50593d8603aad11b70d0d514dc8f7
7
- data.tar.gz: 2636e356c09f723637d585236c58fb50c52e154482a9aebf1d725d397e755fc4a63fbb8aed92d33205c322949f3ca2bf33f61fbc250c0abd6113643f89a304e4
6
+ metadata.gz: 04c93841365a6bf23042e5e495189c6dd134047cf54219dcf7cc4aa72b1936da99f2b63cebbbbdb2041005f1a25815d3bf53ecae66660a942e3ea55efdb2e57e
7
+ data.tar.gz: 794f208951447ba3a5cb71a0908b94e4786a6149f19a31b70072ca65cdb43f4770ab1387769df4374761b89a786c1d1370139faa3c895b23f61103f0d7b0400c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0.rc11
1
+ 7.0.0.rc12
@@ -8,6 +8,8 @@ module Gitlab
8
8
  class Repository
9
9
  include Gitlab::Git::Popen
10
10
 
11
+ SEARCH_CONTEXT_LINES = 3
12
+
11
13
  class NoRepository < StandardError; end
12
14
 
13
15
  # Default branch in the repository
@@ -920,15 +922,63 @@ module Gitlab
920
922
  # Return an array of BlobSnippets for lines in +file_contents+ that match
921
923
  # +query+
922
924
  def build_greps(file_contents, query, ref, filename)
925
+ # The file_contents string is potentially huge so we make sure to loop
926
+ # through it one line at a time. This gives Ruby the chance to GC lines
927
+ # we are not interested in.
928
+ #
929
+ # We need to do a little extra work because we are not looking for just
930
+ # the lines that matches the query, but also for the context
931
+ # (surrounding lines). We will use Enumerable#each_cons to efficiently
932
+ # loop through the lines while keeping surrounding lines on hand.
933
+ #
934
+ # First, we turn "foo\nbar\nbaz" into
935
+ # [
936
+ # [nil, -3], [nil, -2], [nil, -1],
937
+ # ['foo', 0], ['bar', 1], ['baz', 3],
938
+ # [nil, 4], [nil, 5], [nil, 6]
939
+ # ]
940
+ lines_with_index = Enumerator.new do |yielder|
941
+ # Yield fake 'before' lines for the first line of file_contents
942
+ (-SEARCH_CONTEXT_LINES..-1).each do |i|
943
+ yielder.yield [nil, i]
944
+ end
945
+
946
+ # Yield the actual file contents
947
+ count = 0
948
+ file_contents.each_line.each_with_index do |line, i|
949
+ line.chomp!
950
+ yielder.yield [line, i]
951
+ count += 1
952
+ end
953
+
954
+ # Yield fake 'after' lines for the last line of file_contents
955
+ (count+1..count+SEARCH_CONTEXT_LINES).each do |i|
956
+ yielder.yield [nil, i]
957
+ end
958
+ end
959
+
923
960
  greps = []
924
961
 
925
- file_contents.split("\n").each_with_index do |line, i|
926
- next unless line.match(/#{Regexp.escape(query)}/i)
962
+ # Loop through consecutive blocks of lines with indexes
963
+ lines_with_index.each_cons(2 * SEARCH_CONTEXT_LINES + 1) do |line_block|
964
+ # Get the 'middle' line and index from the block
965
+ line, i = line_block[SEARCH_CONTEXT_LINES]
966
+
967
+ next unless line && line.match(/#{Regexp.escape(query)}/i)
968
+
969
+ # Yay, 'line' contains a match!
970
+ # Get an array with just the context lines (no indexes)
971
+ match_with_context = line_block.map(&:first)
972
+ # Remove 'nil' lines in case we are close to the first or last line
973
+ match_with_context.compact!
974
+
975
+ # Get the line number (1-indexed) of the first context line
976
+ first_context_line_number = line_block[0][1] + 1
927
977
 
928
978
  greps << Gitlab::Git::BlobSnippet.new(
929
979
  ref,
930
- file_contents.split("\n")[i - 3..i + 3],
931
- i - 2,
980
+ match_with_context,
981
+ first_context_line_number,
932
982
  filename
933
983
  )
934
984
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.rc11
4
+ version: 7.0.0.rc12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.21.0
47
+ version: 0.21.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.21.0
54
+ version: 0.21.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: charlock_holmes
57
57
  requirement: !ruby/object:Gem::Requirement