195c195
< def check(self, filename, regions=all_regions):
---
> def check(self, filename, regions=all_regions, fobj=None, silent=False):
197a198,208
> Given that it is possible that the current contents of the file
> differ from the file as 'staged to commit', for those cases, and
> maybe others, the argument fobj should be a file object open and reset
> with the contents matching what the file would look like after the
> commit. This is needed keep the messages using 'filename' meaningful.
>
> The argument silent is useful to prevent output when we run check in
> the staged file vs the actual file to detect if the user forgot
> staging fixes to the commit. This way, we prevent reporting errors
> twice in stderr.
>
219,220c230,234
< def check(self, filename, regions=all_regions):
< f = self.open(filename, 'r')
---
> def check(self, filename, regions=all_regions, fobj=None, silent=False):
> close = False
> if fobj is None:
> fobj = self.open(filename, 'r')
> close = True
226c240
< for num,line in enumerate(f):
---
> for num,line in enumerate(fobj):
231,234c245,249
< self.ui.write("invalid %s in %s:%d\n" % \
< (self.test_name, filename, num + 1))
< if self.ui.verbose:
< self.ui.write(">>%s<<\n" % line[:-1])
---
> if not silent:
> self.ui.write("invalid %s in %s:%d\n" % \
> (self.test_name, filename, num + 1))
> if self.ui.verbose:
> self.ui.write(">>%s<<\n" % line[:-1])
236c251,252
< f.close()
---
> if close:
> fobj.close()
332,333c348,352
< def check(self, filename, regions=all_regions):
< f = self.open(filename, 'r')
---
> def check(self, filename, regions=all_regions, fobj=None, silent=False):
> close = False
> if fobj is None:
> fobj = self.open(filename, 'r')
> close = True
336,337c355,357
< old = [ l.rstrip('\n') for l in f.xreadlines() ]
< f.close()
---
> old = [ l.rstrip('\n') for l in fobj.xreadlines() ]
> if close:
> fobj.close()
348,351c368,373
< self.ui.write("invalid sorting of includes in %s\n" % (filename))
< if self.ui.verbose:
< for start, end in modified.regions:
< self.ui.write("bad region [%d, %d)\n" % (start, end))
---
> if not silent:
> self.ui.write("invalid sorting of includes in %s\n"
> % (filename))
> if self.ui.verbose:
> for start, end in modified.regions:
> self.ui.write("bad region [%d, %d)\n" % (start, end))