mercurial/localrepo.py
changeset 1480 ae0d8d632b83
parent 1477 d3566eda2bcb
child 1492 5f0522d31967
equal deleted inserted replaced
1479:1a3c6689ef2b 1480:ae0d8d632b83
    45         try:
    45         try:
    46             self.ui.readconfig(os.path.join(self.path, "hgrc"))
    46             self.ui.readconfig(os.path.join(self.path, "hgrc"))
    47         except IOError: pass
    47         except IOError: pass
    48 
    48 
    49     def hook(self, name, **args):
    49     def hook(self, name, **args):
    50         s = self.ui.config("hooks", name)
    50         def runhook(name, cmd):
    51         if s:
    51             self.ui.note(_("running hook %s: %s\n") % (name, cmd))
    52             self.ui.note(_("running hook %s: %s\n") % (name, s))
       
    53             old = {}
    52             old = {}
    54             for k, v in args.items():
    53             for k, v in args.items():
    55                 k = k.upper()
    54                 k = k.upper()
    56                 old[k] = os.environ.get(k, None)
    55                 old[k] = os.environ.get(k, None)
    57                 os.environ[k] = v
    56                 os.environ[k] = v
    58 
    57 
    59             # Hooks run in the repository root
    58             # Hooks run in the repository root
    60             olddir = os.getcwd()
    59             olddir = os.getcwd()
    61             os.chdir(self.root)
    60             os.chdir(self.root)
    62             r = os.system(s)
    61             r = os.system(cmd)
    63             os.chdir(olddir)
    62             os.chdir(olddir)
    64 
    63 
    65             for k, v in old.items():
    64             for k, v in old.items():
    66                 if v != None:
    65                 if v != None:
    67                     os.environ[k] = v
    66                     os.environ[k] = v
    70 
    69 
    71             if r:
    70             if r:
    72                 self.ui.warn(_("abort: %s hook failed with status %d!\n") %
    71                 self.ui.warn(_("abort: %s hook failed with status %d!\n") %
    73                              (name, r))
    72                              (name, r))
    74                 return False
    73                 return False
    75         return True
    74             return True
       
    75 
       
    76         r = True
       
    77         for hname, cmd in self.ui.configitems("hooks"):
       
    78             s = hname.split(".")
       
    79             if s[0] == name and cmd:
       
    80                 r = runhook(hname, cmd) and r
       
    81         return r
    76 
    82 
    77     def tags(self):
    83     def tags(self):
    78         '''return a mapping of tag to node'''
    84         '''return a mapping of tag to node'''
    79         if not self.tagscache:
    85         if not self.tagscache:
    80             self.tagscache = {}
    86             self.tagscache = {}