gitlab_git 7.0.0.rc8 → 7.0.0.rc9

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 +67 -28
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73f18b742e441f8974c658139ba8e543bfea6f46
4
- data.tar.gz: 35e4be4dc66c78ff87694794deec5f394666e9d3
3
+ metadata.gz: a7ec22b2587950203d9032f5751289974e071e31
4
+ data.tar.gz: fe553f891594bbb3003feb752bebdb6217b28539
5
5
  SHA512:
6
- metadata.gz: 77de354a1a19bf8bb5588946e3d705a97c4f87b2712e610f9dfd5298c7bc72b6ebbaa34a77c36f82a9d090f49215099311121c8c944e5386090fa52702dc81d9
7
- data.tar.gz: f29427c0a612a57cabf3e6988f30fd276778c9c28732563ad0a404450dea2cd5d650f3de81f42a4752ba141903ccbab1070dcf5392eae2f6d0ea10f91cef349b
6
+ metadata.gz: a0f637cfdea87897513107b35aa5166533d6e901ee2b3f8cd27aec7328aa1c4b9d68056ff89e0540aafca89d0d6799042cd9cf26674f71f421f58d49647234fe
7
+ data.tar.gz: 22b05d255f9d5be02aeb6197e04fe1f9e2243fa2c58120ad4bbac5de39f079731c2980716bb0a16d34a1ac81fbac8ef22ee83fbc80a4e6d2489d2b4a86dba46e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0.rc8
1
+ 7.0.0.rc9
@@ -361,13 +361,15 @@ module Gitlab
361
361
  # repo.branch_names_contains('master')
362
362
  #
363
363
  def branches_contains(commit)
364
- sha = rugged.rev_parse_oid(commit)
364
+ commit_obj = rugged.rev_parse(commit)
365
+ parent = commit_obj.parents.first unless commit_obj.parents.empty?
365
366
 
366
367
  walker = Rugged::Walker.new(rugged)
367
368
 
368
369
  rugged.branches.select do |branch|
369
370
  walker.push(branch.target_id)
370
- result = walker.any? { |c| c.oid == sha }
371
+ walker.hide(parent) if parent
372
+ result = walker.any? { |c| c.oid == commit_obj.oid }
371
373
  walker.reset
372
374
 
373
375
  result
@@ -794,43 +796,80 @@ module Gitlab
794
796
  # +follow+ option is true and the file specified by +path+ was renamed,
795
797
  # then the path value is set to the old path.
796
798
  def commit_touches_path?(commit, path, follow)
797
- if commit.parents.empty?
798
- diff = commit.diff
799
+ if follow
800
+ touches_path_diff?(commit, path)
799
801
  else
800
- diff = commit.parents[0].diff(commit)
801
- diff.find_similar! if follow
802
+ touches_path_tree?(commit, path)
802
803
  end
804
+ end
803
805
 
804
- # Check the commit's deltas to see if it touches the :path
805
- # argument
806
- diff.each_delta do |d|
807
- if path_matches?(path, d.old_file[:path], d.new_file[:path])
808
- if should_follow?(follow, d, path)
809
- # Look for the old path in ancestors
810
- path.replace(d.old_file[:path])
811
- end
806
+ # Returns true if +commit+ introduced changes to +path+, using commit
807
+ # trees to make that determination.
808
+ def touches_path_tree?(commit, path)
809
+ parent = commit.parents[0]
810
+ entry = tree_entry(commit, path)
812
811
 
813
- return true
814
- end
812
+ if parent.nil?
813
+ # This is the root commit, return true if it has +path+ in its tree
814
+ return entry != nil
815
815
  end
816
816
 
817
- false
817
+ parent_entry = tree_entry(parent, path)
818
+
819
+ if entry.nil? && parent_entry.nil?
820
+ false
821
+ elsif entry.nil? || parent_entry.nil?
822
+ true
823
+ else
824
+ entry[:oid] != parent_entry[:oid]
825
+ end
818
826
  end
819
827
 
820
- # Used by the #commit_touches_path method to determine whether the
821
- # specified file has been renamed and should be followed in ancestor
822
- # commits. Returns true if +follow_option+ is true, the file is renamed
823
- # in this commit, and the new file's path matches the path option.
824
- def should_follow?(follow_option, delta, path)
825
- follow_option && delta.renamed? && path == delta.new_file[:path]
828
+ # Find the entry for +path+ in the tree for +commit+
829
+ def tree_entry(commit, path)
830
+ pathname = Pathname.new(path)
831
+ tmp_entry = nil
832
+
833
+ pathname.each_filename do |dir|
834
+ if tmp_entry.nil?
835
+ tmp_entry = commit.tree[dir]
836
+ else
837
+ tmp_entry = rugged.lookup(tmp_entry[:oid])[dir]
838
+ end
839
+ end
840
+
841
+ tmp_entry
826
842
  end
827
843
 
828
- # Returns true if any of the strings in +*paths+ begins with the
829
- # +path_to_match+ argument
830
- def path_matches?(path_to_match, *paths)
831
- paths.any? do |p|
832
- p.match(/^#{Regexp.escape(path_to_match)}/)
844
+ # Returns true if +commit+ introduced changes to +path+, using
845
+ # Rugged::Diff objects to make that determination. This is slower than
846
+ # comparing commit trees, but lets us use Rugged::Diff#find_similar to
847
+ # detect file renames.
848
+ def touches_path_diff?(commit, path)
849
+ diff = commit.diff(reverse: true, paths: [path],
850
+ disable_pathspec_match: true)
851
+
852
+ return false if diff.deltas.empty?
853
+
854
+ # If +path+ is a filename, not a directory, then we should only have
855
+ # one delta. We don't need to follow renames for directories.
856
+ return true if diff.deltas.length > 1
857
+
858
+ # Detect renames
859
+ delta = diff.deltas.first
860
+ if delta.added?
861
+ full_diff = commit.diff(reverse: true)
862
+ full_diff.find_similar!
863
+
864
+ full_diff.each_delta do |full_delta|
865
+ if full_delta.renamed? && path == full_delta.new_file[:path]
866
+ # Look for the old path in ancestors
867
+ path.replace(full_delta.old_file[:path])
868
+ end
869
+ end
833
870
  end
871
+
872
+ true
834
873
  end
835
874
 
836
875
  def archive_to_file(treeish = 'master', prefix = nil, filename = 'archive.tar.gz', format = nil, compress_cmd = %W(gzip))
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.rc8
4
+ version: 7.0.0.rc9
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-10-02 00:00:00.000000000 Z
11
+ date: 2014-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist