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
Jérome Perrin
gitlab-ce
Commits
28fba5ed
Commit
28fba5ed
authored
Dec 20, 2017
by
Kim Carlbäcker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Merge branch 'repo-write-ref-client-prep' into 'master'"
This reverts merge request !15712
parent
f5290c97
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
35 deletions
+16
-35
app/models/project.rb
app/models/project.rb
+1
-1
app/models/repository.rb
app/models/repository.rb
+10
-6
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+3
-8
spec/models/project_spec.rb
spec/models/project_spec.rb
+2
-3
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+0
-17
No files found.
app/models/project.rb
View file @
28fba5ed
...
@@ -1148,7 +1148,7 @@ class Project < ActiveRecord::Base
...
@@ -1148,7 +1148,7 @@ class Project < ActiveRecord::Base
def
change_head
(
branch
)
def
change_head
(
branch
)
if
repository
.
branch_exists?
(
branch
)
if
repository
.
branch_exists?
(
branch
)
repository
.
before_change_head
repository
.
before_change_head
repository
.
write_ref
(
'HEAD'
,
"refs/heads/
#{
branch
}
"
,
force:
true
)
repository
.
write_ref
(
'HEAD'
,
"refs/heads/
#{
branch
}
"
)
repository
.
copy_gitattributes
(
branch
)
repository
.
copy_gitattributes
(
branch
)
repository
.
after_change_head
repository
.
after_change_head
reload_default_branch
reload_default_branch
...
...
app/models/repository.rb
View file @
28fba5ed
...
@@ -19,7 +19,6 @@ class Repository
...
@@ -19,7 +19,6 @@ class Repository
attr_accessor
:full_path
,
:disk_path
,
:project
,
:is_wiki
attr_accessor
:full_path
,
:disk_path
,
:project
,
:is_wiki
delegate
:ref_name_for_sha
,
to: :raw_repository
delegate
:ref_name_for_sha
,
to: :raw_repository
delegate
:write_ref
,
to: :raw_repository
CreateTreeError
=
Class
.
new
(
StandardError
)
CreateTreeError
=
Class
.
new
(
StandardError
)
...
@@ -256,10 +255,11 @@ class Repository
...
@@ -256,10 +255,11 @@ class Repository
# This will still fail if the file is corrupted (e.g. 0 bytes)
# This will still fail if the file is corrupted (e.g. 0 bytes)
begin
begin
write_ref
(
keep_around_ref_name
(
sha
),
sha
,
force:
true
)
write_ref
(
keep_around_ref_name
(
sha
),
sha
)
rescue
Gitlab
::
Git
::
Repository
::
GitError
=>
ex
rescue
Rugged
::
ReferenceError
=>
ex
# Necessary because https://gitlab.com/gitlab-org/gitlab-ce/issues/20156
Rails
.
logger
.
error
"Unable to create
#{
REF_KEEP_AROUND
}
reference for repository
#{
path
}
:
#{
ex
}
"
return
true
if
ex
.
message
=~
/Failed to create locked file/
&&
ex
.
message
=~
/File exists/
rescue
Rugged
::
OSError
=>
ex
raise
unless
ex
.
message
=~
/Failed to create locked file/
&&
ex
.
message
=~
/File exists/
Rails
.
logger
.
error
"Unable to create
#{
REF_KEEP_AROUND
}
reference for repository
#{
path
}
:
#{
ex
}
"
Rails
.
logger
.
error
"Unable to create
#{
REF_KEEP_AROUND
}
reference for repository
#{
path
}
:
#{
ex
}
"
end
end
...
@@ -269,6 +269,10 @@ class Repository
...
@@ -269,6 +269,10 @@ class Repository
ref_exists?
(
keep_around_ref_name
(
sha
))
ref_exists?
(
keep_around_ref_name
(
sha
))
end
end
def
write_ref
(
ref_path
,
sha
)
rugged
.
references
.
create
(
ref_path
,
sha
,
force:
true
)
end
def
diverging_commit_counts
(
branch
)
def
diverging_commit_counts
(
branch
)
root_ref_hash
=
raw_repository
.
commit
(
root_ref
).
id
root_ref_hash
=
raw_repository
.
commit
(
root_ref
).
id
cache
.
fetch
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
do
cache
.
fetch
(
:"diverging_commit_counts_
#{
branch
.
name
}
"
)
do
...
@@ -1015,7 +1019,7 @@ class Repository
...
@@ -1015,7 +1019,7 @@ class Repository
end
end
def
create_ref
(
ref
,
ref_path
)
def
create_ref
(
ref
,
ref_path
)
write_ref
(
ref_path
,
ref
)
raw_repository
.
write_ref
(
ref_path
,
ref
)
end
end
def
ls_files
(
ref
)
def
ls_files
(
ref
)
...
...
lib/gitlab/git/repository.rb
View file @
28fba5ed
...
@@ -1101,17 +1101,12 @@ module Gitlab
...
@@ -1101,17 +1101,12 @@ module Gitlab
end
end
end
end
def
write_ref
(
ref_path
,
ref
,
force:
false
)
def
write_ref
(
ref_path
,
ref
)
raise
ArgumentError
,
"invalid ref_path
#{
ref_path
.
inspect
}
"
if
ref_path
.
include?
(
' '
)
raise
ArgumentError
,
"invalid ref_path
#{
ref_path
.
inspect
}
"
if
ref_path
.
include?
(
' '
)
raise
ArgumentError
,
"invalid ref
#{
ref
.
inspect
}
"
if
ref
.
include?
(
"
\x00
"
)
raise
ArgumentError
,
"invalid ref
#{
ref
.
inspect
}
"
if
ref
.
include?
(
"
\x00
"
)
ref
=
"refs/heads/
#{
ref
}
"
unless
ref
.
start_with?
(
"refs"
)
||
ref
=~
/\A[a-f0-9]+\z/i
input
=
"update
#{
ref_path
}
\x00
#{
ref
}
\x00\x00
"
run_git!
(
%w[update-ref --stdin -z]
)
{
|
stdin
|
stdin
.
write
(
input
)
}
rugged
.
references
.
create
(
ref_path
,
ref
,
force:
force
)
rescue
Rugged
::
ReferenceError
=>
ex
raise
GitError
,
"could not create ref
#{
ref_path
}
:
#{
ex
}
"
rescue
Rugged
::
OSError
=>
ex
raise
GitError
,
"could not create ref
#{
ref_path
}
:
#{
ex
}
"
end
end
def
fetch_ref
(
source_repository
,
source_ref
:,
target_ref
:)
def
fetch_ref
(
source_repository
,
source_ref
:,
target_ref
:)
...
...
spec/models/project_spec.rb
View file @
28fba5ed
...
@@ -1863,11 +1863,10 @@ describe Project do
...
@@ -1863,11 +1863,10 @@ describe Project do
project
.
change_head
(
project
.
default_branch
)
project
.
change_head
(
project
.
default_branch
)
end
end
it
'creates the new reference'
do
it
'creates the new reference
with rugged
'
do
expect
(
project
.
repository
.
r
aw_repository
).
to
receive
(
:write_ref
).
with
(
'HEAD'
,
expect
(
project
.
repository
.
r
ugged
.
references
).
to
receive
(
:create
).
with
(
'HEAD'
,
"refs/heads/
#{
project
.
default_branch
}
"
,
"refs/heads/
#{
project
.
default_branch
}
"
,
force:
true
)
force:
true
)
project
.
change_head
(
project
.
default_branch
)
project
.
change_head
(
project
.
default_branch
)
end
end
...
...
spec/models/repository_spec.rb
View file @
28fba5ed
...
@@ -1979,23 +1979,6 @@ describe Repository do
...
@@ -1979,23 +1979,6 @@ describe Repository do
File
.
delete
(
path
)
File
.
delete
(
path
)
end
end
it
"attempting to call keep_around when exists a lock does not fail"
do
ref
=
repository
.
send
(
:keep_around_ref_name
,
sample_commit
.
id
)
path
=
File
.
join
(
repository
.
path
,
ref
)
lock_path
=
"
#{
path
}
.lock"
FileUtils
.
mkdir_p
(
File
.
dirname
(
path
))
File
.
open
(
lock_path
,
'w'
)
{
|
f
|
f
.
write
(
''
)
}
begin
expect
{
repository
.
keep_around
(
sample_commit
.
id
)
}.
not_to
raise_error
(
Gitlab
::
Git
::
Repository
::
GitError
)
expect
(
File
.
exist?
(
lock_path
)).
to
be_falsey
ensure
File
.
delete
(
path
)
end
end
end
end
describe
'#update_ref'
do
describe
'#update_ref'
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