changeset 6906:b343a4599178

diffs: cleanup of variable naming around cut_off_limit A brief summary of this area: The base controller sets self.cut_off_limit from config and is used for diffs, unless controllers are given a fulldiff query parameter. In a few cases, these are passed to templates as c.cut_off_limit or c.fulldiff . Also, if the diff function returns a LimitedDiffContainer, c.limited_diff is set so the UI can report the data set is partial.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 03 Oct 2017 00:14:40 +0200
parents ff5c4b26461a
children 71a29042ab8a
files kallithea/controllers/changeset.py kallithea/controllers/compare.py kallithea/controllers/feed.py kallithea/controllers/files.py kallithea/controllers/pullrequests.py kallithea/lib/diffs.py
diffstat 6 files changed, 18 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/changeset.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/controllers/changeset.py	Tue Oct 03 00:14:40 2017 +0200
@@ -206,7 +206,7 @@
         c.anchor_url = anchor_url
         c.ignorews_url = _ignorews_url
         c.context_url = _context_url
-        c.fulldiff = fulldiff = request.GET.get('fulldiff')
+        c.fulldiff = request.GET.get('fulldiff') # for reporting number of changed files
         # get ranges of revisions if preset
         rev_range = revision.split('...')[:2]
         enable_comments = True
@@ -273,7 +273,7 @@
 
             _diff = c.db_repo_scm_instance.get_diff(cs1, cs2,
                 ignore_whitespace=ign_whitespace_lcl, context=context_lcl)
-            diff_limit = self.cut_off_limit if not fulldiff else None
+            diff_limit = None if c.fulldiff else self.cut_off_limit
             diff_processor = diffs.DiffProcessor(_diff,
                                                  vcs=c.db_repo_scm_instance.alias,
                                                  format='gitdiff',
--- a/kallithea/controllers/compare.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/controllers/compare.py	Tue Oct 03 00:14:40 2017 +0200
@@ -189,7 +189,7 @@
         #   Changesets in one and not in the other will be ignored
         merge = bool(request.GET.get('merge'))
         # fulldiff disables cut_off_limit
-        c.fulldiff = request.GET.get('fulldiff')
+        fulldiff = request.GET.get('fulldiff')
         # partial uses compare_cs.html template directly
         partial = request.environ.get('HTTP_X_PARTIAL_XHR')
         # is_ajax_preview puts hidden input field with changeset revisions
@@ -263,7 +263,7 @@
                 raise HTTPBadRequest
             rev1 = c.a_rev
 
-        diff_limit = self.cut_off_limit if not c.fulldiff else None
+        diff_limit = None if fulldiff else self.cut_off_limit
 
         log.debug('running diff between %s and %s in %s',
                   rev1, c.cs_rev, org_repo.scm_instance.path)
--- a/kallithea/controllers/feed.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/controllers/feed.py	Tue Oct 03 00:14:40 2017 +0200
@@ -61,9 +61,9 @@
 
     def __changes(self, cs):
         changes = []
-        rss_cut_off_limit = safe_int(CONFIG.get('rss_cut_off_limit', 32 * 1024))
+        diff_limit = safe_int(CONFIG.get('rss_cut_off_limit', 32 * 1024))
         diff_processor = DiffProcessor(cs.diff(),
-                                       diff_limit=rss_cut_off_limit)
+                                       diff_limit=diff_limit)
         _parsed = diff_processor.prepare(inline_diff=False)
         limited_diff = False
         if isinstance(_parsed, LimitedDiffContainer):
--- a/kallithea/controllers/files.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/controllers/files.py	Tue Oct 03 00:14:40 2017 +0200
@@ -71,7 +71,6 @@
 
     def _before(self, *args, **kwargs):
         super(FilesController, self)._before(*args, **kwargs)
-        c.cut_off_limit = self.cut_off_limit
 
     def __get_cs(self, rev, silent_empty=False):
         """
@@ -138,6 +137,8 @@
         c.f_path = f_path
         c.annotate = annotate
         cur_rev = c.changeset.revision
+        # used in files_source.html:
+        c.cut_off_limit = self.cut_off_limit
         c.fulldiff = request.GET.get('fulldiff')
 
         # prev link
@@ -593,6 +594,7 @@
         c.no_changes = diff1 == diff2
         c.f_path = f_path
         c.big_diff = False
+        fulldiff = request.GET.get('fulldiff')
         c.anchor_url = anchor_url
         c.ignorews_url = _ignorews_url
         c.context_url = _context_url
@@ -674,10 +676,10 @@
             line_context_lcl = get_line_ctx(fid, request.GET)
             ign_whitespace_lcl = get_ignore_ws(fid, request.GET)
 
-            lim = request.GET.get('fulldiff') or self.cut_off_limit
+            diff_limit = None if fulldiff else self.cut_off_limit
             c.a_rev, c.cs_rev, a_path, diff, st, op = diffs.wrapped_diff(filenode_old=node1,
                                          filenode_new=node2,
-                                         cut_off_limit=lim,
+                                         diff_limit=diff_limit,
                                          ignore_whitespace=ign_whitespace_lcl,
                                          line_context=line_context_lcl,
                                          enable_comments=False)
--- a/kallithea/controllers/pullrequests.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/controllers/pullrequests.py	Tue Oct 03 00:14:40 2017 +0200
@@ -585,8 +585,8 @@
         line_context = safe_int(request.GET.get('context'), 3)
         c.ignorews_url = _ignorews_url
         c.context_url = _context_url
-        c.fulldiff = request.GET.get('fulldiff')
-        diff_limit = self.cut_off_limit if not c.fulldiff else None
+        fulldiff = request.GET.get('fulldiff')
+        diff_limit = None if fulldiff else self.cut_off_limit
 
         # we swap org/other ref since we run a simple diff on one repo
         log.debug('running diff between %s and %s in %s',
--- a/kallithea/lib/diffs.py	Mon Oct 02 23:44:49 2017 +0200
+++ b/kallithea/lib/diffs.py	Tue Oct 03 00:14:40 2017 +0200
@@ -51,11 +51,11 @@
               </table>''' % str_
 
 
-def wrapped_diff(filenode_old, filenode_new, cut_off_limit=None,
+def wrapped_diff(filenode_old, filenode_new, diff_limit=None,
                 ignore_whitespace=True, line_context=3,
                 enable_comments=False):
     """
-    returns a wrapped diff into a table, checks for cut_off_limit and presents
+    returns a wrapped diff into a table, checks for diff_limit and presents
     proper message
     """
 
@@ -68,9 +68,9 @@
         diff = wrap_to_table(_('Binary file'))
         stats = (0, 0)
 
-    elif cut_off_limit != -1 and (
-            cut_off_limit is None or
-            (filenode_old.size < cut_off_limit and filenode_new.size < cut_off_limit)):
+    elif diff_limit != -1 and (
+            diff_limit is None or
+            (filenode_old.size < diff_limit and filenode_new.size < diff_limit)):
 
         f_gitdiff = get_gitdiff(filenode_old, filenode_new,
                                 ignore_whitespace=ignore_whitespace,