2012-04-04 78 views
1

我建立了一個遠程Mercurial(Hg)存儲庫,它包含一個大的Java項目。我想監視對項目的pom文件所做的任何更改,並在對pom進行更改時收到電子郵件。如何監視特定文件以查看Mercurial中的更改?

我想從通知中排除所有其他文件更改,因爲我只對監視依賴關係(即POM)中的任何可能更改感興趣。是否有任何Mercurial擴展或解決方法使用Jenkins訂閱Mercurial回購庫內的單個文件的更改歷史記錄?

回答

2

notify extension發送電子郵件回購更改。

Change Context(請參閱第6節)爲您提供了一種迭代變更集中文件的方法。

把這兩樣東西放到一個自定義鉤子中應該相當簡單。如果您提到特殊文件,請查看上下文並僅發送電子郵件。

+0

看起來如此:)但是您能否描述更詳細的操作方法?據我瞭解,我應該重寫 changegroup.notify = python:hgext.notify.hook 與我的鉤子的代碼。 但是,如果發現目標文件被更改,我怎麼能從我的代碼中調用原始的「hgext.notify.hook」? – 2014-05-28 13:51:54

0

@ Ed.ward

最近,我不得不這樣做,如果某些文件改變(結合與變化背景下的通知擴展)只通知。 爲了從您自己的掛鉤中調用通知掛鉤,您需要導入hgext,然後調用hgext.notify.hook。我的python工作示例:

import re, traceback 
import hgext 
def check_changegroup(ui, repo, hooktype, node=None, source=None, **kwargs): 
    ui.note("Checking for files in %s with path: %s\n" % (repo.__class__.__name__, repo.root)) 
    file_match = ".*base.*" #ui.config('monitor_files', 'file_match') 
    ui.note("file_match: %s\n" % file_match) 
    file_match_re = re.compile(file_match, re.I) 
    monitored_file_changed = False 
    for rev in xrange(repo[node].rev(), len(repo)): 
     changectx = repo[rev]  
     for f in changectx.files(): 
      if file_match_re.match(f): 
       ui.note(" matched: %s\n" % f) 
       monitored_file_changed = True 
     if monitored_file_changed: 
      ui.note("rev: %s from user: %s has changes on monitored files\n" % (rev, changectx.user())) 
    if monitored_file_changed: 
     ui.note("calling notify hook\n") 
     try: 
      hgext.notify.hook(ui, repo, hooktype, node, source) 
     except Exception as exc: 
      ui.warn(('%s error calling notify hook: %s\n') % (exc.__class__.__name__, exc)) 
      traceback.print_exc() 
      raise