如何监视特定文件以查看Mercurial中的更改?

问题描述:

我建立了一个远程Mercurial(Hg)存储库,它包含一个大的Java项目。我想监视对项目的pom文件所做的任何更改,并在对pom进行更改时收到电子邮件。如何监视特定文件以查看Mercurial中的更改?

我想从通知中排除所有其他文件更改,因为我只对监视依赖关系(即POM)中的任何可能更改感兴趣。是否有任何Mercurial扩展或解决方法使用Jenkins订阅Mercurial回购库内的单个文件的更改历史记录?

notify extension发送电子邮件回购更改。

Change Context(请参阅第6节)为您提供了一种迭代变更集中文件的方法。

把这两样东西放到一个自定义钩子中应该相当简单。如果您提到特殊文件,请查看上下文并仅发送电子邮件。

+0

看起来如此:)但是您能否描述更详细的操作方法?据我了解,我应该重写 changegroup.notify = python:hgext.notify.hook 与我的钩子的代码。 但是,如果发现目标文件被更改,我怎么能从我的代码中调用原始的“hgext.notify.hook”? – 2014-05-28 13:51:54

@ 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