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
1520da38
Commit
1520da38
authored
14 years ago
by
Jonas Haag
Browse files
Options
Downloads
Patches
Plain Diff
Refactored the 'get_branch_or_commit' into the RepoWrapper class.
parent
b48ea431
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
klaus.py
+2
-8
2 additions, 8 deletions
klaus.py
repo.py
+16
-8
16 additions, 8 deletions
repo.py
with
18 additions
and
16 deletions
klaus.py
+
2
−
8
View file @
1520da38
...
...
@@ -87,12 +87,6 @@ def get_commit(repo, id):
except
KeyError
:
raise
HttpError
(
404
,
'"
%s
"
has no commit
"
%s
"'
%
(
repo
.
name
,
id
))
def
get_branch_or_commit
(
repo
,
id
):
try
:
return
repo
.
get_branch
(
id
)
except
KeyError
:
return
get_commit
(
repo
,
id
)
def
get_tree_or_blob_url
(
repo
,
commit_id
,
tree_entry
):
if
tree_entry
.
mode
&
stat
.
S_IFDIR
:
view
=
'
view_tree
'
...
...
@@ -113,7 +107,7 @@ def view_repo(env, repo):
@app.route
(
'
/:repo:/tree/:commit_id:/(?P<path>.*)
'
)
def
view_tree
(
env
,
repo
,
commit_id
,
path
):
repo
=
get_repo
(
repo
)
commit
=
get_branch_or_commit
(
repo
,
commit_id
)
commit
=
repo
.
get_branch_or_commit
(
commit_id
)
files
=
((
name
,
get_tree_or_blob_url
(
repo
,
commit_id
,
entry
))
for
name
,
entry
in
repo
.
listdir
(
commit
,
path
))
return
{
'
repo
'
:
repo
,
'
commit_id
'
:
commit_id
,
...
...
@@ -122,7 +116,7 @@ def view_tree(env, repo, commit_id, path):
@app.route
(
'
/:repo:/blob/:commit_id:/(?P<path>.*)
'
)
def
view_blob
(
env
,
repo
,
commit_id
,
path
):
repo
=
get_repo
(
repo
)
commit
=
get_branch_or_commit
(
repo
,
commit_id
)
commit
=
repo
.
get_branch_or_commit
(
commit_id
)
directory
,
filename
=
os
.
path
.
split
(
path
)
blob
=
repo
[
repo
.
get_tree
(
commit
,
directory
)[
filename
][
1
]]
return
{
'
repo
'
:
repo
,
'
blob
'
:
blob
,
'
path
'
:
path
,
'
commit_id
'
:
commit_id
}
...
...
This diff is collapsed.
Click to expand it.
repo.py
+
16
−
8
View file @
1520da38
...
...
@@ -6,18 +6,26 @@ import difflib
import
dulwich
,
dulwich
.
patch
class
RepoWrapper
(
dulwich
.
repo
.
Repo
):
def
get_branch
(
self
,
name
=
None
):
if
name
is
None
:
name
=
'
master
'
def
get_branch_or_commit
(
self
,
id
):
try
:
return
self
[
id
]
except
KeyError
:
return
self
.
get_branch
(
id
)
def
get_branch
(
self
,
name
):
return
self
[
'
refs/heads/
'
+
name
]
def
history
(
self
,
branch
=
None
,
max_commits
=
None
):
def
get_default_branch
(
self
):
return
self
.
get_branch
(
'
master
'
)
def
history
(
self
,
commit
=
None
,
max_commits
=
None
):
if
commit
is
None
:
commit
=
self
.
get_default_branch
()
if
max_commits
is
None
:
max_commits
=
float
(
'
inf
'
)
head
=
self
.
get_branch
(
branch
)
while
max_commits
and
head
.
parents
:
yield
head
head
=
self
[
head
.
parents
[
0
]]
while
max_commits
and
commit
.
parents
:
yield
commit
commit
=
self
[
commit
.
parents
[
0
]]
max_commits
-=
1
def
get_tree
(
self
,
commit
,
path
):
...
...
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