Overloading the pull command in the Hg extension

I am trying to debug Mercurial extension. This extension adds code that must be executed when executed pull. The original author sets this hook by changing the class of the repository object.

Here is the relevant code (which is actually a valid Mercurial extension):

def reposetup(ui, repo):
    class myrepo(repo.__class__):
        def pull(self, remote, heads=None, force=False):
            print "pull called"
            return super(myrepo, self).pull(remote, heads, force)

    print "reposetup called"
    if repo.local():
        print "repo is local"
        repo.__class__ = myrepo

When I run hg pullwith the extension turned on, here is the output:

# hg pull
reposetup called
repo is local
pulling from ssh://hgbox/myrepo
reposetup called
searching for changes
no changes found

Is this a smart way to enter extension code into a command pull? Why has the so-called “push” never been achieved?

I am using Mercurial 3.4.1 for Windows 7 with python 2.7.5.

+4
source share
1 answer

(mercurial/extensions.py) (https://www.mercurial-scm.org/repo/hg/file/ff5172c83002/mercurial/extensions.py#l227).

, , localrepo, , pull, , "pull called" print - , !

pulls, , . , - , , exchange.pull:

extensions.wrapfunction(exchange, 'pull', my_pull_function)

:

def expull(orig, repo, remote, *args, **kwargs):
    transferprojrc(repo.ui, repo, remote)
    return orig(repo, remote, *args, **kwargs)

extsetup :

extensions.wrapfunction(exchange, 'pull', expull)

, reposetup projrcrepo. , , .

+5

All Articles