gitlab-grit 2.6.4 → 2.6.5

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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/VERSION +1 -1
  4. data/lib/grit/git.rb +0 -59
  5. data/lib/grit/repo.rb +100 -51
  6. metadata +23 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8611933f8aa9a6d1f66c3037d40ee93001e1d764
4
- data.tar.gz: 3f52e9f42157e9a033ed17689eb747641d524c10
3
+ metadata.gz: 64a8b118ad835c82733051f1f950afa9f107e08b
4
+ data.tar.gz: b51dcfd5613c248cdb9c2654bb870da5c6a80204
5
5
  SHA512:
6
- metadata.gz: 3aae41c2e4e0f66f0338222f1849580446b4648b4a5b630b72fa100aea1cd67c6fb72f837c7efa3a5767ef92063260ebb6cb1bdbe8e063a710f4a0aa7a4458bb
7
- data.tar.gz: 40cb71314bc6c1e8d7a299f9c3fc4059dd3f924d25de13e602ceac5a91cb18029017e2c16fc0dafc639a1acfff5cfa833eea82889d52c908a48fab60d93545ec
6
+ metadata.gz: 359e1450304d9f783b54246186c5bd33dc4a44d52212c5b4785d87875336b537e0b802955e945658e279e962b48e9121effec1abf222bf0e31d185607d953409
7
+ data.tar.gz: bd37bca63d26b93bf2d33d32888db73b9c919b7888deacb6fb0053b835963b5742056f9f02922df313e84046c840e9b9de47a2a9163dba5951bf22d59e7caa2b
data/README.md CHANGED
@@ -11,6 +11,21 @@
11
11
  * [![Coverage Status](https://coveralls.io/repos/gitlabhq/grit/badge.png?branch=master)](https://coveralls.io/r/gitlabhq/grit)
12
12
 
13
13
 
14
+ ## Fork changes
15
+
16
+ We patched existing grit library to use it inside GitLab
17
+
18
+ * Added grep method to look for files
19
+ * Fixed commits parsing for signed commits
20
+ * Encoding fixes
21
+ * Cleanup and improve code style
22
+ * Handle filenames with spaces
23
+ * Fixes symlinks omission from diff
24
+ * Added Gemfile
25
+ * and much more small fixes
26
+
27
+
28
+ ## Grit
14
29
 
15
30
  Grit gives you object oriented read/write access to Git repositories via Ruby.
16
31
  The main goals are stability and performance. To this end, some of the
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.6.4
1
+ 2.6.5
data/lib/grit/git.rb CHANGED
@@ -315,13 +315,6 @@ module Grit
315
315
  env = options.delete(:env) || {}
316
316
  raise_errors = options.delete(:raise)
317
317
  process_info = options.delete(:process_info)
318
- pipeline = options.delete(:pipeline)
319
-
320
- # fall back to using a shell when the last argument looks like it wants to
321
- # start a pipeline for compatibility with previous versions of grit.
322
- if args[-1].to_s[0] == ?| && pipeline
323
- return run(prefix, cmd, '', options, args)
324
- end
325
318
 
326
319
  # more options
327
320
  input = options.delete(:input)
@@ -416,58 +409,6 @@ module Grit
416
409
  end
417
410
  end
418
411
 
419
- # DEPRECATED OPEN3-BASED COMMAND EXECUTION
420
- # Used only for pipeline support.
421
- # Ex.
422
- # git log | grep bugfix
423
- #
424
- def run(prefix, cmd, postfix, options, args, &block)
425
- timeout = options.delete(:timeout) rescue nil
426
- timeout = true if timeout.nil?
427
-
428
- base = options.delete(:base) rescue nil
429
- base = true if base.nil?
430
-
431
- if input = options.delete(:input)
432
- block = lambda { |stdin| stdin.write(input) }
433
- end
434
-
435
- opt_args = transform_options(options)
436
-
437
- if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/
438
- ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "\"#{e(a)}\"" }
439
- gitdir = base ? "--git-dir=\"#{self.git_dir}\"" : ""
440
- call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
441
- else
442
- ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|' || Grit.no_quote) ? a : "'#{e(a)}'" }
443
- gitdir = base ? "--git-dir='#{self.git_dir}'" : ""
444
- call = "#{prefix}#{Git.git_binary} #{gitdir} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
445
- end
446
-
447
- Grit.log(call) if Grit.debug
448
- response, err = timeout ? sh(call, &block) : wild_sh(call, &block)
449
- Grit.log(response) if Grit.debug
450
- Grit.log(err) if Grit.debug
451
- response
452
- end
453
-
454
- def sh(command, &block)
455
- process =
456
- Child.new(
457
- command,
458
- :timeout => Git.git_timeout,
459
- :max => Git.git_max_size
460
- )
461
- [process.out, process.err]
462
- rescue TimeoutExceeded, MaximumOutputExceeded
463
- raise GitTimeout, command
464
- end
465
-
466
- def wild_sh(command, &block)
467
- process = Child.new(command)
468
- [process.out, process.err]
469
- end
470
-
471
412
  # Transform Ruby style options into git command line options
472
413
  # +options+ is a hash of Ruby style options
473
414
  #
data/lib/grit/repo.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Grit
2
2
  class Repo
3
+ include POSIX::Spawn
4
+
3
5
  DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
4
6
  BATCH_PARSERS = {
5
7
  'commit' => ::Grit::Commit
@@ -581,63 +583,29 @@ module Grit
581
583
  Commit.diff(self, commit)
582
584
  end
583
585
 
584
- # Archive the given treeish
585
- # +treeish+ is the treeish name/id (default 'master')
586
- # +prefix+ is the optional prefix
587
- #
588
- # Examples
589
- # repo.archive_tar
590
- # # => <String containing tar archive>
591
- #
592
- # repo.archive_tar('a87ff14')
593
- # # => <String containing tar archive for commit a87ff14>
594
- #
595
- # repo.archive_tar('master', 'myproject/')
596
- # # => <String containing tar archive and prefixed with 'myproject/'>
597
- #
598
- # Returns String (containing tar archive)
599
- def archive_tar(treeish = 'master', prefix = nil)
600
- options = {}
601
- options[:prefix] = prefix if prefix
602
- self.git.archive(options, treeish)
603
- end
604
-
605
- # Archive and gzip the given treeish
606
- # +treeish+ is the treeish name/id (default 'master')
607
- # +prefix+ is the optional prefix
608
- #
609
- # Examples
610
- # repo.archive_tar_gz
611
- # # => <String containing tar.gz archive>
612
- #
613
- # repo.archive_tar_gz('a87ff14')
614
- # # => <String containing tar.gz archive for commit a87ff14>
615
- #
616
- # repo.archive_tar_gz('master', 'myproject/')
617
- # # => <String containing tar.gz archive and prefixed with 'myproject/'>
618
- #
619
- # Returns String (containing tar.gz archive)
620
- def archive_tar_gz(treeish = 'master', prefix = nil)
621
- options = {}
622
- options[:prefix] = prefix if prefix
623
- options[:pipeline] = true
624
- self.git.archive(options, treeish, "| gzip -n")
625
- end
626
-
627
586
  # Write an archive directly to a file
628
587
  # +treeish+ is the treeish name/id (default 'master')
629
588
  # +prefix+ is the optional prefix (default nil)
630
589
  # +filename+ is the name of the file (default 'archive.tar.gz')
631
590
  # +format+ is the optional format (default nil)
632
- # +pipe+ is the command to run the output through (default 'gzip')
591
+ # +compress_cmd+ is the command to run the output through (default ['gzip'])
633
592
  #
634
593
  # Returns nothing
635
- def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, pipe = "gzip")
636
- options = {}
637
- options[:prefix] = prefix if prefix
638
- options[:format] = format if format
639
- options[:pipeline] = true
640
- self.git.archive(options, treeish, "| #{pipe} > #{filename}")
594
+ def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, compress_cmd = %W(gzip))
595
+ git_archive_cmd = %W(#{Git.git_binary} --git-dir=#{self.git.git_dir} archive)
596
+ git_archive_cmd << "--prefix=#{prefix}" if prefix
597
+ git_archive_cmd << "--format=#{format}" if format
598
+ git_archive_cmd += %W(-- #{treeish})
599
+
600
+ open(filename, 'w') do |file|
601
+ pipe_rd, pipe_wr = IO.pipe
602
+ git_archive_pid = spawn(*git_archive_cmd, :out => pipe_wr)
603
+ compress_pid = spawn(*compress_cmd, :in => pipe_rd, :out => file)
604
+ pipe_rd.close
605
+ pipe_wr.close
606
+ Process.waitpid(git_archive_pid)
607
+ Process.waitpid(compress_pid)
608
+ end
641
609
  end
642
610
 
643
611
  # Enable git-daemon serving of this repository by writing the
@@ -716,7 +684,7 @@ module Grit
716
684
 
717
685
  def grep(searchtext, contextlines = 3, branch = 'master')
718
686
  context_arg = '-C ' + contextlines.to_s
719
- result = git.native(:grep, {pipeline: false}, '-n', '-E', '-i', '-z', '--heading', '--break', context_arg, searchtext, branch).encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
687
+ result = git.native(:grep, {}, '-n', '-E', '-i', '-z', '--heading', '--break', context_arg, searchtext, branch).encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
720
688
  greps = []
721
689
  filematches = result.split("\n\n")
722
690
  filematches.each do |filematch|
@@ -752,6 +720,87 @@ module Grit
752
720
  greps
753
721
  end
754
722
 
723
+ def final_escape(str)
724
+ str.gsub('"', '\\"')
725
+ end
726
+
727
+ # Accepts quoted strings and negation (-) operator in search strings
728
+ def advanced_grep(searchtext, contextlines = 3, branch = 'master')
729
+
730
+ # If there's not an even number of quote marks, get rid of them all
731
+ searchtext = searchtext.gsub('"', '') if searchtext.count('"') % 2 == 1
732
+
733
+ # Escape the text, but allow spaces and quote marks (by unescaping them)
734
+ searchtext = Shellwords.shellescape(searchtext).gsub('\ ',' ').gsub('\\"','"')
735
+
736
+ # Shellwords happens to parse search terms really nicely!
737
+ terms = Shellwords.split(searchtext)
738
+
739
+ term_args = []
740
+ negative_args = []
741
+
742
+ # For each search term (either a word or a quoted string), add the relevant term argument to either the term
743
+ # args array, or the negative args array, used for two separate calls to git grep
744
+ terms.each do |term|
745
+ arg_array = term_args
746
+ if term[0] == '-'
747
+ arg_array = negative_args
748
+ term = term[1..-1]
749
+ end
750
+ arg_array.push '-e'
751
+ arg_array.push final_escape(term)
752
+ end
753
+
754
+ context_arg = '-C ' + contextlines.to_s
755
+ result = git.native(:grep, {pipeline: false}, '-n', '-F', '-i', '-z', '--heading', '--break', '--all-match', context_arg, *term_args, branch).encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
756
+
757
+ # Find files that match the negated terms; these will be excluded from the results
758
+ excluded_files = Array.new
759
+ unless negative_args.empty?
760
+ negative = git.native(:grep, {pipeline: false}, '-F', '-i', '--files-with-matches', *negative_args, branch).encode('UTF-8', invalid: :replace, undef: :replace, replace: '')
761
+ excluded_files = negative.split("\n").map {|text| text.partition(':')[2]}
762
+ end
763
+
764
+ greps = []
765
+ filematches = result.split("\n\n")
766
+ filematches.each do |filematch|
767
+ binary = false
768
+ file = ''
769
+ matches = filematch.split("--\n")
770
+ matches.each_with_index do |match, i|
771
+ content = []
772
+ startline = 0
773
+ lines = match.split("\n")
774
+ if i == 0
775
+ text = lines.first
776
+ lines.slice!(0)
777
+ file = text[/^Binary file (.+) matches$/]
778
+ if file
779
+ puts "BINARY #{file}"
780
+ binary = true
781
+ else
782
+ text.slice! /^#{branch}:/
783
+ file = text
784
+ end
785
+ end
786
+
787
+ # Skip this result if the file is to be ignored (due to a negative match)
788
+ next if excluded_files.include? file || ( excluded_files.include? text[/^Binary file (.+) matches$/, 1].partition(':')[2] )
789
+
790
+ lines.each_with_index do |line, j|
791
+ line.chomp!
792
+ number, text = line.split("\0", 2)
793
+ if j == 0
794
+ startline = number.to_i
795
+ end
796
+ content << text
797
+ end
798
+ greps << Grit::Grep.new(self, file, startline, content, binary)
799
+ end
800
+ end
801
+ greps
802
+ end
803
+
755
804
  # Pretty object inspection
756
805
  def inspect
757
806
  %Q{#<Grit::Repo "#{@path}">}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-grit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -10,76 +10,76 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-05 00:00:00.000000000 Z
13
+ date: 2014-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: charlock_holmes
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 0.6.9
21
+ version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 0.6.9
28
+ version: '0.6'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: posix-spawn
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 0.3.6
35
+ version: '0.3'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 0.3.6
42
+ version: '0.3'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: mime-types
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ~>
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '1.15'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ~>
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.15'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: diff-lcs
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: '1.1'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ~>
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
70
  version: '1.1'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: mocha
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  description: Grit is a Ruby library for extracting information from a git repository
@@ -91,6 +91,9 @@ extra_rdoc_files:
91
91
  - README.md
92
92
  - LICENSE
93
93
  files:
94
+ - LICENSE
95
+ - README.md
96
+ - VERSION
94
97
  - lib/grit.rb
95
98
  - lib/grit/actor.rb
96
99
  - lib/grit/blame.rb
@@ -128,31 +131,28 @@ files:
128
131
  - lib/grit_ext/tag.rb
129
132
  - lib/grit_ext/tree.rb
130
133
  - lib/grit_ext/version.rb
131
- - VERSION
132
- - README.md
133
- - LICENSE
134
134
  homepage: http://github.com/gitlabhq/grit
135
135
  licenses:
136
136
  - MIT
137
137
  metadata: {}
138
138
  post_install_message:
139
139
  rdoc_options:
140
- - --charset=UTF-8
140
+ - "--charset=UTF-8"
141
141
  require_paths:
142
142
  - lib
143
143
  required_ruby_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  requirements: []
154
154
  rubyforge_project:
155
- rubygems_version: 2.1.11
155
+ rubygems_version: 2.2.2
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Ruby Git bindings.