From e8a830d64de1df12641bfc9e6906c6dcc4719e37 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 26 2015 13:05:06 +0000 Subject: [PATCH 1/6] show commits before commit hash instead of 404 in commits page --- diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html index 4b6c477..bd6aff0 100644 --- a/pagure/templates/repo_info.html +++ b/pagure/templates/repo_info.html @@ -130,6 +130,7 @@ {% else %}

Last {{ last_commits | length }} commits

{% endif %} + {% if branchname %} {% if diff_commits and authenticated %} Commits + repo=repo.name, identifier=branchname) }}">Commits
  • diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index c2f15a6..add3d37 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -234,11 +234,11 @@ def view_repo_branch(repo, branchname, username=None): @APP.route('//commits/') @APP.route('//commits') -@APP.route('//commits/') +@APP.route('//commits/') @APP.route('/fork///commits/') @APP.route('/fork///commits') -@APP.route('/fork///commits/') -def view_commits(repo, branchname=None, username=None): +@APP.route('/fork///commits/') +def view_commits(repo, identifier=None, username=None): """ Displays the commits of the specified repo. """ repo = pagure.lib.get_project(SESSION, repo, user=username) @@ -250,20 +250,39 @@ def view_commits(repo, branchname=None, username=None): repo_obj = pygit2.Repository(reponame) - if branchname and branchname not in repo_obj.listall_branches(): - flask.abort(404, 'Branch no found') + branchname = None + branch = None + commit = None + head = None + is_commit_hash = False - if branchname: - branch = repo_obj.lookup_branch(branchname) - elif not repo_obj.is_empty and not repo_obj.head_is_unborn: - branch = repo_obj.lookup_branch(repo_obj.head.shorthand) - else: - branch = None + if not repo_obj.is_empty: + if identifier in repo_obj.listall_branches(): + branchname = identifier + branch = repo_obj.lookup_branch(identifier) + commit = branch.get_object() + else: + try: + commit = repo_obj.get(identifier) + except (ValueError, TypeError): + if not repo_obj.is_empty and not repo_obj.head_is_unborn and not identifier: + branch = repo_obj.lookup_branch(repo_obj.head.shorthand) + branchname = branch.branch_name + commit = branch.get_object() + else: + if username: + return flask.redirect( + flask.url_for('view_commits', + repo=repo.name, username=username)) + else: + return flask.redirect( + flask.url_for('view_commits', repo=repo.name)) + + if not commit: + flask.abort(404, 'Commit/Branch not found') if not repo_obj.is_empty and not repo_obj.head_is_unborn: head = repo_obj.head.shorthand - else: - head = None try: page = int(flask.request.args.get('page', 1)) @@ -276,11 +295,11 @@ def view_commits(repo, branchname=None, username=None): n_commits = 0 last_commits = [] - if branch: - for commit in repo_obj.walk( - branch.get_object().hex, pygit2.GIT_SORT_TIME): + if commit: + for commit_obj in repo_obj.walk( + commit.hex, pygit2.GIT_SORT_TIME): if n_commits >= start and n_commits <= end: - last_commits.append(commit) + last_commits.append(commit_obj) n_commits += 1 total_page = int(ceil(n_commits / float(limit))) @@ -309,18 +328,16 @@ def view_commits(repo, branchname=None, username=None): if compare_branch: compare_commits = [ - commit.oid.hex - for commit in orig_repo.walk( + commit_obj.oid.hex + for commit_obj in orig_repo.walk( compare_branch.get_object().hex, pygit2.GIT_SORT_TIME) ] - if branch: - repo_commit = repo_obj[branch.get_object().hex] - - for commit in repo_obj.walk( - repo_commit.oid.hex, pygit2.GIT_SORT_TIME): - if commit.oid.hex in compare_commits: + if commit: + for commit_obj in repo_obj.walk( + commit.oid.hex, pygit2.GIT_SORT_TIME): + if commit_obj.oid.hex in compare_commits: break diff_commits.append(commit.oid.hex) From 7d1e810239ccc30685b1d2b446a395e5b2ee4794 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 26 2015 13:05:06 +0000 Subject: [PATCH 2/6] remove redundant variable --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index add3d37..e7597eb 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -254,7 +254,6 @@ def view_commits(repo, identifier=None, username=None): branch = None commit = None head = None - is_commit_hash = False if not repo_obj.is_empty: if identifier in repo_obj.listall_branches(): From 0c7d4a89509e6366a615757b984539f4a30da2ce Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 26 2015 13:05:06 +0000 Subject: [PATCH 3/6] fix the name of the url parameter --- diff --git a/pagure/templates/repo_info.html b/pagure/templates/repo_info.html index bd6aff0..303c944 100644 --- a/pagure/templates/repo_info.html +++ b/pagure/templates/repo_info.html @@ -72,7 +72,7 @@ {{ branch }} (commits) + repo=repo.name, identifier=branch) }}">commits)
  • {% endfor %} From d6ee5036ee16a4336edbe37c0878a27dc02515a0 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 26 2015 13:05:06 +0000 Subject: [PATCH 4/6] remove duplicate if check condition --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index e7597eb..30571c5 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -264,7 +264,7 @@ def view_commits(repo, identifier=None, username=None): try: commit = repo_obj.get(identifier) except (ValueError, TypeError): - if not repo_obj.is_empty and not repo_obj.head_is_unborn and not identifier: + if not repo_obj.head_is_unborn and not identifier: branch = repo_obj.lookup_branch(repo_obj.head.shorthand) branchname = branch.branch_name commit = branch.get_object() From 3dc7c69e77c6d82ba584bdaeaa50f4b07d2668c6 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 26 2015 13:05:06 +0000 Subject: [PATCH 5/6] switch to another branch if repo is not empty and repo head is unborn --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 30571c5..783db38 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -264,18 +264,14 @@ def view_commits(repo, identifier=None, username=None): try: commit = repo_obj.get(identifier) except (ValueError, TypeError): - if not repo_obj.head_is_unborn and not identifier: + if not repo_obj.head_is_unborn: branch = repo_obj.lookup_branch(repo_obj.head.shorthand) branchname = branch.branch_name commit = branch.get_object() else: - if username: - return flask.redirect( - flask.url_for('view_commits', - repo=repo.name, username=username)) - else: - return flask.redirect( - flask.url_for('view_commits', repo=repo.name)) + branchname = repo_obj.listall_branches()[0] + branch = repo_obj.lookup_branch(branchname) + commit = branch.get_object() if not commit: flask.abort(404, 'Commit/Branch not found') diff --git a/tests/test_progit_flask_ui_no_master_branch.py b/tests/test_progit_flask_ui_no_master_branch.py index 2addff7..0873b9b 100644 --- a/tests/test_progit_flask_ui_no_master_branch.py +++ b/tests/test_progit_flask_ui_no_master_branch.py @@ -178,7 +178,7 @@ class PagureFlaskNoMasterBranchtests(tests.Modeltests): output = self.app.get('/test/commits') self.assertEqual(output.status_code, 200) self.assertIn( - '

    Commits list

    \n
      \n
    ', output.data) + '

    Commits list

    \n
      \n
    • ', output.data) self.assertTrue(output.data.count('