Patchwork extensions: don't fail to load on Windows if path ends with a '\' (issue4187)

login
register
mail settings
Submitter Simon Heimberg
Date March 6, 2014, 7:57 p.m.
Message ID <fdc109d7f256c16ef7b9.1394135868@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/3879/
State Superseded
Headers show

Comments

Simon Heimberg - March 6, 2014, 7:57 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1394057163 -3600
#      Wed Mar 05 23:06:03 2014 +0100
# Node ID fdc109d7f256c16ef7b9fdbb76ab9bd3b49f5bcc
# Parent  779ceb84f4f782d32dfe47f6684107c08d2f6142
extensions: don't fail to load on Windows if path ends with a '\' (issue4187)

Same fix as 5c794e7331e7 but now works on Windows too.

Original idea by Ed Morley.
Simon Heimberg - March 6, 2014, 11:50 p.m.
On 06.03.2014, 20:57 +0100 Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1394057163 -3600
> #      Wed Mar 05 23:06:03 2014 +0100
> # Node ID fdc109d7f256c16ef7b9fdbb76ab9bd3b49f5bcc
> # Parent  779ceb84f4f782d32dfe47f6684107c08d2f6142
> extensions: don't fail to load on Windows if path ends with a '\' (issue4187)
> 
> Same fix as 5c794e7331e7 but now works on Windows too.
> 
> Original idea by Ed Morley.
> 
Oops, it is already fixed. Maybe I will resend the tests only.

> diff -r 779ceb84f4f7 -r fdc109d7f256 mercurial/extensions.py
> --- a/mercurial/extensions.py	Tue Mar 04 09:56:59 2014 -0600
> +++ b/mercurial/extensions.py	Wed Mar 05 23:06:03 2014 +0100
> @@ -46,7 +46,7 @@
>      path = util.expandpath(path)
>      if os.path.isdir(path):
>          # module/__init__.py style
> -        d, f = os.path.split(path.rstrip('/'))
> +        d, f = os.path.split(path.rstrip('/' + os.sep))
>          fd, fpath, desc = imp.find_module(f, [d])
>          return imp.load_module(module_name, fd, fpath, desc)
>      else:
> diff -r 779ceb84f4f7 -r fdc109d7f256 tests/test-extension.t
> --- a/tests/test-extension.t	Tue Mar 04 09:56:59 2014 -0600
> +++ b/tests/test-extension.t	Wed Mar 05 23:06:03 2014 +0100
> @@ -68,6 +68,20 @@
>    reposetup called for a
>    ui == repo.ui
>    Foo
> +  $ echo "barfoo = $barfoopath/" >> $HGRCPATH
> +  $ hg foo
> +  uisetup called
> +  reposetup called for a
> +  ui == repo.ui
> +  Foo
> +#if windows
> +  $ echo "barfoo = $barfoopath\\" >> $HGRCPATH
> +  $ hg foo
> +  uisetup called
> +  reposetup called for a
> +  ui == repo.ui
> +  Foo
> +#endif
>    $ echo 'barfoo = !' >> $HGRCPATH
>  
>  Check that extensions are loaded in phases:

Patch

diff -r 779ceb84f4f7 -r fdc109d7f256 mercurial/extensions.py
--- a/mercurial/extensions.py	Tue Mar 04 09:56:59 2014 -0600
+++ b/mercurial/extensions.py	Wed Mar 05 23:06:03 2014 +0100
@@ -46,7 +46,7 @@ 
     path = util.expandpath(path)
     if os.path.isdir(path):
         # module/__init__.py style
-        d, f = os.path.split(path.rstrip('/'))
+        d, f = os.path.split(path.rstrip('/' + os.sep))
         fd, fpath, desc = imp.find_module(f, [d])
         return imp.load_module(module_name, fd, fpath, desc)
     else:
diff -r 779ceb84f4f7 -r fdc109d7f256 tests/test-extension.t
--- a/tests/test-extension.t	Tue Mar 04 09:56:59 2014 -0600
+++ b/tests/test-extension.t	Wed Mar 05 23:06:03 2014 +0100
@@ -68,6 +68,20 @@ 
   reposetup called for a
   ui == repo.ui
   Foo
+  $ echo "barfoo = $barfoopath/" >> $HGRCPATH
+  $ hg foo
+  uisetup called
+  reposetup called for a
+  ui == repo.ui
+  Foo
+#if windows
+  $ echo "barfoo = $barfoopath\\" >> $HGRCPATH
+  $ hg foo
+  uisetup called
+  reposetup called for a
+  ui == repo.ui
+  Foo
+#endif
   $ echo 'barfoo = !' >> $HGRCPATH
 
 Check that extensions are loaded in phases: