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
iv
gitlab-ce
Commits
81a21e57
Commit
81a21e57
authored
Apr 23, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CommitRange improvements
parent
6bac823a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
16 deletions
+13
-16
app/models/commit_range.rb
app/models/commit_range.rb
+11
-14
spec/models/commit_range_spec.rb
spec/models/commit_range_spec.rb
+2
-2
No files found.
app/models/commit_range.rb
View file @
81a21e57
...
@@ -45,12 +45,10 @@ class CommitRange
...
@@ -45,12 +45,10 @@ class CommitRange
raise
ArgumentError
,
"invalid CommitRange string format:
#{
range_string
}
"
raise
ArgumentError
,
"invalid CommitRange string format:
#{
range_string
}
"
end
end
@inclusive
=
range_string
!~
/\.{3}/
@inclusive
=
!
range_string
.
include?
(
'...'
)
@sha_from
,
@notation
,
@sha_to
=
range_string
.
split
(
/(\.{2,3})/
,
2
)
@sha_from
,
@notation
,
@sha_to
=
range_string
.
split
(
/(\.{2,3})/
,
2
)
@project
=
project
@project
=
project
@_commit_map
=
{}
end
end
def
inspect
def
inspect
...
@@ -63,7 +61,7 @@ class CommitRange
...
@@ -63,7 +61,7 @@ class CommitRange
# Returns `[nil, nil]` if `valid_commits?` is falsey
# Returns `[nil, nil]` if `valid_commits?` is falsey
def
to_a
def
to_a
if
valid_commits?
if
valid_commits?
[
commit
(
sha_from
),
commit
(
sha_to
)
]
[
commit
_from
,
commit_to
]
else
else
[
nil
,
nil
]
[
nil
,
nil
]
end
end
...
@@ -104,25 +102,24 @@ class CommitRange
...
@@ -104,25 +102,24 @@ class CommitRange
return
nil
unless
project
.
present?
return
nil
unless
project
.
present?
return
false
unless
project
.
valid_repo?
return
false
unless
project
.
valid_repo?
commit
(
sha_from
).
present?
&&
commit
(
sha_to
)
.
present?
commit
_from
.
present?
&&
commit_to
.
present?
end
end
def
persisted?
def
persisted?
true
true
end
end
private
def
commit_from
@commit_from
||=
project
.
repository
.
commit
(
sha_from_as_param
)
def
sha_from_as_param
sha_from
+
(
inclusive?
?
'^'
:
''
)
end
end
def
commit
(
sha
)
def
commit_to
unless
@_commit_map
[
sha
]
@commit_to
||=
project
.
repository
.
commit
(
sha_to
)
# FIXME (rspeicher): Law of Demeter
@_commit_map
[
sha
]
=
project
.
repository
.
commit
(
sha
)
end
end
@_commit_map
[
sha
]
private
def
sha_from_as_param
sha_from
+
(
inclusive?
?
'^'
:
''
)
end
end
end
end
spec/models/commit_range_spec.rb
View file @
81a21e57
...
@@ -18,8 +18,8 @@ describe CommitRange do
...
@@ -18,8 +18,8 @@ describe CommitRange do
before
do
before
do
expect
(
range
).
to
receive
(
:valid_commits?
).
and_return
(
true
)
expect
(
range
).
to
receive
(
:valid_commits?
).
and_return
(
true
)
allow
(
range
).
to
receive
(
:commit
).
with
(
sha
_from
).
and_return
(
commit1
)
allow
(
range
).
to
receive
(
:commit_from
).
and_return
(
commit1
)
allow
(
range
).
to
receive
(
:commit
).
with
(
sha
_to
).
and_return
(
commit2
)
allow
(
range
).
to
receive
(
:commit_to
).
and_return
(
commit2
)
end
end
it
'returns an Array of Commits'
do
it
'returns an Array of Commits'
do
...
...
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