I've enabled the rcextensions for rhodecode, and copied the example _pre_push_hook which should allow validating the file sizes, e.g. to reject any files if they are larger than a given size.
I found the hook wasn't working: it was allowing all files regardless of their size, and after some digging I found that the relevant helper function is missing an implementation for mercurial:
def get_hg_files(repo, vcs_repo, refs):
files = []
return files
Can anyone suggest how this function should be implemented, to get info for files in the new changesets?
I've tried adapting the equivalent git helper function, noting that mercurial repository objects include a more convenient get_diff method. But I cannot successfully get the relevant commits for the repo, I guess because they are not yet added to the repo.
def get_hg_files(repo, vcs_repo, refs):
files = []
for data in refs:
old_rev = data['old_rev']
new_rev = data['new_rev']
# These fail, as the commit is not found
old_commit = vcs_repo.get_commit(old_rev)
new_commit = vcs_repo.get_commit(new_rev)
vcs_diff = vcs_repo.get_diff(old_commit, new_commit)
diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
files = _parsed = diff_processor.prepare()
return files
I realise that I could use a pure mercurial hook as an alternative, but I'm interested in using a rhodecode hook here.
question from:
https://stackoverflow.com/questions/65866589/how-to-get-files-for-mercurial-changeset-in-rhodecode-extension 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…