~edwargix/git.sr.ht

48dcdbd06de9702795ecc8ebd33bdf6c6345676b — Nolan Prescott 3 years ago 82edbf5
Allow "path" ref in log and tree URLs

This change updates both the <owner>/<repo>/log and
<owner>/<repo>/tree URLs by including a sentinel value between the two
possible "path"-like parts of the URL, the ref and the path.

Without a sentinel value it is not possible to use the two path
variables due to the greedy nature of the last instance.

Case in point, something like:

@route(<path:first>/<path:second>)
def example(first, second):
    return f'first: {first}    second: {second}'

GET debian/0.1.0-2/some/file

first: debian    second: 0.1.0-2/some/file
1 files changed, 2 insertions(+), 2 deletions(-)

M gitsrht/blueprints/repo.py
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +2 -2
@@ 186,7 186,7 @@ def lookup_ref(git_repo, ref, path):

@repo.route("/<owner>/<repo>/tree", defaults={"ref": None, "path": ""})
@repo.route("/<owner>/<repo>/tree/<path:ref>", defaults={"path": ""})
@repo.route("/<owner>/<repo>/tree/<ref>/<path:path>")
@repo.route("/<owner>/<repo>/tree/<path:ref>/item/<path:path>")
def tree(owner, repo, ref, path):
    owner, repo = get_repo_or_redir(owner, repo)



@@ 394,7 394,7 @@ def collect_refs(git_repo):

@repo.route("/<owner>/<repo>/log", defaults={"ref": None, "path": ""})
@repo.route("/<owner>/<repo>/log/<path:ref>", defaults={"path": ""})
@repo.route("/<owner>/<repo>/log/<ref>/<path:path>")
@repo.route("/<owner>/<repo>/log/<path:ref>/item/<path:path>")
def log(owner, repo, ref, path):
    owner, repo = get_repo_or_redir(owner, repo)
    with GitRepository(repo.path) as git_repo: