Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

How to get files for mercurial changeset in rhodecode extension

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...