# HG changeset patch # User Mads Kiilerich # Date 1408657615 -7200 # Node ID 6cb077e99873bdce8bbd9b51948cd2bdfa478fa9 # Parent 296b37f6fcdc651ae6a9a133b4198e049ea408a3 diff: rename template values for org and other for compare and PR sed -i -e 's,\<\(c\.\(default_\)\?\)org_,\1a_,g' -e 's,\<\(c\.\(default_\)\?\)other_,\1cs_,g' kallithea/controllers/compare.py kallithea/templates/compare/compare_cs.html kallithea/templates/compare/compare_diff.html sed -i -e 's,\<\(c\.\(default_\)\?\)org_,\1cs_,g' -e 's,\<\(c\.\(default_\)\?\)other_,\1a_,g' kallithea/controllers/pullrequests.py kallithea/templates/pullrequests/pullrequest.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/templates/changeset/diff_block.html Renaming it differently for compare and PR finally fixes some issues with diffs and links pointing at wrong revisions and repos - no more whac-a-mole. diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/controllers/compare.py --- a/kallithea/controllers/compare.py Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/controllers/compare.py Thu Aug 21 23:46:55 2014 +0200 @@ -149,9 +149,9 @@ c.compare_home = True org_repo = c.db_repo.repo_name other_repo = request.GET.get('other_repo', org_repo) - c.org_repo = Repository.get_by_repo_name(org_repo) - c.other_repo = Repository.get_by_repo_name(other_repo) - c.org_ref_name = c.other_ref_name = _('Select changeset') + c.a_repo = Repository.get_by_repo_name(org_repo) + c.cs_repo = Repository.get_by_repo_name(other_repo) + c.a_ref_name = c.cs_ref_name = _('Select changeset') return render('compare/compare_diff.html') @LoginRequired() @@ -210,27 +210,27 @@ h.flash(msg, category='error') return redirect(url('compare_home', repo_name=c.repo_name)) - c.org_rev = self._get_ref_rev(org_repo, org_ref_type, org_ref_name) - c.other_rev = self._get_ref_rev(other_repo, other_ref_type, other_ref_name) + c.a_rev = self._get_ref_rev(org_repo, org_ref_type, org_ref_name) + c.cs_rev = self._get_ref_rev(other_repo, other_ref_type, other_ref_name) c.compare_home = False - c.org_repo = org_repo - c.other_repo = other_repo - c.org_ref_name = org_ref_name - c.other_ref_name = other_ref_name - c.org_ref_type = org_ref_type - c.other_ref_type = other_ref_type + c.a_repo = org_repo + c.cs_repo = other_repo + c.a_ref_name = org_ref_name + c.cs_ref_name = other_ref_name + c.a_ref_type = org_ref_type + c.cs_ref_type = other_ref_type c.cs_repo = other_repo c.cs_ranges, c.cs_ranges_org, c.ancestor = self._get_changesets( - org_repo.scm_instance.alias, org_repo.scm_instance, c.org_rev, - other_repo.scm_instance, c.other_rev) + org_repo.scm_instance.alias, org_repo.scm_instance, c.a_rev, + other_repo.scm_instance, c.cs_rev) raw_ids = [x.raw_id for x in c.cs_ranges] c.cs_comments = other_repo.get_comments(raw_ids) c.statuses = other_repo.statuses(raw_ids) revs = [ctx.revision for ctx in reversed(c.cs_ranges)] - c.jsdata = json.dumps(graph_data(c.other_repo.scm_instance, revs)) + c.jsdata = json.dumps(graph_data(c.cs_repo.scm_instance, revs)) if partial: return render('compare/compare_cs.html') @@ -239,7 +239,7 @@ # previewing what will be merged. # Make the diff on the other repo (which is known to have other_rev) log.debug('Using ancestor %s as rev1 instead of %s' - % (c.ancestor, c.org_rev)) + % (c.ancestor, c.a_rev)) rev1 = c.ancestor org_repo = other_repo else: # comparing tips, not necessarily linearly related @@ -250,13 +250,13 @@ log.error('cannot compare across repos %s and %s', org_repo, other_repo) h.flash(_('Cannot compare repositories without using common ancestor'), category='error') raise HTTPBadRequest - rev1 = c.org_rev + rev1 = c.a_rev diff_limit = self.cut_off_limit if not c.fulldiff else None log.debug('running diff between %s and %s in %s' - % (rev1, c.other_rev, org_repo.scm_instance.path)) - txtdiff = org_repo.scm_instance.get_diff(rev1=rev1, rev2=c.other_rev, + % (rev1, c.cs_rev, org_repo.scm_instance.path)) + txtdiff = org_repo.scm_instance.get_diff(rev1=rev1, rev2=c.cs_rev, ignore_whitespace=ignore_whitespace, context=line_context) diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/controllers/pullrequests.py --- a/kallithea/controllers/pullrequests.py Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/controllers/pullrequests.py Thu Aug 21 23:46:55 2014 +0200 @@ -259,26 +259,26 @@ #other_rev = request.POST.get('rev_start') branch = request.GET.get('branch') - c.org_repos = [(org_repo.repo_name, org_repo.repo_name)] - c.default_org_repo = org_repo.repo_name - c.org_refs, c.default_org_ref = self._get_repo_refs(org_scm_instance, rev=org_rev, branch=branch) + c.cs_repos = [(org_repo.repo_name, org_repo.repo_name)] + c.default_cs_repo = org_repo.repo_name + c.cs_refs, c.default_cs_ref = self._get_repo_refs(org_scm_instance, rev=org_rev, branch=branch) # add org repo to other so we can open pull request against peer branches on itself - c.other_repos = [(org_repo.repo_name, '%s (self)' % org_repo.repo_name)] + c.a_repos = [(org_repo.repo_name, '%s (self)' % org_repo.repo_name)] # add parent of this fork also and select it if org_repo.parent: - c.other_repos.append((org_repo.parent.repo_name, '%s (parent)' % org_repo.parent.repo_name)) - c.other_repo = org_repo.parent - c.other_refs, c.default_other_ref = self._get_repo_refs(org_repo.parent.scm_instance) + c.a_repos.append((org_repo.parent.repo_name, '%s (parent)' % org_repo.parent.repo_name)) + c.a_repo = org_repo.parent + c.a_refs, c.default_a_ref = self._get_repo_refs(org_repo.parent.scm_instance) else: - c.other_repo = org_repo - c.other_refs, c.default_other_ref = self._get_repo_refs(org_scm_instance) # without rev and branch + c.a_repo = org_repo + c.a_refs, c.default_a_ref = self._get_repo_refs(org_scm_instance) # without rev and branch # gather forks and add to this list ... even though it is rare to # request forks to pull from their parent for fork in org_repo.forks: - c.other_repos.append((fork.repo_name, fork.repo_name)) + c.a_repos.append((fork.repo_name, fork.repo_name)) return render('/pullrequests/pullrequest.html') @@ -553,32 +553,32 @@ raise HTTPNotFound # load compare data into template context - c.org_repo = c.pull_request.org_repo - (c.org_ref_type, - c.org_ref_name, - c.org_rev) = c.pull_request.org_ref.split(':') + c.cs_repo = c.pull_request.org_repo + (c.cs_ref_type, + c.cs_ref_name, + c.cs_rev) = c.pull_request.org_ref.split(':') - c.other_repo = c.pull_request.other_repo - (c.other_ref_type, - c.other_ref_name, - c.other_rev) = c.pull_request.other_ref.split(':') # other_rev is ancestor + c.a_repo = c.pull_request.other_repo + (c.a_ref_type, + c.a_ref_name, + c.a_rev) = c.pull_request.other_ref.split(':') # other_rev is ancestor - org_scm_instance = c.org_repo.scm_instance # property with expensive cache invalidation check!!! - c.cs_repo = c.org_repo + org_scm_instance = c.cs_repo.scm_instance # property with expensive cache invalidation check!!! + c.cs_repo = c.cs_repo c.cs_ranges = [org_scm_instance.get_changeset(x) for x in c.pull_request.revisions] 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)) c.available = [] - c.org_branch_name = c.org_ref_name - other_scm_instance = c.other_repo.scm_instance - if org_scm_instance.alias == 'hg' and c.other_ref_name != 'ancestor': - if c.org_ref_type != 'branch': - c.org_branch_name = org_scm_instance.get_changeset(c.org_ref_name).branch # use ref_type ? - other_branch_name = c.other_ref_name - if c.other_ref_type != 'branch': - other_branch_name = other_scm_instance.get_changeset(c.other_ref_name).branch # use ref_type ? + c.cs_branch_name = c.cs_ref_name + other_scm_instance = c.a_repo.scm_instance + if 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 ? + other_branch_name = c.a_ref_name + if c.a_ref_type != 'branch': + other_branch_name = other_scm_instance.get_changeset(c.a_ref_name).branch # use ref_type ? # candidates: descendants of old head that are on the right branch # and not are the old head itself ... # and nothing at all if old head is a descendent of target ref name @@ -586,26 +586,26 @@ c.update_msg = _('This pull request has already been merged to %s.') % other_branch_name else: # look for children of PR head on source branch in org repo arevs = org_scm_instance._repo.revs('%s:: & branch(%s) - %s', - revs[0], c.org_branch_name, revs[0]) + revs[0], c.cs_branch_name, revs[0]) if arevs: if c.pull_request.is_closed(): - c.update_msg = _('This pull request has been closed and can not be updated with descendent changes on %s:') % c.org_branch_name + c.update_msg = _('This pull request has been closed and can not be updated with descendent changes on %s:') % c.cs_branch_name else: - c.update_msg = _('This pull request can be updated with descendent changes on %s:') % c.org_branch_name + c.update_msg = _('This pull request can be updated with descendent changes on %s:') % c.cs_branch_name c.available = [org_scm_instance.get_changeset(x) for x in arevs] else: c.update_msg = _('No changesets found for updating this pull request.') - revs = org_scm_instance._repo.revs('head() & not (%s::) & branch(%s) & !closed()', revs[0], c.org_branch_name) + revs = org_scm_instance._repo.revs('head() & not (%s::) & branch(%s) & !closed()', revs[0], c.cs_branch_name) if revs: - c.update_msg_other = _('Note: Branch %s also contains unrelated changes, such as %s.') % (c.org_branch_name, + c.update_msg_other = _('Note: Branch %s also contains unrelated changes, such as %s.') % (c.cs_branch_name, h.short_id(org_scm_instance.get_changeset((max(revs))).raw_id)) else: - c.update_msg_other = _('Branch %s does not contain other changes.') % c.org_branch_name + c.update_msg_other = _('Branch %s does not contain other changes.') % c.cs_branch_name raw_ids = [x.raw_id for x in c.cs_ranges] - c.cs_comments = c.org_repo.get_comments(raw_ids) - c.statuses = c.org_repo.statuses(raw_ids) + c.cs_comments = c.cs_repo.get_comments(raw_ids) + c.statuses = c.cs_repo.statuses(raw_ids) ignore_whitespace = request.GET.get('ignorews') == '1' line_context = request.GET.get('context', 3) @@ -616,8 +616,8 @@ # we swap org/other ref since we run a simple diff on one repo log.debug('running diff between %s and %s in %s' - % (c.other_rev, c.org_rev, org_scm_instance.path)) - txtdiff = org_scm_instance.get_diff(rev1=safe_str(c.other_rev), rev2=safe_str(c.org_rev), + % (c.a_rev, c.cs_rev, org_scm_instance.path)) + txtdiff = org_scm_instance.get_diff(rev1=safe_str(c.a_rev), rev2=safe_str(c.cs_rev), ignore_whitespace=ignore_whitespace, context=line_context) diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/templates/changeset/diff_block.html --- a/kallithea/templates/changeset/diff_block.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/changeset/diff_block.html Thu Aug 21 23:46:55 2014 +0200 @@ -78,20 +78,20 @@ ## TODO: link to ancestor and head of other instead of exactly other %if op == 'A': ${_('Added')} - ${h.short_id(c.org_ref_name) if c.org_ref_type=='rev' else c.org_ref_name} + ${h.short_id(c.cs_ref_name) if c.cs_ref_type=='rev' else c.cs_ref_name} %elif op == 'M': - ${h.short_id(c.org_ref_name) if c.org_ref_type=='rev' else c.org_ref_name} + ${h.short_id(c.cs_ref_name) if c.cs_ref_type=='rev' else c.cs_ref_name} - ${h.short_id(c.other_ref_name) if c.other_ref_type=='rev' else c.other_ref_name} + ${h.short_id(c.a_ref_name) if c.a_ref_type=='rev' else c.a_ref_name} %elif op == 'D': ${_('Deleted')} - ${h.short_id(c.other_ref_name) if c.other_ref_type=='rev' else c.other_ref_name} + ${h.short_id(c.a_ref_name) if c.a_ref_type=='rev' else c.a_ref_name} %else: ${op}??? %endif
- + ${c.ignorews_url(request.GET)} @@ -110,11 +110,11 @@
%if op == 'M': + realsrc="${h.url('files_raw_home',repo_name=c.a_repo.repo_name,revision=c.a_rev,f_path=filenode_path) if op in 'DM' else ''}" /> %endif %if op in 'AM': + realsrc="${h.url('files_raw_home',repo_name=c.cs_repo.repo_name,revision=c.cs_rev,f_path=filenode_path) if op in 'AM' else ''}" /> %endif
%endif diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/templates/compare/compare_cs.html --- a/kallithea/templates/compare/compare_cs.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/compare/compare_cs.html Thu Aug 21 23:46:55 2014 +0200 @@ -57,13 +57,13 @@ %if c.as_form:
- ## links should perhaps use ('rev', c.org_rev) instead ... + ## links should perhaps use ('rev', c.a_rev) instead ... ${h.link_to(_('Show merge diff'), h.url('compare_url', - repo_name=c.org_repo.repo_name, - org_ref_type=c.org_ref_type, org_ref_name=c.org_ref_name, - other_repo=c.other_repo.repo_name, - other_ref_type=c.other_ref_type, other_ref_name=c.other_ref_name, + repo_name=c.a_repo.repo_name, + org_ref_type=c.a_ref_type, org_ref_name=c.a_ref_name, + other_repo=c.cs_repo.repo_name, + other_ref_type=c.cs_ref_type, other_ref_name=c.cs_ref_name, merge='1'), )}
@@ -79,11 +79,11 @@ %if c.cs_ranges_org is not None: ## TODO: list actual changesets?
- ${h.link_to_ref(c.other_repo.repo_name, c.other_ref_type, c.other_ref_name, c.other_rev)} + ${h.link_to_ref(c.cs_repo.repo_name, c.cs_ref_type, c.cs_ref_name, c.cs_rev)} ${_('is')} ${_('%s changesets') % (len(c.cs_ranges_org))} ${_('behind')} - ${h.link_to_ref(c.org_repo.repo_name, c.org_ref_type, c.org_ref_name, c.org_rev)} + ${h.link_to_ref(c.a_repo.repo_name, c.a_ref_type, c.a_ref_name, c.a_rev)}
%endif %endif diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/templates/compare/compare_diff.html --- a/kallithea/templates/compare/compare_diff.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/compare/compare_diff.html Thu Aug 21 23:46:55 2014 +0200 @@ -5,7 +5,7 @@ %if c.compare_home: ${_('%s Compare') % c.repo_name} %else: - ${_('%s Compare') % c.repo_name} - ${'%s@%s' % (c.org_repo.repo_name, c.org_ref_name)} > ${'%s@%s' % (c.other_repo.repo_name, c.other_ref_name)} + ${_('%s Compare') % c.repo_name} - ${'%s@%s' % (c.a_repo.repo_name, c.a_ref_name)} > ${'%s@%s' % (c.cs_repo.repo_name, c.cs_ref_name)} %endif %if c.site_name: · ${c.site_name} @@ -97,9 +97,9 @@ $(document).ready(function(){ var cache = {} $("#compare_org").select2({ - placeholder: "${'%s@%s' % (c.org_repo.repo_name, c.org_ref_name)}", + placeholder: "${'%s@%s' % (c.a_repo.repo_name, c.a_ref_name)}", formatSelection: function(obj){ - return '{0}@{1}'.format("${c.org_repo.repo_name}", obj.text) + return '{0}@{1}'.format("${c.a_repo.repo_name}", obj.text) }, dropdownAutoWidth: true, query: function(query){ @@ -124,7 +124,7 @@ query.callback(data); }else{ $.ajax({ - url: pyroutes.url('repo_refs_data', {'repo_name': '${c.org_repo.repo_name}'}), + url: pyroutes.url('repo_refs_data', {'repo_name': '${c.a_repo.repo_name}'}), data: {}, dataType: 'json', type: 'GET', @@ -137,10 +137,10 @@ }, }); $("#compare_other").select2({ - placeholder: "${'%s@%s' % (c.other_repo.repo_name, c.other_ref_name)}", + placeholder: "${'%s@%s' % (c.cs_repo.repo_name, c.cs_ref_name)}", dropdownAutoWidth: true, formatSelection: function(obj){ - return '{0}@{1}'.format("${c.other_repo.repo_name}", obj.text) + return '{0}@{1}'.format("${c.cs_repo.repo_name}", obj.text) }, query: function(query){ var key = 'cache2'; @@ -164,7 +164,7 @@ query.callback(data); }else{ $.ajax({ - url: pyroutes.url('repo_refs_data', {'repo_name': '${c.other_repo.repo_name}'}), + url: pyroutes.url('repo_refs_data', {'repo_name': '${c.cs_repo.repo_name}'}), data: {}, dataType: 'json', type: 'GET', @@ -197,7 +197,7 @@ return; } - var compare_url = "${h.url('compare_url',repo_name=c.repo_name,org_ref_type='__other_ref_type__',org_ref_name='__org__',other_ref_type='__org_ref_type__',other_ref_name='__other__', other_repo=c.other_repo.repo_name)}"; + var compare_url = "${h.url('compare_url',repo_name=c.repo_name,org_ref_type='__other_ref_type__',org_ref_name='__org__',other_ref_type='__org_ref_type__',other_ref_name='__other__', other_repo=c.cs_repo.repo_name)}"; var u = compare_url.replace('__other_ref_type__',org.type) .replace('__org__',org.text) .replace('__org_ref_type__',other.type) diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/templates/pullrequests/pullrequest.html --- a/kallithea/templates/pullrequests/pullrequest.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/pullrequests/pullrequest.html Thu Aug 21 23:46:55 2014 +0200 @@ -56,7 +56,7 @@ ${_('Origin repository')}: ${c.db_repo.description.split('\n')[0]}
- ${h.select('org_repo','',c.org_repos,class_='refs')}:${h.select('org_ref',c.default_org_ref,c.org_refs,class_='refs')} + ${h.select('org_repo','',c.cs_repos,class_='refs')}:${h.select('org_ref',c.default_cs_ref,c.cs_refs,class_='refs')}
${_('Revision')}: - @@ -69,10 +69,10 @@
## filled with JS
- ${_('Destination repository')}: ${c.other_repo.description.split('\n')[0]} + ${_('Destination repository')}: ${c.a_repo.description.split('\n')[0]}
- ${h.select('other_repo',c.other_repo.repo_name,c.other_repos,class_='refs')}:${h.select('other_ref',c.default_other_ref,c.other_refs,class_='refs')} + ${h.select('other_repo',c.a_repo.repo_name,c.a_repos,class_='refs')}:${h.select('other_ref',c.default_a_ref,c.a_refs,class_='refs')}
${_('Revision')}: - @@ -99,7 +99,7 @@ ## members goes here !
    - %for member in [c.other_repo.user]: + %for member in [c.a_repo.user]:
  • gravatar
    diff -r 296b37f6fcdc -r 6cb077e99873 kallithea/templates/pullrequests/pullrequest_show.html --- a/kallithea/templates/pullrequests/pullrequest_show.html Thu Aug 21 23:46:55 2014 +0200 +++ b/kallithea/templates/pullrequests/pullrequest_show.html Thu Aug 21 23:46:55 2014 +0200 @@ -8,7 +8,7 @@ <%def name="breadcrumbs_links()"> - ${_('Pull request #%s from %s#%s') % (c.pull_request.pull_request_id, c.pull_request.org_repo.repo_name, c.org_branch_name)} + ${_('Pull request #%s from %s#%s') % (c.pull_request.pull_request_id, c.pull_request.org_repo.repo_name, c.cs_branch_name)} <%def name="page_nav()"> @@ -116,9 +116,9 @@
    - ${h.link_to_ref(c.pull_request.org_repo.repo_name, c.org_ref_type, c.org_ref_name, c.org_rev)} - %if c.org_ref_type != 'branch': - ${_('on')} ${h.link_to_ref(c.pull_request.org_repo.repo_name, 'branch', c.org_branch_name)} + ${h.link_to_ref(c.pull_request.org_repo.repo_name, c.cs_ref_type, c.cs_ref_name, c.cs_rev)} + %if c.cs_ref_type != 'branch': + ${_('on')} ${h.link_to_ref(c.pull_request.org_repo.repo_name, 'branch', c.cs_branch_name)} %endif
    @@ -129,8 +129,8 @@
- ${h.link_to_ref(c.pull_request.other_repo.repo_name, c.other_ref_type, c.other_ref_name)} - ## we don't know other rev - c.other_rev is ancestor and not necessarily on other_name_branch branch + ${h.link_to_ref(c.pull_request.other_repo.repo_name, c.a_ref_type, c.a_ref_name)} + ## we don't know other rev - c.a_rev is ancestor and not necessarily on other_name_branch branch
@@ -185,7 +185,7 @@ %for cnt, cs in enumerate(reversed(c.available)): ${h.radio(name='updaterev', value=cs.raw_id)} - ${h.link_to(h.show_id(cs),h.url('changeset_home',repo_name=c.org_repo.repo_name,revision=cs.raw_id))} + ${h.link_to(h.show_id(cs),h.url('changeset_home',repo_name=c.cs_repo.repo_name,revision=cs.raw_id))}
${h.urlify_commit(cs.message, c.repo_name)}
%endfor @@ -261,7 +261,7 @@
${_('Common ancestor')}: - ${h.link_to(h.short_id(c.other_rev),h.url('changeset_home',repo_name=c.other_repo.repo_name,revision=c.other_rev))} + ${h.link_to(h.short_id(c.a_rev),h.url('changeset_home',repo_name=c.a_repo.repo_name,revision=c.a_rev))}
## FILES