Patchwork posix: fix split() for the case where the path is at the root of the filesystem

login
register
mail settings
Submitter Remy Blank
Date Jan. 5, 2013, 4:29 p.m.
Message ID <9d750e6d7338555bb8a9.1357403395@pat.athome>
Download mbox | patch
Permalink /patch/400/
State Superseded
Headers show

Comments

Remy Blank - Jan. 5, 2013, 4:29 p.m.
# HG changeset patch
# User Remy Blank <remy.blank at pobox.com>
# Date 1357401181 -3600
# Node ID 9d750e6d7338555bb8a9a47aac1efed1f7a3219c
# Parent  83aa4359c49f67bcb98fb9c7d885ed4ac7443239
posix: fix split() for the case where the path is at the root of the filesystem

posixpath.split() strips '/' from the dirname *unless it is the root*. This patch reproduces this behavior in posix.split(). The old behavior causes a crash when creating a file at the root of the repo with localrepo.wfile() when the repo is at the root of the filesystem.
Mads Kiilerich - Jan. 6, 2013, 1:01 a.m.
Remy Blank wrote, On 01/05/2013 05:29 PM:
> # HG changeset patch
> # User Remy Blank <remy.blank at pobox.com>
> # Date 1357401181 -3600
> # Node ID 9d750e6d7338555bb8a9a47aac1efed1f7a3219c
> # Parent  83aa4359c49f67bcb98fb9c7d885ed4ac7443239
> posix: fix split() for the case where the path is at the root of the filesystem
>
> posixpath.split() strips '/' from the dirname *unless it is the root*. This patch reproduces this behavior in posix.split(). The old behavior causes a crash when creating a file at the root of the repo with localrepo.wfile() when the repo is at the root of the filesystem.

Thanks.

But please wrap the commit message at 80 characters (or slightly less).

And this posix.split apparently needs some test coverage. That could be 
a couple of doc test cases, tested from test-doctest.py ...

/Mads

> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -28,7 +28,7 @@ def split(p):
>       nh = ht[0].rstrip('/')
>       if nh:
>           return nh, ht[1]
> -    return ht
> +    return ht[0] + '/', ht[1]
>   
>   def openhardlinks():
>       '''return true if it is safe to hold open file handles to hardlinks'''
>
Remy Blank - Jan. 6, 2013, 1:23 a.m.
Mads Kiilerich wrote:
> But please wrap the commit message at 80 characters (or slightly less).
> 
> And this posix.split apparently needs some test coverage. That could be 
> a couple of doc test cases, tested from test-doctest.py ...

Thanks for the feedback. Update coming shortly.

-- Remy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130106/c8b74275/attachment.pgp>

Patch

diff --git a/mercurial/posix.py b/mercurial/posix.py
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -28,7 +28,7 @@  def split(p):
     nh = ht[0].rstrip('/')
     if nh:
         return nh, ht[1]
-    return ht
+    return ht[0] + '/', ht[1]
 
 def openhardlinks():
     '''return true if it is safe to hold open file handles to hardlinks'''