Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
klaus
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
jonashaag
klaus
Commits
0657a07c
Commit
0657a07c
authored
5 years ago
by
Jonas Haag
Browse files
Options
Downloads
Patches
Plain Diff
Follow-up fix for #233
parent
5b0ca477
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
klaus/repo.py
+20
-13
20 additions, 13 deletions
klaus/repo.py
klaus/templates/tree.inc.html
+6
-6
6 additions, 6 deletions
klaus/templates/tree.inc.html
tests/repos/scripts/test_repo
+3
-0
3 additions, 0 deletions
tests/repos/scripts/test_repo
tests/test_views.py
+7
-0
7 additions, 0 deletions
tests/test_views.py
with
36 additions
and
19 deletions
klaus/repo.py
+
20
−
13
View file @
0657a07c
...
...
@@ -170,23 +170,30 @@ class FancyRepo(dulwich.repo.Repo):
return
self
[
oid
]
def
listdir
(
self
,
commit
,
path
):
"""
Return a list of directories and files in given directory.
"""
"""
Return a list of submodules, directories and files in given
directory: Lists of (link name, target path) tuples.
"""
submodules
,
dirs
,
files
=
[],
[],
[]
for
entry
in
self
.
get_blob_or_tree
(
commit
,
path
).
items
():
entry_path
=
decode_from_git
(
entry
.
path
)
name
,
entry
=
entry_path
,
entry
.
in_path
(
encode_for_git
(
path
))
if
S_ISGITLINK
(
entry
.
mode
):
submodules
.
append
(
(
name
.
lower
(),
name
,
entry_path
,
entry
.
sha
))
elif
stat
.
S_ISDIR
(
entry
.
mode
):
dirs
.
append
((
name
.
lower
(),
name
,
entry_path
))
for
entry_rel
in
self
.
get_blob_or_tree
(
commit
,
path
).
items
():
# entry_rel: Entry('foo.txt', ...)
# entry_abs: Entry('spam/eggs/foo.txt', ...)
entry_abs
=
entry_rel
.
in_path
(
encode_for_git
(
path
))
path_str
=
decode_from_git
(
entry_abs
.
path
)
item
=
(
os
.
path
.
basename
(
path_str
),
path_str
)
if
S_ISGITLINK
(
entry_abs
.
mode
):
submodules
.
append
(
item
)
elif
stat
.
S_ISDIR
(
entry_abs
.
mode
):
dirs
.
append
(
item
)
else
:
files
.
append
((
name
.
lower
(),
name
,
entry_path
))
files
.
sort
()
dirs
.
sort
()
files
.
append
(
item
)
keyfunc
=
lambda
tpl
:
tpl
[
0
].
lower
()
submodules
.
sort
(
key
=
keyfunc
)
files
.
sort
(
key
=
keyfunc
)
dirs
.
sort
(
key
=
keyfunc
)
if
path
:
dirs
.
insert
(
0
,
(
None
,
'
..
'
,
parent_directory
(
path
)))
dirs
.
insert
(
0
,
(
'
..
'
,
parent_directory
(
path
)))
return
{
'
submodules
'
:
submodules
,
'
dirs
'
:
dirs
,
'
files
'
:
files
}
...
...
This diff is collapsed.
Click to expand it.
klaus/templates/tree.inc.html
+
6
−
6
View file @
0657a07c
...
...
@@ -3,14 +3,14 @@
<span>
(
<a
href=
"{{ url_for('download', repo=repo.name, rev=rev) }}"
>
Download .tar.gz
</a>
)
</span>
</h2>
<ul>
{% for
_,
name, fullpath in root_tree.dirs %}
<li><a
href=
"{{ url_for('history', repo=repo.name, rev=rev, path=fullpath) }}"
class=
dir
>
{{ name
|force_unicode
}}
</a></li>
{% for name, fullpath in root_tree.dirs %}
<li><a
href=
"{{ url_for('history', repo=repo.name, rev=rev, path=fullpath) }}"
class=
dir
>
{{ name }}
</a></li>
{% endfor %}
{% for
_,
name, fullpath
, submodulerev
in root_tree.submodules %}
<li><a
href=
"{{ url_for('submodule', repo=repo.name, rev=rev, path=fullpath) }}"
class=
submodule
>
{{ name
|force_unicode
}}
</a></li>
{% for name, fullpath in root_tree.submodules %}
<li><a
href=
"{{ url_for('submodule', repo=repo.name, rev=rev, path=fullpath) }}"
class=
submodule
>
{{ name }}
</a></li>
{% endfor %}
{% for
_,
name, fullpath in root_tree.files %}
<li><a
href=
"{{ url_for('blob', repo=repo.name, rev=rev, path=fullpath) }}"
>
{{ name
|force_unicode
}}
</a></li>
{% for name, fullpath in root_tree.files %}
<li><a
href=
"{{ url_for('blob', repo=repo.name, rev=rev, path=fullpath) }}"
>
{{ name }}
</a></li>
{% endfor %}
</ul>
</div>
This diff is collapsed.
Click to expand it.
tests/repos/scripts/test_repo
+
3
−
0
View file @
0657a07c
...
...
@@ -8,8 +8,11 @@ git init
echo
"int a;"
>
test.c
echo
"function test() {}"
>
test.js
mkdir
-p
folder
echo
>
folder/test.txt
git add test.c
git add test.js
git add folder
git commit
-m
"Add some code"
git commit
--allow-empty
-m
"Empty commit 1"
...
...
This diff is collapsed.
Click to expand it.
tests/test_views.py
+
7
−
0
View file @
0657a07c
...
...
@@ -36,3 +36,10 @@ def test_dont_render_large_file():
with
serve
():
response
=
requests
.
get
(
TEST_REPO_DONT_RENDER_URL
+
"
blob/HEAD/toolarge
"
).
text
assert
"
Large file not shown
"
in
response
def
test_regression_gh233_treeview_paths
():
with
serve
():
response
=
requests
.
get
(
UNAUTH_TEST_REPO_URL
+
"
tree/HEAD/folder
"
).
text
assert
"
blob/HEAD/test.txt
"
not
in
response
assert
"
blob/HEAD/folder/test.txt
"
in
response
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment