pretxnchangegroup hook on http server

Alexis S. L. Carvalho alexis at cecm.usp.br
Fri Feb 9 05:55:14 UTC 2007


Thus spake Teemu Torma:
> I tried installing a pretxnchangegroup hook on a repo served by 
> hgweb.cgi to prevent creating new heads on the repo with push -f.  The 
> hook uses hg heads to see if more than one head is present.
> 
> In local repo test the hook works fine and prevents push creating new 
> heads, but with hgweb.cgi the push -f fails to the client 
> with "abort: .. does not appear to be an hg repository" and leaves the 
> server repository in interrupted transaction state.  After hg recover, 
> the push appears to have succeeded and the repository now has two 
> heads.
> 
> Am I doing something wrong, or missing something?

This looks like a bug - I've filed it as
http://www.selenic.com/mercurial/bts/issue499

The attached patch (for the server) makes things work, but I think it
hides a somewhat more subtle problem.

Alexis
-------------- next part --------------
diff -r 5b1f663ef86d mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Tue Feb 06 16:12:22 2007 -0600
+++ b/mercurial/hgweb/hgweb_mod.py	Fri Feb 09 03:54:30 2007 -0200
@@ -1130,8 +1130,12 @@ class hgweb(object):
                 try:
                     url = 'remote:%s:%s' % (proto,
                                             req.env.get('REMOTE_HOST', ''))
-                    ret = self.repo.addchangegroup(util.chunkbuffer(gen),
-                                                   'serve', url)
+                    try:
+                        ret = self.repo.addchangegroup(util.chunkbuffer(gen),
+                                                       'serve', url)
+                    except util.Abort, inst:
+                        sys.stdout.write("abort: %s\n" % inst)
+                        ret = 0
                 finally:
                     val = sys.stdout.getvalue()
                     sys.stdout = old_stdout


More information about the Mercurial mailing list