我正在嘗試調試Mercurial擴展。這個擴展添加了一些執行pull
時應該執行的代碼。原作者通過更改存儲庫對象的類來設置此掛鉤。在Hg擴展中重載拉命令
下面是相關的代碼(這實際上是一個有效的水銀擴展名):
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
當我執行與本擴展的hg pull
啓用,這裏是輸出:
# hg pull
reposetup called
repo is local
pulling from ssh://hgbox/myrepo
reposetup called
searching for changes
no changes found
這是在pull
命令中注入擴展代碼的合理方法?爲什麼「拉來電」的聲明從未達到過?
我在Windows 7上使用Mercurial 3.4.1與python 2.7.5。
感謝您的回答。我試圖用你的建議來調整代碼,但目前爲止沒有成功(我不是Python開發人員,有時候我有點失落)。實際上,我試圖完成的是讓projrc擴展工作。我提交了[問題](https://bitbucket.org/aragost/projrc/issue/2/no-projrc-update-on-pull#comment-18753387)描述了我的問題,但由於我沒有得到反饋我試圖自己修復它(在SO的幫助下,顯然!)。 – barjak
我檢出了mercurial的代碼,並且在localrepo類中沒有看到任何拉出方法,這可能是爲什麼代碼沒有運行的更好解釋。現在我會更新我的答案,提供一些更具體的想法,我知道你想要完成什麼。 – ryanmce
感謝您的跟進。我可以按照你使用'exchange :: pull'的建議來工作。我爲Projrc項目創建了一個[pull request](https://bitbucket.org/aragost/projrc/pull-request/5/make-projrc-compatible-with-mercurial-32/diff)。你介意看看我的差異,並告訴我,如果你認爲沒關係? – barjak