Patchwork [2,of,3] hgweb: overwrite cwd to resolve file patterns relative to repo (issue4568)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 22, 2015, 9:27 a.m.
Message ID <1fd00d367894b351a5f6.1442914038@mimosa>
Download mbox | patch
Permalink /patch/10575/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 22, 2015, 9:27 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1442747491 -32400
#      Sun Sep 20 20:11:31 2015 +0900
# Node ID 1fd00d367894b351a5f6110eb7ed5b67d233846c
# Parent  070f6327fd0155d32712d01881432c01f43a2da5
hgweb: overwrite cwd to resolve file patterns relative to repo (issue4568)

It's useless to handle file patterns as relative to the cwd of the server
process. The only sensible way in hgweb is to resolve paths relative to the
repository root.

It seems dirstate.getcwd() isn't used to get a real file path, so this patch
won't cause problem.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -42,6 +42,10 @@  class dirstate(object):
         # ntpath.join(root, '') of Python 2.7.9 does not add sep if root is
         # UNC path pointing to root share (issue4557)
         self._rootdir = pathutil.normasprefix(root)
+        # internal config: ui.forcecwd
+        forcecwd = ui.config('ui', 'forcecwd')
+        if forcecwd:
+            self._cwd = forcecwd
         self._dirty = False
         self._dirtypl = False
         self._lastnormaltime = 0
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -205,6 +205,9 @@  class hgweb(object):
         r.baseui.setconfig('ui', 'report_untrusted', 'off', 'hgweb')
         r.ui.setconfig('ui', 'nontty', 'true', 'hgweb')
         r.baseui.setconfig('ui', 'nontty', 'true', 'hgweb')
+        # resolve file patterns relative to repo root
+        r.ui.setconfig('ui', 'forcecwd', r.root, 'hgweb')
+        r.baseui.setconfig('ui', 'forcecwd', r.root, 'hgweb')
         # displaying bundling progress bar while serving feel wrong and may
         # break some wsgi implementation.
         r.ui.setconfig('progress', 'disable', 'true', 'hgweb')
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -2050,6 +2050,35 @@  Static files
   	top: -1px;
   }
 
+Stop and restart the server at the directory different from the repository
+root. Even in such case, file patterns should be resolved relative to the
+repository root. (issue4568)
+
+  $ killdaemons.py
+  $ hg serve --config server.preferuncompressed=True -n test \
+  > -p $HGPORT -d --pid-file=`pwd`/hg.pid -E `pwd`/errors.log \
+  > --cwd .. -R `pwd`
+  $ cat hg.pid >> $DAEMON_PIDS
+
+  $ get-with-headers.py 127.0.0.1:$HGPORT 'log?rev=adds("foo")&style=raw'
+  200 Script output follows
+  
+  
+  # HG changesets search
+  # Node ID cad8025a2e87f88c06259790adfa15acb4080123
+  # Query "adds("foo")"
+  # Mode revset expression search
+  
+  changeset:   2ef0ac749a14e4f57a5a822464a0902c6f7f448f
+  revision:    0
+  user:        test
+  date:        Thu, 01 Jan 1970 00:00:00 +0000
+  summary:     base
+  tag:         1.0
+  bookmark:    anotherthing
+  
+  
+
 Stop and restart with HGENCODING=cp932 and preferuncompressed
 
   $ killdaemons.py