Patchwork [2,of,2] py3: fix a type error in hghave.has_hardlink

login
register
mail settings
Submitter Matt Harbison
Date Sept. 21, 2018, 5:03 a.m.
Message ID <0be4328bfbaf10cbd9f8.1537506185@Envy>
Download mbox | patch
Permalink /patch/34888/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 21, 2018, 5:03 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537504623 14400
#      Fri Sep 21 00:37:03 2018 -0400
# Node ID 0be4328bfbaf10cbd9f8aa6e96222107426567a5
# Parent  1b0ca924a1c3de80bf3b2b3efcf0f82b2815b4d7
py3: fix a type error in hghave.has_hardlink

test-hghave.t was failing with:

      feature hardlink failed:  argument 1: <class 'TypeError'>: wrong type
Yuya Nishihara - Sept. 21, 2018, 11:22 a.m.
On Fri, 21 Sep 2018 01:03:05 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1537504623 14400
> #      Fri Sep 21 00:37:03 2018 -0400
> # Node ID 0be4328bfbaf10cbd9f8aa6e96222107426567a5
> # Parent  1b0ca924a1c3de80bf3b2b3efcf0f82b2815b4d7
> py3: fix a type error in hghave.has_hardlink
> 
> test-hghave.t was failing with:
> 
>       feature hardlink failed:  argument 1: <class 'TypeError'>: wrong type
> 
> diff --git a/tests/hghave.py b/tests/hghave.py
> --- a/tests/hghave.py
> +++ b/tests/hghave.py
> @@ -16,6 +16,16 @@ checks = {
>      "false": (lambda: False, "nail clipper"),
>  }
>  
> +def _bytespath(p):
> +    if p is None:
> +        return p
> +    return p.encode('utf-8')
> +
> +def _strpath(p):
> +    if p is None:
> +        return p
> +    return p.decode('utf-8')

Can you conditionalize these? On Python 2, mktemp() should return a byte
string.

> @@ -360,7 +370,7 @@ def has_hardlink():
>      os.close(fh)
>      name = tempfile.mktemp(dir='.', prefix=tempprefix)
>      try:
> -        util.oslink(fn, name)
> +        util.oslink(_bytespath(fn), _bytespath(name))

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -16,6 +16,16 @@  checks = {
     "false": (lambda: False, "nail clipper"),
 }
 
+def _bytespath(p):
+    if p is None:
+        return p
+    return p.encode('utf-8')
+
+def _strpath(p):
+    if p is None:
+        return p
+    return p.decode('utf-8')
+
 def check(name, desc):
     """Registers a check function for a feature."""
     def decorator(func):
@@ -360,7 +370,7 @@  def has_hardlink():
     os.close(fh)
     name = tempfile.mktemp(dir='.', prefix=tempprefix)
     try:
-        util.oslink(fn, name)
+        util.oslink(_bytespath(fn), _bytespath(name))
         os.unlink(name)
         return True
     except OSError: