gitlab_git 7.0.0.rc12 → 7.0.0.rc13

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44a52af0f3a9985bae1ccd85e7cb074682d8b691
4
- data.tar.gz: 26e8ffbe31ae2baa9880ba82c568baed3188dd98
3
+ metadata.gz: f86d9c6e73cb52a8f31d29324a44392a2553ba05
4
+ data.tar.gz: 0576273f835e885e8959be448057bc4021b443ee
5
5
  SHA512:
6
- metadata.gz: 04c93841365a6bf23042e5e495189c6dd134047cf54219dcf7cc4aa72b1936da99f2b63cebbbbdb2041005f1a25815d3bf53ecae66660a942e3ea55efdb2e57e
7
- data.tar.gz: 794f208951447ba3a5cb71a0908b94e4786a6149f19a31b70072ca65cdb43f4770ab1387769df4374761b89a786c1d1370139faa3c895b23f61103f0d7b0400c
6
+ metadata.gz: 94e6049f197b94027436e028c9d19f835a06146e3020c6c3cf537cd13cb458322324af04ae38a11fd5f3d77bf880f494de3028600f2bfd6ec6f4eb4c8ec70848
7
+ data.tar.gz: 6b01cb8f1debacf1b7df04d45a801325ba23d967f5f80c8b3e3a0615e25ca3031c155697829fd71add957b7963dac0199067490213a12bdd0c50b2042960eef9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0.rc12
1
+ 7.0.0.rc13
@@ -108,6 +108,25 @@ module Gitlab
108
108
  def decorate(commit, ref = nil)
109
109
  Gitlab::Git::Commit.new(commit, ref)
110
110
  end
111
+
112
+ # Returns a diff object for the changes introduced by +rugged_commit+.
113
+ # If +rugged_commit+ doesn't have a parent, then the diff is between
114
+ # this commit and an empty repo. See Repository#diff for the keys
115
+ # allowed in the +options+ hash.
116
+ def diff_from_parent(rugged_commit, options = {})
117
+ options ||= {}
118
+ break_rewrites = options[:break_rewrites]
119
+ actual_options = Diff.filter_diff_options(options)
120
+
121
+ if rugged_commit.parents.empty?
122
+ diff = rugged_commit.diff(actual_options.merge(reverse: true))
123
+ else
124
+ diff = rugged_commit.parents[0].diff(rugged_commit, actual_options)
125
+ end
126
+
127
+ diff.find_similar!(break_rewrites: break_rewrites)
128
+ diff
129
+ end
111
130
  end
112
131
 
113
132
  def initialize(raw_commit, head = nil)
@@ -152,8 +171,8 @@ module Gitlab
152
171
  # Shows the diff between the commit's parent and the commit.
153
172
  #
154
173
  # Cuts out the header and stats from #to_patch and returns only the diff.
155
- def to_diff
156
- patch = to_patch
174
+ def to_diff(options = {})
175
+ patch = to_patch(options)
157
176
 
158
177
  # discard lines before the diff
159
178
  lines = patch.split("\n")
@@ -167,13 +186,10 @@ module Gitlab
167
186
 
168
187
  # Returns a diff object for the changes from this commit's first parent.
169
188
  # If there is no parent, then the diff is between this commit and an
170
- # empty repo.
171
- def diff_from_parent
172
- if raw_commit.parents.empty?
173
- raw_commit.diff(reverse: true)
174
- else
175
- raw_commit.parents[0].diff(raw_commit)
176
- end
189
+ # empty repo. See Repository#diff for keys allowed in the +options+
190
+ # hash.
191
+ def diff_from_parent(options = {})
192
+ Commit.diff_from_parent(raw_commit, options)
177
193
  end
178
194
 
179
195
  def has_zero_stats?
@@ -196,8 +212,8 @@ module Gitlab
196
212
  committed_date
197
213
  end
198
214
 
199
- def diffs
200
- diff_from_parent.map { |diff| Gitlab::Git::Diff.new(diff) }
215
+ def diffs(options = {})
216
+ diff_from_parent(options).map { |diff| Gitlab::Git::Diff.new(diff) }
201
217
  end
202
218
 
203
219
  def parents
@@ -212,8 +228,8 @@ module Gitlab
212
228
  Gitlab::Git::CommitStats.new(self)
213
229
  end
214
230
 
215
- def to_patch
216
- raw_commit.to_mbox
231
+ def to_patch(options = {})
232
+ raw_commit.to_mbox(options)
217
233
  end
218
234
 
219
235
  # Get a collection of Rugged::Reference objects for this commit.
@@ -24,7 +24,7 @@ module Gitlab
24
24
  @commits = Gitlab::Git::Commit.between(repository, @base.id, @head.id)
25
25
  end
26
26
 
27
- def diffs(paths = nil)
27
+ def diffs(paths = nil, options = {})
28
28
  unless @head && @base
29
29
  return []
30
30
  end
@@ -33,7 +33,8 @@ module Gitlab
33
33
  # Otherwise return cached version
34
34
  if @diffs.empty? && @timeout == false
35
35
  begin
36
- @diffs = Gitlab::Git::Diff.between(@repository, @head.id, @base.id, *paths)
36
+ @diffs = Gitlab::Git::Diff.between(@repository, @head.id, @base.id,
37
+ options, *paths)
37
38
  rescue Gitlab::Git::Diff::TimeoutError => ex
38
39
  @diffs = []
39
40
  @timeout = true
@@ -12,13 +12,146 @@ module Gitlab
12
12
  attr_accessor :new_file, :renamed_file, :deleted_file
13
13
 
14
14
  class << self
15
- def between(repo, head, base, *paths)
15
+ def between(repo, head, base, options = {}, *paths)
16
16
  # Only show what is new in the source branch compared to the target branch, not the other way around.
17
17
  # The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
18
18
  # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
19
19
  common_commit = repo.merge_base_commit(head, base)
20
20
 
