From 5725a9d4fa729d46aa72254f126a1c81fb102130 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 14 2016 10:18:24 +0000 Subject: Add endpoint to redirect all view_commit URLs to the new URLs This bring backward compatibility for URLs using the entire git hash. For URL using short hash, this will no longer works but that's the cost we'll have to pay to get pseudo-namespace working in pagure. --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 9862de2..2f3a6fb 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -553,20 +553,26 @@ def view_raw_file(repo, identifier, filename=None, username=None): return (data, 200, headers) -#@APP.route('///') -#@APP.route('//') -#@APP.route('/fork////') -#@APP.route('/fork///') -#def view_commit_old(repo, commitid, username=None): - #""" Render a commit in a repo - #""" - #print repo, commitid, username - #tmp = '%s/%s' % (repo, commitid) - #if not pagure.lib.get_project(SESSION, tmp, user=username): - #return flask.redirect(flask.url_for( - #'view_commit', repo=repo, commitid=commitid, username=username)) - #else: - #return view_repo(tmp, username=username) +@APP.route('///') +@APP.route('//') +@APP.route('/fork////') +@APP.route('/fork///') +def view_commit_old(repo, commitid, username=None): + """ Redirect from the old view_commit to the new one. + + This method aims to provide backward compatibility with the old URL + scheme where the commit id was right after the repo name. + This is problematic since we now allow up to one slash ('/') in the + project name, making the url parsing a little trickier. + So if the element after the '/' is exactly 40 characters long, then we + consider it's a commit hash and redirect to the new URL scheme for + viewing commits. + If the element is more (not possible) or less than 40 characters, then + the other URLs should catch it. + + """ + return flask.redirect(flask.url_for( + 'view_commit', repo=repo, commitid=commitid, username=username)) @APP.route('//c//')