#491 Show list of commits from a particular commit hex
Closed 2 years ago by sayanchowdhury. Opened 3 years ago by sayanchowdhury.
sayanchowdhury/pagure rev-commits  into  master

@@ -72,7 +72,7 @@ 

            {{ branch }}

          </a>

          (<a href="{{ url_for('view_commits', username=username,

-                    repo=repo.name, branchname=branch) }}">commits</a>)

+                    repo=repo.name, identifier=branch) }}">commits</a>)

  

        </li>

        {% endfor %}

@@ -130,6 +130,7 @@ 

      {% else %}

      <h3>Last {{ last_commits | length }} commits</h3>

      {% endif %}

+     {% if branchname %}

      {% if diff_commits and authenticated %}

      <span id="request_pull" class="inline_it">

          <a href="{{ url_for('new_request_pull',

@@ -146,6 +147,7 @@ 

          </a>

      </span>

      {% endif %}

+     {% endif %}

      {% if repo_admin and branchname and branchname != 'master' %}

      <form action="{{

          url_for('.delete_branch',

@@ -47,7 +47,7 @@ 

  

        <li {% if select == 'logs' %}class="selected" {% endif %}>

          <a href="{{ url_for('.view_commits', username=username,

-                    repo=repo.name, branchname=branchname) }}">Commits</a>

+                    repo=repo.name, identifier=branchname) }}">Commits</a>

        </li>

  

        <li {% if select == 'tree' %}class="selected" {% endif %}>

file modified
+38 -25

@@ -234,11 +234,11 @@ 

  

  @APP.route('/<repo>/commits/')

  @APP.route('/<repo>/commits')

- @APP.route('/<repo>/commits/<path:branchname>')

+ @APP.route('/<repo>/commits/<path:identifier>')

  @APP.route('/fork/<username>/<repo>/commits/')

  @APP.route('/fork/<username>/<repo>/commits')

- @APP.route('/fork/<username>/<repo>/commits/<path:branchname>')

- def view_commits(repo, branchname=None, username=None):

+ @APP.route('/fork/<username>/<repo>/commits/<path:identifier>')

+ 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,35 @@ 

  

      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

  

-     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.head_is_unborn:

+                     branch = repo_obj.lookup_branch(repo_obj.head.shorthand)

+                     branchname = branch.branch_name

+                     commit = branch.get_object()

+                 else:

+                     branchname = repo_obj.listall_branches()[0]

+                     branch = repo_obj.lookup_branch(branchname)

+                     commit = branch.get_object()

+                     flask.flash('Showing commits for branch %s' % branchname)

+ 

+     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 +291,11 @@ 

  

      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 +324,16 @@ 

  

          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)

  

@@ -178,7 +178,7 @@ 

          output = self.app.get('/test/commits')

          self.assertEqual(output.status_code, 200)

          self.assertIn(

-             '<h3>Commits list</h3>\n    <ul>\n    </ul>', output.data)

+             '<h3>Commits list</h3>\n    <ul>\n      <li>', output.data)

          self.assertTrue(output.data.count('<a href="/test/branch/'), 1)

  

          output = self.app.get('/test/commits/feature')

no initial comment

Should we add some unit-tests for these changes?

Should we add some unit-tests for these changes?

Yes, This might require some test changes. I am currently looking into it.

Can you review the code to check to everything fine and I did not miss anything?

not repo_obj.is_empty

This is already checked above no?

The rest looks fine, I'll test it locally but from a quick look it looks fine :)

@sayanchowdhury, any luck with the unit tests here?

I'll will working on this tomorrow. There were some test cases which were failing

Closing this issue and will create a new one. Rebasing seems to be resulting in lot of conflicts.