Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 487:2ad41189bee5
Add initial hook support
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Add initial hook support
This adds the basic hook code as well as pre and post-commit hooks.
Argument passing is by environment variable key/value pairs so that
extra data can be passed over time. File lists will generally not be
passed to hooks as these can be extremely long (>1M).
manifest hash: 45cf9bab432782c391bc9c1c048c84cc75d52740
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCwOukywK+sNU5EO8RAsVsAJ9QipR2aKRSSvoRNo+3If6JddUDkwCgkZrM
KEmZpUOxhNHqezFVrHDRTjE=
=aedm
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Mon, 27 Jun 2005 22:18:12 -0800 |
parents | 934279f3ca53 |
children | e94cebc60d96 |
comparison
equal
deleted
inserted
replaced
486:098d1f039c18 | 487:2ad41189bee5 |
---|---|
368 self.ignorelist.append(re.compile(util.pconvert(pat[:-1]))) | 368 self.ignorelist.append(re.compile(util.pconvert(pat[:-1]))) |
369 except IOError: pass | 369 except IOError: pass |
370 for pat in self.ignorelist: | 370 for pat in self.ignorelist: |
371 if pat.search(f): return True | 371 if pat.search(f): return True |
372 return False | 372 return False |
373 | |
374 def hook(self, name, **args): | |
375 s = self.ui.config("hooks", name) | |
376 if s: | |
377 self.ui.note("running hook %s: %s\n" % (name, s)) | |
378 old = {} | |
379 for k, v in args.items(): | |
380 k = k.upper() | |
381 old[k] = os.environ.get(k, None) | |
382 os.environ[k] = v | |
383 | |
384 r = os.system(s) | |
385 | |
386 for k, v in old.items(): | |
387 if v != None: | |
388 os.environ[k] = v | |
389 else: | |
390 del os.environ[k] | |
391 | |
392 if r: | |
393 self.ui.warn("abort: %s hook failed with status %d!\n" % | |
394 (name, r)) | |
395 return False | |
396 return True | |
373 | 397 |
374 def tags(self): | 398 def tags(self): |
375 '''return a mapping of tag to node''' | 399 '''return a mapping of tag to node''' |
376 if not self.tagscache: | 400 if not self.tagscache: |
377 self.tagscache = {} | 401 self.tagscache = {} |
546 | 570 |
547 if not commit and not remove: | 571 if not commit and not remove: |
548 self.ui.status("nothing changed\n") | 572 self.ui.status("nothing changed\n") |
549 return | 573 return |
550 | 574 |
575 if not self.hook("precommit"): | |
576 return 1 | |
577 | |
551 p1, p2 = self.dirstate.parents() | 578 p1, p2 = self.dirstate.parents() |
552 c1 = self.changelog.read(p1) | 579 c1 = self.changelog.read(p1) |
553 c2 = self.changelog.read(p2) | 580 c2 = self.changelog.read(p2) |
554 m1 = self.manifest.read(c1[0]) | 581 m1 = self.manifest.read(c1[0]) |
555 mf1 = self.manifest.readflags(c1[0]) | 582 mf1 = self.manifest.readflags(c1[0]) |
601 if not edittext.rstrip(): | 628 if not edittext.rstrip(): |
602 return 1 | 629 return 1 |
603 text = edittext | 630 text = edittext |
604 | 631 |
605 n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) | 632 n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) |
633 | |
634 if not self.hook("commit", node=hex(n)): | |
635 return 1 | |
636 | |
606 tr.close() | 637 tr.close() |
607 | 638 |
608 self.dirstate.setparents(n) | 639 self.dirstate.setparents(n) |
609 self.dirstate.update(new, "n") | 640 self.dirstate.update(new, "n") |
610 self.dirstate.forget(remove) | 641 self.dirstate.forget(remove) |