Find filenames for mercurial hook

Extract the files changed in a particular commit or set of commits
for the commit and qrefresh mercurial hooks.
This commit is contained in:
Ian Cordasco 2016-06-16 07:20:09 -05:00
parent eff77e2bc2
commit 023de21fe2
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A

View file

@ -32,8 +32,10 @@ def hook(ui, repo, **kwargs):
hgconfig = configparser_for(hgrc)
strict = hgconfig.get('flake8', 'strict', fallback=True)
filenames = list(get_filenames_from(repo, kwargs))
app = application.Application()
app.run()
app.run(filenames)
if strict:
return app.result_count
@ -78,6 +80,22 @@ def install():
return True
def get_filenames_from(repository, kwargs):
seen_filenames = set()
node = kwargs['node']
for revision in range(repository[node], len(repository)):
for filename in repository[revision].files():
full_filename = os.path.join(repository.root, filename)
have_seen_filename = full_filename in seen_filenames
filename_does_not_exist = not os.path.exists(full_filename)
if have_seen_filename or filename_does_not_exist:
continue
seen_filenames.add(full_filename)
if full_filename.endswith('.py'):
yield full_filename
def find_hgrc(create_if_missing=False):
root = subprocess.Popen(
['hg', 'root'],