21
- repo.diff(common_commit, head, *paths)
21
+ options ||= {}
22
+ break_rewrites = options[:break_rewrites]
23
+ actual_options = filter_diff_options(options)
24
+ repo.diff(common_commit, head, actual_options, *paths)
25
+ end
26
+
27
+ # Return a copy of the +options+ hash containing only keys that can be
28
+ # passed to Rugged. Allowed options are:
29
+ #
30
+ # :max_size ::
31
+ # An integer specifying the maximum byte size of a file before a it
32
+ # will be treated as binary. The default value is 512MB.
33
+ #
34
+ # :context_lines ::
35
+ # The number of unchanged lines that define the boundary of a hunk
36
+ # (and to display before and after the actual changes). The default is
37
+ # 3.
38
+ #
39
+ # :interhunk_lines ::
40
+ # The maximum number of unchanged lines between hunk boundaries before
41
+ # the hunks will be merged into a one. The default is 0.
42
+ #
43
+ # :old_prefix ::
44
+ # The virtual "directory" to prefix to old filenames in hunk headers.
45
+ # The default is "a".
46
+ #
47
+ # :new_prefix ::
48
+ # The virtual "directory" to prefix to new filenames in hunk headers.
49
+ # The default is "b".
50
+ #
51
+ # :reverse ::
52
+ # If true, the sides of the diff will be reversed.
53
+ #
54
+ # :force_text ::
55
+ # If true, all files will be treated as text, disabling binary
56
+ # attributes & detection.
57
+ #
58
+ # :ignore_whitespace ::
59
+ # If true, all whitespace will be ignored.
60
+ #
61
+ # :ignore_whitespace_change ::
62
+ # If true, changes in amount of whitespace will be ignored.
63
+ #
64
+ # :ignore_whitespace_eol ::
65
+ # If true, whitespace at end of line will be ignored.
66
+ #
67
+ # :ignore_submodules ::
68
+ # if true, submodules will be excluded from the diff completely.
69
+ #
70
+ # :patience ::
71
+ # If true, the "patience diff" algorithm will be used (currenlty
72
+ # unimplemented).
73
+ #
74
+ # :include_ignored ::
75
+ # If true, ignored files will be included in the diff.
76
+ #
77
+ # :include_untracked ::
78
+ # If true, untracked files will be included in the diff.
79
+ #
80
+ # :include_unmodified ::
81
+ # If true, unmodified files will be included in the diff.
82
+ #
83
+ # :recurse_untracked_dirs ::
84
+ # Even if +:include_untracked+ is true, untracked directories will
85
+ # only be marked with a single entry in the diff. If this flag is set
86
+ # to true, all files under ignored directories will be included in the
87
+ # diff, too.
88
+ #
89
+ # :disable_pathspec_match ::
90
+ # If true, the given +*paths+ will be applied as exact matches,
91
+ # instead of as fnmatch patterns.
92
+ #
93
+ # :deltas_are_icase ::
94
+ # If true, filename comparisons will be made with case-insensitivity.
95
+ #
96
+ # :include_untracked_content ::
97
+ # if true, untracked content will be contained in the the diff patch
98
+ # text.
99
+ #
100
+ # :skip_binary_check ::
101
+ # If true, diff deltas will be generated without spending time on
102
+ # binary detection. This is useful to improve performance in cases
103
+ # where the actual file content difference is not needed.
104
+ #
105
+ # :include_typechange ::
106
+ # If true, type changes for files will not be interpreted as deletion
107
+ # of the "old file" and addition of the "new file", but will generate
108
+ # typechange records.
109
+ #
110
+ # :include_typechange_trees ::
111
+ # Even if +:include_typechange+ is true, blob -> tree changes will
112
+ # still usually be handled as a deletion of the blob. If this flag is
113
+ # set to true, blob -> tree changes will be marked as typechanges.
114
+ #
115
+ # :ignore_filemode ::
116
+ # If true, file mode changes will be ignored.
117
+ #
118
+ # :recurse_ignored_dirs ::
119
+ # Even if +:include_ignored+ is true, ignored directories will only be
120
+ # marked with a single entry in the diff. If this flag is set to true,
121
+ # all files under ignored directories will be included in the diff,
122
+ # too.
123
+ def filter_diff_options(options, default_options = {})
124
+ allowed_options = [:max_size, :context_lines, :interhunk_lines,
125
+ :old_prefix, :new_prefix, :reverse, :force_text,
126
+ :ignore_whitespace, :ignore_whitespace_change,
127
+ :ignore_whitespace_eol, :ignore_submodules,
128
+ :patience, :include_ignored, :include_untracked,
129
+ :include_unmodified, :recurse_untracked_dirs,
130
+ :disable_pathspec_match, :deltas_are_icase,
131
+ :include_untracked_content, :skip_binary_check,
132
+ :include_typechange, :include_typechange_trees,
133
+ :ignore_filemode, :recurse_ignored_dirs, :paths]
134
+
135
+ if default_options
136
+ actual_defaults = default_options.dup
137
+ actual_defaults.keep_if do |key|
138
+ allowed_options.include?(key)
139
+ end
140
+ else
141
+ actual_defaults = {}
142
+ end
143
+
144
+ if options
145
+ filtered_opts = options.dup
146
+ filtered_opts.keep_if do |key|
147
+ allowed_options.include?(key)
148
+ end
149
+ filtered_opts = actual_defaults.merge(filtered_opts)
150
+ else
151
+ filtered_opts = actual_defaults
152
+ end
153
+
154
+ filtered_opts
22
155
  end
23
156
  end
24
157
 
@@ -11,6 +11,7 @@ module Gitlab
11
11
  SEARCH_CONTEXT_LINES = 3
12
12
 
13
13
  class NoRepository < StandardError; end
14
+ class InvalidBlobName < StandardError; end
14
15
 
15
16
  # Default branch in the repository
16
17
  attr_accessor :root_ref
@@ -265,19 +266,22 @@ module Gitlab
265
266
  end
266
267
 
267
268
  # Return an array of Diff objects that represent the diff
268
- # between +from+ and +to+.
269
- def diff(from, to, *paths)
270
- rugged.diff(from, to, paths: paths).each_patch.map do |p|
269
+ # between +from+ and +to+. See Diff::filter_diff_options for the allowed
270
+ # diff options. The +options+ hash can also include :break_rewrites to
271
+ # split larger rewrites into delete/add pairs.
272
+ def diff(from, to, options = {}, *paths)
273
+ diff_patches(from, to, options, *paths).map do |p|
271
274
  Gitlab::Git::Diff.new(p)
