Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
6a4a17f3
Commit
6a4a17f3
authored
Apr 15, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove native git calls from MR. Dump diff as array, not class
parent
5f8f685b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
app/models/merge_request.rb
app/models/merge_request.rb
+12
-14
No files found.
app/models/merge_request.rb
View file @
6a4a17f3
...
@@ -24,8 +24,6 @@ require Rails.root.join("lib/static_model")
...
@@ -24,8 +24,6 @@ require Rails.root.join("lib/static_model")
class
MergeRequest
<
ActiveRecord
::
Base
class
MergeRequest
<
ActiveRecord
::
Base
include
Issuable
include
Issuable
BROKEN_DIFF
=
"--broken-diff"
attr_accessible
:title
,
:assignee_id
,
:target_branch
,
:source_branch
,
:milestone_id
,
attr_accessible
:title
,
:assignee_id
,
:target_branch
,
:source_branch
,
:milestone_id
,
:author_id_of_changes
,
:state_event
:author_id_of_changes
,
:state_event
...
@@ -109,22 +107,18 @@ class MergeRequest < ActiveRecord::Base
...
@@ -109,22 +107,18 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diffs
def
diffs
st_diffs
||
[]
load_diffs
(
st_diffs
)
||
[]
end
end
def
reloaded_diffs
def
reloaded_diffs
if
opened?
&&
unmerged_diffs
.
any?
if
opened?
&&
unmerged_diffs
.
any?
self
.
st_diffs
=
unmerged_diffs
self
.
st_diffs
=
dump_diffs
(
unmerged_diffs
)
self
.
save
self
.
save
end
end
rescue
Grit
::
Git
::
GitTimeout
self
.
st_diffs
=
[
BROKEN_DIFF
]
self
.
save
end
end
def
broken_diffs?
def
broken_diffs?
diffs
==
[
BROKEN_DIFF
]
diffs
==
[
Gitlab
::
Git
::
Diff
::
BROKEN_DIFF
]
end
end
def
valid_diffs?
def
valid_diffs?
...
@@ -132,11 +126,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -132,11 +126,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
unmerged_diffs
def
unmerged_diffs
# Only show what is new in the source branch compared to the target branch, not the other way around.
project
.
repository
.
diffs_between
(
source_branch
,
target_branch
)
# The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit
=
project
.
repo
.
git
.
native
(
:merge_base
,
{},
[
target_branch
,
source_branch
]).
strip
diffs
=
project
.
repo
.
diff
(
common_commit
,
source_branch
)
end
end
def
last_commit
def
last_commit
...
@@ -222,4 +212,12 @@ class MergeRequest < ActiveRecord::Base
...
@@ -222,4 +212,12 @@ class MergeRequest < ActiveRecord::Base
def
load_commits
(
array
)
def
load_commits
(
array
)
array
.
map
{
|
hash
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
hash
))
}
array
.
map
{
|
hash
|
Commit
.
new
(
Gitlab
::
Git
::
Commit
.
new
(
hash
))
}
end
end
def
dump_diffs
(
diffs
)
diffs
.
map
(
&
:to_hash
)
end
def
load_diffs
(
array
)
array
.
map
{
|
hash
|
Gitlab
::
Git
::
Diff
.
new
(
hash
)
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment