Mercurial > kallithea
changeset 6909:54199f3aab93
diffs: drop the noop as_raw method - just use the raw diff directly and with proper variable naming
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Tue, 03 Oct 2017 00:14:40 +0200 |
parents | 791430c43bca |
children | 0c19e4661b71 |
files | kallithea/controllers/changeset.py kallithea/controllers/feed.py kallithea/controllers/files.py kallithea/lib/diffs.py |
diffstat | 4 files changed, 26 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/changeset.py Tue Oct 03 00:14:40 2017 +0200 @@ -271,14 +271,14 @@ context_lcl = get_line_ctx('', request.GET) ign_whitespace_lcl = get_ignore_ws('', request.GET) - _diff = c.db_repo_scm_instance.get_diff(cs1, cs2, + raw_diff = c.db_repo_scm_instance.get_diff(cs1, cs2, ignore_whitespace=ign_whitespace_lcl, context=context_lcl) diff_limit = None if c.fulldiff else self.cut_off_limit - diff_processor = diffs.DiffProcessor(_diff, - vcs=c.db_repo_scm_instance.alias, - diff_limit=diff_limit) file_diff_data = [] if method == 'show': + diff_processor = diffs.DiffProcessor(raw_diff, + vcs=c.db_repo_scm_instance.alias, + diff_limit=diff_limit) _parsed = diff_processor.prepare() c.limited_diff = False if isinstance(_parsed, LimitedDiffContainer): @@ -295,8 +295,7 @@ file_diff_data.append((fid, url_fid, f['operation'], f['old_filename'], filename, diff, st)) else: # downloads/raw we only need RAW diff nothing else - diff = diff_processor.as_raw() - file_diff_data.append(('', None, None, None, diff, None)) + file_diff_data.append(('', None, None, None, raw_diff, None)) c.changes[changeset.raw_id] = (cs1, cs2, file_diff_data) # sort comments in creation order @@ -315,14 +314,14 @@ response.content_type = 'text/plain' response.content_disposition = 'attachment; filename=%s.diff' \ % revision[:12] - return diff + return raw_diff elif method == 'patch': response.content_type = 'text/plain' - c.diff = safe_unicode(diff) + c.diff = safe_unicode(raw_diff) return render('changeset/patch_changeset.html') elif method == 'raw': response.content_type = 'text/plain' - return diff + return raw_diff elif method == 'show': self.__load_data() if len(c.cs_ranges) == 1:
--- a/kallithea/controllers/feed.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/feed.py Tue Oct 03 00:14:40 2017 +0200 @@ -59,10 +59,21 @@ def _get_title(self, cs): return h.shorter(cs.message, 160) - def __changes(self, cs): + def __get_desc(self, cs): + desc_msg = [(_('%s committed on %s') + % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>'] + # branches, tags, bookmarks + if cs.branch: + desc_msg.append('branch: %s<br/>' % cs.branch) + for book in cs.bookmarks: + desc_msg.append('bookmark: %s<br/>' % book) + for tag in cs.tags: + desc_msg.append('tag: %s<br/>' % tag) + changes = [] diff_limit = safe_int(CONFIG.get('rss_cut_off_limit', 32 * 1024)) - diff_processor = DiffProcessor(cs.diff(), + raw_diff = cs.diff() + diff_processor = DiffProcessor(raw_diff, diff_limit=diff_limit) _parsed = diff_processor.prepare(inline_diff=False) limited_diff = False @@ -78,19 +89,7 @@ if limited_diff: changes = changes + ['\n ' + _('Changeset was too big and was cut off...')] - return diff_processor, changes - def __get_desc(self, cs): - desc_msg = [(_('%s committed on %s') - % (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>'] - # branches, tags, bookmarks - if cs.branch: - desc_msg.append('branch: %s<br/>' % cs.branch) - for book in cs.bookmarks: - desc_msg.append('bookmark: %s<br/>' % book) - for tag in cs.tags: - desc_msg.append('tag: %s<br/>' % tag) - diff_processor, changes = self.__changes(cs) # rev link _url = h.canonical_url('changeset_home', repo_name=c.db_repo.repo_name, revision=cs.raw_id) @@ -102,7 +101,7 @@ desc_msg.extend(changes) if str2bool(CONFIG.get('rss_include_diff', False)): desc_msg.append('\n\n') - desc_msg.append(diff_processor.as_raw()) + desc_msg.append(raw_diff) desc_msg.append('</pre>') return map(safe_unicode, desc_msg)
--- a/kallithea/controllers/files.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/controllers/files.py Tue Oct 03 00:14:40 2017 +0200 @@ -651,25 +651,22 @@ f_path=f_path)) if c.action == 'download': - _diff = diffs.get_gitdiff(node1, node2, + raw_diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context) - diff = diffs.DiffProcessor(_diff) - diff_name = '%s_vs_%s.diff' % (diff1, diff2) response.content_type = 'text/plain' response.content_disposition = ( 'attachment; filename=%s' % diff_name ) - return diff.as_raw() + return raw_diff elif c.action == 'raw': - _diff = diffs.get_gitdiff(node1, node2, + raw_diff = diffs.get_gitdiff(node1, node2, ignore_whitespace=ignore_whitespace, context=line_context) - diff = diffs.DiffProcessor(_diff) response.content_type = 'text/plain' - return diff.as_raw() + return raw_diff else: fid = h.FID(diff2, node2.path)
--- a/kallithea/lib/diffs.py Tue Oct 03 00:14:40 2017 +0200 +++ b/kallithea/lib/diffs.py Tue Oct 03 00:14:40 2017 +0200 @@ -592,12 +592,6 @@ self.parsed_diff = parsed return parsed - def as_raw(self): - """ - Returns raw string diff, exactly as it was passed in the first place. - """ - return self._diff - def as_html(self, table_class='code-difftable', line_class='line', old_lineno_class='lineno old', new_lineno_class='lineno new', no_lineno_class='lineno',