2013-05-02 24 views
0

我是Mercurial的新手,我正在編寫一個標籤鉤以檢查標籤名稱上的策略。Mercurial預標籤鉤甚至用--remove選項

我有以下代碼。

version_re = r'(ver-\d+\.\d+\.\d+|tip)$' 
def invalidtag(ui, repo, hooktype, node, tag, **kwargs): 
assert(hooktype == 'pretag') 

.... 


if not re_.match(tag): 
    ui.warn('Invalid tag name "%s".\n' % tag) 
    return True 
return False 

這個掛鉤在我標記時非常完美。但是當我想用--remove選項去除無效標籤時,這個鉤子也會被執行。

那麼,有什麼辦法可以避免他的情況?

回答

0

當標記標記爲刪除時,傳遞給鉤子的節點是來自mercurial.node的nullid。 所以你應該能夠檢查這個節點是否來自mercurial.node的nullid。

您應該使用mercurial.node中的「hex」函數將節點轉換爲十六進制表示形式。這個十六進制函數與python中的內置函數有不同的行爲。