Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
21ae869d
Commit
21ae869d
authored
Apr 20, 2012
by
Enrique García Cota
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
increased scm file download in scm views
parent
c4f80d5e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
395 additions
and
361 deletions
+395
-361
repositories_controller.rb
app/controllers/repositories_controller.rb
+38
-31
repository.rb
app/models/repository.rb
+4
-0
abstract_adapter.rb
lib/redmine/scm/adapters/abstract_adapter.rb
+52
-17
bazaar_adapter.rb
lib/redmine/scm/adapters/bazaar_adapter.rb
+1
-1
cvs_adapter.rb
lib/redmine/scm/adapters/cvs_adapter.rb
+1
-1
darcs_adapter.rb
lib/redmine/scm/adapters/darcs_adapter.rb
+1
-1
filesystem_adapter.rb
lib/redmine/scm/adapters/filesystem_adapter.rb
+9
-1
git_adapter.rb
lib/redmine/scm/adapters/git_adapter.rb
+73
-79
mercurial_adapter.rb
lib/redmine/scm/adapters/mercurial_adapter.rb
+122
-120
subversion_adapter.rb
lib/redmine/scm/adapters/subversion_adapter.rb
+94
-110
No files found.
app/controllers/repositories_controller.rb
View file @
21ae869d
...
...
@@ -118,41 +118,48 @@ class RepositoriesController < ApplicationController
# If the entry is a dir, show the browser
(
show
;
return
)
if
@entry
.
is_dir?
@content
=
@repository
.
cat
(
@path
,
@rev
)
(
show_error_not_found
;
return
)
unless
@content
if
'raw'
==
params
[
:format
]
||
(
@content
.
size
&&
@content
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
||
!
is_entry_text_data?
(
@content
,
@path
)
# Force the download
send_opt
=
{
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
)
}
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
send_opt
[
:type
]
=
send_type
.
to_s
if
send_type
send_data
@content
,
send_opt
else
# Prevent empty lines when displaying a file with Windows style eol
# TODO: UTF-16
# Is this needs? AttachmentsController reads file simply.
@content
.
gsub!
(
"
\r\n
"
,
"
\n
"
)
@changeset
=
@repository
.
find_changeset_by_name
(
@rev
)
@repository
.
cat_to_tempfile
(
@path
,
@rev
)
do
|
f
|
if
params
[
:format
]
==
'raw'
||
is_too_large_to_show?
(
f
)
||
is_binary?
(
f
,
@path
)
send_type
=
Redmine
::
MimeType
.
of
(
@path
)
options
=
{
:filename
=>
filename_for_content_disposition
(
@path
.
split
(
'/'
).
last
),
:disposition
=>
'attachment'
,
:x_sendfile
=>
false
# x_sendfile does not work well with tempfiles
}
options
[
:type
]
=
send_type
.
to_s
if
send_type
send_file
(
f
.
path
,
options
)
else
@content
=
f
.
read
@changeset
=
@repository
.
find_changeset_by_name
(
@rev
)
end
end
rescue
Errno
::
ENOENT
show_error_not_found
end
def
is_entry_text_data?
(
ent
,
path
)
# UTF-16 contains "\x00".
# It is very strict that file contains less than 30% of ascii symbols
# in non Western Europe.
return
true
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# Ruby 1.8.6 has a bug of integer divisions.
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
if
ent
.
respond_to?
(
"is_binary_data?"
)
&&
ent
.
is_binary_data?
# Ruby 1.8.x and <1.9.2
return
false
elsif
ent
.
respond_to?
(
:force_encoding
)
&&
(
ent
.
dup
.
force_encoding
(
"UTF-8"
)
!=
ent
.
dup
.
force_encoding
(
"BINARY"
)
)
# Ruby 1.9.2
# TODO: need to handle edge cases of non-binary content that isn't UTF-8
return
false
end
true
def
is_too_large_to_show?
(
f
)
f
.
size
>
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
end
private
:is_too_large_to_show?
def
is_binary?
(
file
,
path
)
return
false
if
Redmine
::
MimeType
.
is_type?
(
'text'
,
path
)
# First block of the file is examined for odd
# characters such as strange control codes or char-
# acters with the high bit set. If too many strange
# characters (>30%) are found, it's a binary file,
# otherwise it's a text file. Also, any file con-
# taining null in the first block is considered a
# binary file.
blk
=
file
.
read
(
Setting
.
file_max_size_displayed
.
to_i
.
kilobyte
)
return
blk
.
size
==
0
||
blk
.
count
(
"^ -~"
,
"^
\r\n
"
)
/
blk
.
size
>
0.3
||
blk
.
count
(
"
\x00
"
)
>
0
end
private
:is_
entry_text_data
?
private
:is_
binary
?
def
annotate
@entry
=
@repository
.
entry
(
@path
,
@rev
)
...
...
app/models/repository.rb
View file @
21ae869d
...
...
@@ -104,6 +104,10 @@ class Repository < ActiveRecord::Base
scm
.
cat
(
path
,
identifier
)
end
def
cat_to_tempfile
(
path
,
identifier
,
&
block
)
scm
.
cat_to_tempfile
(
path
,
identifier
,
&
block
)
end
def
diff
(
path
,
rev
,
rev_to
)
scm
.
diff
(
path
,
rev
,
rev_to
)
end
...
...
lib/redmine/scm/adapters/abstract_adapter.rb
View file @
21ae869d
...
...
@@ -69,7 +69,7 @@ module Redmine
end
def
adapter_name
'Abstract'
self
.
class
.
name
.
gsub
(
"Adapter"
,
""
)
end
def
supports_cat?
...
...
@@ -143,6 +143,19 @@ module Redmine
return
nil
end
def
cat_to_tempfile
(
path
,
identifier
,
&
block
)
prefix
=
path
.
split
(
"/"
).
last
tmp_path
=
Rails
.
root
.
join
(
'tmp'
)
Tempfile
.
open
(
prefix
,
tmp_path
)
do
|
f
|
save_entry_in_file
(
f
,
path
,
identifier
)
block
.
call
(
f
)
end
end
def
save_entry_in_file
(
file
,
path
,
identifier
)
return
nil
end
def
with_leading_slash
(
path
)
path
||=
''
(
path
[
0
,
1
]
!=
"/"
)
?
"/
#{
path
}
"
:
path
...
...
@@ -183,34 +196,56 @@ module Redmine
self
.
class
.
logger
end
def
shellout
(
cmd
,
&
block
)
self
.
class
.
shellout
(
cmd
,
&
block
)
def
shellout
(
cmd
,
output_path
=
nil
,
&
block
)
self
.
class
.
shellout
(
cmd
,
output_path
,
&
block
)
end
def
build_scm_cmd
(
cmd_args
)
([
self
.
class
.
sq_bin
]
+
cmd_args
).
join
(
' '
)
end
def
scm_cmd
(
cmd_args
,
output_path
=
nil
,
&
block
)
cmd
=
build_scm_cmd
(
cmd_args
)
begin
ret
=
shellout
(
cmd
,
output_path
,
&
block
)
rescue
Exception
=>
e
msg
=
strip_credential
(
e
.
message
)
cmd
=
strip_credential
(
cmd
)
logger
.
error
(
"Error executing
#{
adapter_name
}
command [
#{
cmd
}
]:
#{
msg
}
"
)
end
return
nil
if
$?
&&
$?
.
exitstatus
!=
0
ret
end
def
self
.
logger
RAILS_DEFAULT_LOGGER
end
def
self
.
shellout
(
cmd
,
&
block
)
logger
.
debug
"Shelling out:
#{
strip_credential
(
cmd
)
}
"
if
logger
&&
logger
.
debug?
if
Rails
.
env
==
'development'
# Capture stderr when running in dev environment
cmd
=
"
#{
cmd
}
2>>
#{
RAILS_ROOT
}
/log/scm.stderr.log"
end
def
self
.
process_cmd
(
cmd
,
output_path
)
cmd
=
Rails
.
env
==
'development'
?
"
#{
cmd
}
2>>
#{
RAILS_ROOT
}
/log/scm.stderr.log"
:
cmd
cmd
=
"
#{
cmd
}
>>
#{
output_path
}
"
if
output_path
.
present?
cmd
end
def
self
.
get_reading_mode_for_ruby_version
RUBY_VERSION
<
'1.9'
?
'r+'
:
'r+:ASCII-8BIT'
end
def
self
.
shellout
(
cmd
,
output_path
=
nil
,
&
block
)
logger
.
debug
(
"Shelling out:
#{
strip_credential
(
cmd
)
}
"
)
if
logger
&&
logger
.
respond_to?
(
:debug
)
cmd
=
process_cmd
(
cmd
,
output_path
)
mode
=
get_reading_mode_for_ruby_version
begin
if
RUBY_VERSION
<
'1.9'
mode
=
"r+"
else
mode
=
"r+:ASCII-8BIT"
end
result
=
nil
IO
.
popen
(
cmd
,
mode
)
do
|
io
|
io
.
close_write
block
.
call
(
io
)
if
block_given?
result
=
block
.
call
(
io
)
if
block_given?
end
result
rescue
Errno
::
ENOENT
=>
e
msg
=
strip_credential
(
e
.
message
)
# The command failed, log it and re-raise
logger
.
error
(
"SCM command failed, make sure that your SCM binary (eg. svn) is in PATH (
#{
ENV
[
'PATH'
]
}
):
#{
strip_credential
(
cmd
)
}
\n
with:
#{
msg
}
"
)
cmd
=
strip_credential
(
cmd
)
logger
.
error
(
"SCM command failed, make sure that your SCM binary (eg. svn) is in PATH (
#{
ENV
[
'PATH'
]
}
):
#{
cmd
}
\n
with:
#{
msg
}
"
)
raise
CommandFailed
.
new
(
msg
)
end
end
...
...
lib/redmine/scm/adapters/bazaar_adapter.rb
View file @
21ae869d
...
...
@@ -12,7 +12,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require
'redmine/scm/adapters/abstract_adapter'
require
_dependency
'redmine/scm/adapters/abstract_adapter'
module
Redmine
module
Scm
...
...
lib/redmine/scm/adapters/cvs_adapter.rb
View file @
21ae869d
...
...
@@ -12,7 +12,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require
'redmine/scm/adapters/abstract_adapter'
require
_dependency
'redmine/scm/adapters/abstract_adapter'
module
Redmine
module
Scm
...
...
lib/redmine/scm/adapters/darcs_adapter.rb
View file @
21ae869d
...
...
@@ -12,7 +12,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require
'redmine/scm/adapters/abstract_adapter'
require
_dependency
'redmine/scm/adapters/abstract_adapter'
require
'rexml/document'
module
Redmine
...
...
lib/redmine/scm/adapters/filesystem_adapter.rb
View file @
21ae869d
...
...
@@ -12,7 +12,7 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require
'redmine/scm/adapters/abstract_adapter'
require
_dependency
'redmine/scm/adapters/abstract_adapter'
require
'find'
module
Redmine
...
...
@@ -91,6 +91,14 @@ module Redmine
raise
CommandFailed
.
new
(
err
.
message
)
end
def
save_entry_in_file
(
f
,
path
,
identifier
)
p
=
scm_iconv
(
@path_encoding
,
'UTF-8'
,
target
(
path
))
FileUtils
.
cp
(
p
,
f
.
path
)
rescue
=>
err
logger
.
error
"scm: filesystem: error:
#{
err
.
message
}
"
raise
CommandFailed
.
new
(
err
.
message
)
end
private
# AbstractAdapter::target is implicitly made to quote paths.
...
...
lib/redmine/scm/adapters/git_adapter.rb
View file @
21ae869d
This diff is collapsed.
Click to expand it.
lib/redmine/scm/adapters/mercurial_adapter.rb
View file @
21ae869d
This diff is collapsed.
Click to expand it.
lib/redmine/scm/adapters/subversion_adapter.rb
View file @
21ae869d
This diff is collapsed.
Click to expand it.
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