272
275
  end
273
276
  end
274
277
 
275
- # Return the diff between +from+ and +to+ in a single patch string.
276
- def diff_text(from, to, *paths)
278
+ # Return the diff between +from+ and +to+ in a single patch string. The
279
+ # +options+ hash has the same allowed keys as #diff.
280
+ def diff_text(from, to, options = {}, *paths)
277
281
  # NOTE: It would be simpler to use the Rugged::Diff#patch method, but
278
282
  # that formats the diff text differently than Rugged::Patch#to_s for
279
283
  # changes to binary files.
280
- rugged.diff(from, to, paths: paths).each_patch.map do |p|
284
+ diff_patches(from, to, options, *paths).map do |p|
281
285
  p.to_s
282
286
  end.join("\n")
283
287
  end
@@ -416,7 +420,12 @@ module Gitlab
416
420
  def submodules(ref)
417
421
  commit = rugged.rev_parse(ref)
418
422
 
419
- content = blob_content(commit, ".gitmodules")
423
+ begin
424
+ content = blob_content(commit, ".gitmodules")
425
+ rescue InvalidBlobName
426
+ return {}
427
+ end
428
+
420
429
  parse_gitmodules(commit, content)
421
430
  end
422
431
 
@@ -658,13 +667,16 @@ module Gitlab
658
667
  end
659
668
 
660
669
  # Return a String containing the mbox-formatted diff between +from+ and
661
- # +to+
662
- def format_patch(from, to)
663
- rugged.diff(from, to).patch
670
+ # +to+. See #diff for the allowed keys in the +options+ hash.
671
+ def format_patch(from, to, options = {})
672
+ options ||= {}
673
+ break_rewrites = options[:break_rewrites]
674
+ actual_options = Diff.filter_diff_options(options)
675
+
664
676
  from_sha = rugged.rev_parse_oid(from)
665
677
  to_sha = rugged.rev_parse_oid(to)
666
678
  commits_between(from_sha, to_sha).map do |commit|
667
- commit.to_mbox
679
+ commit.to_mbox(actual_options)
668
680
  end.join("\n")
669
681
  end
670
682
 
@@ -724,6 +736,10 @@ module Gitlab
724
736
  def blob_content(commit, blob_name)
725
737
  blob_entry = tree_entry(commit, blob_name)
726
738
 
739
+ unless blob_entry
740
+ raise InvalidBlobName.new("Invalid blob name: #{blob_name}")
741
+ end
742
+
727
743
  if blob_entry[:type] == :commit
728
744
  blob_entry[:oid]
729
745
  else
@@ -742,11 +758,16 @@ module Gitlab
742
758
  current = txt.match(/(?<=").*(?=")/)[0]
743
759
  results[current] = {}
744
760
  else
761
+ next unless results[current]
745
762
  match_data = txt.match(/(\w+)\s*=\s*(.*)/)
746
763
  results[current][match_data[1]] = match_data[2]
747
764
 
748
765
  if match_data[1] == "path"
749
- results[current]["id"] = blob_content(commit, match_data[2])
766
+ begin
767
+ results[current]["id"] = blob_content(commit, match_data[2])
768
+ rescue InvalidBlobName
769
+ results.delete(current)
770
+ end
750
771
  end
751
772
  end
752
773
  end
@@ -985,6 +1006,17 @@ module Gitlab
985
1006
 
986
1007
  greps
987
1008
  end
1009
+
1010
+ # Return the Rugged patches for the diff between +from+ and +to+.
1011
+ def diff_patches(from, to, options = {}, *paths)
1012
+ options ||= {}
1013
+ break_rewrites = options[:break_rewrites]
1014
+ actual_options = Diff.filter_diff_options(options.merge(paths: paths))
1015
+
1016
+ diff = rugged.diff(from, to, actual_options)
1017
+ diff.find_similar!(break_rewrites: break_rewrites)
1018
+ diff.each_patch
1019
+ end
988
1020
  end
989
1021
  end
990
1022
  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.rc12
4
+ version: 7.0.0.rc13
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-18 00:00:00.000000000 Z
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist