Changeset - 19e619f3cde1
[Not reviewed]
default
0 2 0
Mads Kiilerich - 9 years ago 2016-07-28 16:28:34
madski@unity3d.com
pullrequests: better handling of Mercurial pullrequests with missing revisions - don't crash

Trying to display a Mercurial PR with missing changesets could give a crash
when trying to compute available updates after 3f646f7bac39 did that
c.cs_ranges could be empty. That would normally not happen on Mercurial, but
could happen when restoring an old filesystem backup ... or when using strip on
the server.
2 files changed with 9 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -576,6 +576,8 @@ class PullrequestsController(BaseRepoCon
 
                           for x in c.pull_request.revisions]
 
        except ChangesetDoesNotExistError:
 
            c.cs_ranges = []
 
            h.flash(_('Revision %s not found in %s') % (x, c.cs_repo.repo_name),
 
                'error')
 
        c.cs_ranges_org = None # not stored and not important and moving target - could be calculated ...
 
        revs = [ctx.revision for ctx in reversed(c.cs_ranges)]
 
        c.jsdata = json.dumps(graph_data(org_scm_instance, revs))
 
@@ -600,7 +602,9 @@ class PullrequestsController(BaseRepoCon
 
        c.update_msg = ""
 
        c.update_msg_other = ""
 
        try:
 
            if org_scm_instance.alias == 'hg' and c.a_ref_name != 'ancestor':
 
            if not c.cs_ranges:
 
                c.update_msg = _('Error: changesets not found when displaying pull request from %s.') % c.cs_rev
 
            elif org_scm_instance.alias == 'hg' and c.a_ref_name != 'ancestor':
 
                if c.cs_ref_type != 'branch':
 
                    c.cs_branch_name = org_scm_instance.get_changeset(c.cs_ref_name).branch # use ref_type ?
 
                c.a_branch_name = c.a_ref_name
 
@@ -654,7 +658,7 @@ class PullrequestsController(BaseRepoCon
 
                c.cs_repo.scm_instance.get_changeset(c.cs_rev) # check it exists - raise ChangesetDoesNotExistError if not
 
                c.update_msg = _("Git pull requests don't support iterating yet.")
 
        except ChangesetDoesNotExistError:
 
            c.update_msg = _('Error: revision %s was not found. Please create a new pull request!') % c.cs_rev
 
            c.update_msg = _('Error: some changesets not found when displaying pull request from %s.') % c.cs_rev
 

	
 
        c.avail_revs = avail_revs
 
        c.avail_cs = [org_scm_instance.get_changeset(r) for r in avail_show]
kallithea/templates/pullrequests/pullrequest_show.html
Show inline comments
 
@@ -133,6 +133,7 @@ ${self.repo_context_bar('showpullrequest
 
              <label>${_('Pull changes')}:</label>
 
          </div>
 
          <div class="input">
 
            %if c.cs_ranges:
 
              <div>
 
               ## TODO: use cs_ranges[-1] or org_ref_parts[1] in both cases?
 
               %if h.is_hg(c.pull_request.org_repo):
 
@@ -141,6 +142,7 @@ ${self.repo_context_bar('showpullrequest
 
                 <span style="font-family: monospace">git pull ${c.pull_request.org_repo.clone_url()} ${c.pull_request.org_ref_parts[1]}</span>
 
               %endif
 
              </div>
 
            %endif
 
          </div>
 
        </div>
 
        <div class="field">
 
@@ -180,7 +182,7 @@ ${self.repo_context_bar('showpullrequest
 
                <table id="updaterevs-table" class="noborder" style="padding-left:50px">
 
                  %for cnt, cs in enumerate(c.avail_cs):
 
                    <tr id="chg_available_${cnt+1}">
 
                      %if cs.revision == c.cs_ranges[-1].revision:
 
                      %if c.cs_ranges and cs.revision == c.cs_ranges[-1].revision:
 
                        <td>
 
                          %if editable:
 
                            ${h.radio(name='updaterev', value='', checked=True)}
0 comments (0 inline, 0 general)