[PATCH 11 of 15] Handle repositories that are not in the configfile, by showing a http 404

vincent at ricardis.tudelft.nl vincent at ricardis.tudelft.nl
Wed Aug 24 16:49:19 CDT 2005


not found error.


# HG changeset patch
# User Vincent Wagelaar <vincent at ricardis.tudelft.nl>
# Node ID 62ea868cafbfa3acb7e5dba6982ecb46a1637246
# Parent  db5cb7b9b646e0f7f2a822b0d269f3b598f76c23
Handle repositories that are not in the configfile, by showing a http 404
not found error.

diff -r db5cb7b9b646 -r 62ea868cafbf mercurial/hgweb.py
--- a/mercurial/hgweb.py	Tue Aug 23 22:57:34 2005
+++ b/mercurial/hgweb.py	Wed Aug 24 11:22:18 2005
@@ -55,6 +55,10 @@
 
 def httphdr(fd, type):
     fd.write('Content-type: %s\n\n' % type)
+
+def httpnotfound(fd, filename):
+    out.write("Status: 404\r\n\r\n")
+    out.write("File not found: (%s)" % (filename, ))
 
 def write(stdout, fd, *things):
     for thing in things:
@@ -844,11 +848,17 @@
         except:
             virtual = ""
 
-        if virtual:
-            real = self.cp.get("paths", virtual[1:])
-            h = hgweb(real)
-            h.run()
-            return
+        virtual = virtual.strip('/')
+
+        if len(virtual):
+            try:
+                real = self.cp.get("paths", virtual)
+                h = hgweb(real)
+                h.run()
+                return
+            except NoOptionError:
+                httpnotfound(stdout, virtual)
+                return
 
         def header(**map):
             yield tmpl("header", **map)


More information about the Mercurial mailing list