Patchwork D1024: hgweb: do not import uuid immediately to avoid its side effect

login
register
mail settings
Submitter phabricator
Date Oct. 13, 2017, 2:06 p.m.
Message ID <cc424114dd392273d5f6a4df787bd1bb@localhost.localdomain>
Download mbox | patch
Permalink /patch/24831/
State Not Applicable
Headers show

Comments

phabricator - Oct. 13, 2017, 2:06 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf42dec9c976e: hgweb: do not import uuid immediately to avoid its side effect (authored by quark, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D1024?vs=2635&id=2681#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1024?vs=2635&id=2681

REVISION DETAIL
  https://phab.mercurial-scm.org/D1024

AFFECTED FILES
  mercurial/hgweb/common.py
  tests/test-dispatch.t

CHANGE DETAILS




To: quark, #hg-reviewers, av6
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-dispatch.t b/tests/test-dispatch.t
--- a/tests/test-dispatch.t
+++ b/tests/test-dispatch.t
@@ -60,3 +60,16 @@ 
   [255]
 
 #endif
+
+#if rmcwd
+
+Current directory removed:
+
+  $ mkdir $TESTTMP/repo1
+  $ cd $TESTTMP/repo1
+  $ rm -rf $TESTTMP/repo1
+  $ HGDEMANDIMPORT=disable hg version -q
+  abort: error getting current working directory: * (glob)
+  [255]
+
+#endif
diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -12,7 +12,6 @@ 
 import errno
 import mimetypes
 import os
-import uuid
 
 from .. import (
     encoding,
@@ -221,6 +220,23 @@ 
     First value is ``None`` if CSP isn't enabled. Second value is ``None``
     if CSP isn't enabled or if the CSP header doesn't need a nonce.
     """
+    # Without demandimport, "import uuid" could have an immediate side-effect
+    # running "ldconfig" on Linux trying to find libuuid.
+    # With Python <= 2.7.12, that "ldconfig" is run via a shell and the shell
+    # may pollute the terminal with:
+    #
+    #   shell-init: error retrieving current directory: getcwd: cannot access
+    #   parent directories: No such file or directory
+    #
+    # Python >= 2.7.13 has fixed it by running "ldconfig" directly without a
+    # shell (hg changeset a09ae70f3489).
+    #
+    # Moved "import uuid" from here so it's executed after we know we have
+    # a sane cwd (i.e. after dispatch.py cwd check).
+    #
+    # We can move it back once we no longer need Python <= 2.7.12 support.
+    import uuid
+
     # Don't allow untrusted CSP setting since it be disable protections
     # from a trusted/global source.
     csp = ui.config('web', 'csp', untrusted=False)