How to get files for mercurial changeset in rhodecode extension

60 views Asked by At

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.

1

There are 1 answers

1
marcinkuzminski On

This is a problem with Mercurial, and that in rcextensions is unable to see the data "prior" the push inside rcextensions as the objects that see the data are only in internal hooks of Mercurial, and on. We're still investigating this but it seems the logic needs to be moved into hooks itself. For SVN and GIT this works fine