Søren Løvborg avatar Søren Løvborg committed 3b8498b

Since ctx can be None in CheckFiles.__init__, move the context-dependent code to a separate CheckFiles.set_context method.

Comments (0)

Files changed (1)

 
 class CheckFiles(object):
     def __init__(self, ui, repo, ctx, opts = {}):
-        self.ctx = ctx
         self.ui = ui
         self.repo = repo
 
         if 'tabsize' in opts:
             self.tab_size = int(opts['tabsize'])
 
-        if 'all' in opts and opts['all']:
-            modified, added, removed, deleted, unknown, ignored, clean = repo.status(clean=True)
-            self.files = modified + added + clean # we can't get filecontext for unknown files
+        self.opt_all = opts.get('all', False)
+
+        if self.opt_all:
             self.check_diffs = False
-        else:
-            self.files = ctx.files()
 
         if self.checked_exts == '""':
             self.ui.debug('checkfiles: checked extensions: (all text files)\n')
         self.ui.debug('checkfiles: check diffs only: %r\n' % self.check_diffs)
         self.ui.debug('checkfiles: use spaces: %r\n' % self.use_spaces)
 
+        if ctx:
+            self.set_changectx(ctx)
+
+    def set_changectx(self, ctx):
+        self.ctx = ctx
+
+        if self.opt_all:
+            modified, added, removed, deleted, unknown, ignored, clean = self.repo.status(clean=True)
+            self.files = modified + added + clean # we can't get filecontext for unknown files
+        else:
+            self.files = ctx.files()
+
         self.ui.debug('checkfiles: considering files:\n  %s\n' % '\n  '.join(self.files))
 
     def is_relevant(self, file):
         fail = False
 
         for rev in cmdutil.revrange(repo, ['%s::' % node]):
-            cf.ctx = repo.changectx(rev)
+            cf.set_changectx(repo.changectx(rev))
             fail = cf.check() or fail
 
         return fail
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.