Patchwork [V2] py3: fix a type error in hghave.has_hardlink

login
register
mail settings
Submitter Matt Harbison
Date Sept. 21, 2018, 11:07 p.m.
Message ID <47b396135bb2ee0d5c5b.1537571244@Envy>
Download mbox | patch
Permalink /patch/34913/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 21, 2018, 11:07 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537504623 14400
#      Fri Sep 21 00:37:03 2018 -0400
# Node ID 47b396135bb2ee0d5c5b9ed91cd7a87920b344b5
# Parent  543f26ece6cf09d9ab36ff601ec53422f6b54b91
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. 22, 2018, 12:18 a.m.
On Fri, 21 Sep 2018 19:07:24 -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 47b396135bb2ee0d5c5b9ed91cd7a87920b344b5
> # Parent  543f26ece6cf09d9ab36ff601ec53422f6b54b91
> py3: fix a type error in hghave.has_hardlink

Queued, thanks.

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -16,6 +16,22 @@  checks = {
     "false": (lambda: False, "nail clipper"),
 }
 
+if sys.version_info[0] >= 3:
+    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')
+else:
+    def _bytespath(p):
+        return p
+
+    _strpath = _bytespath
+
 def check(name, desc):
     """Registers a check function for a feature."""
     def decorator(func):
@@ -360,7 +376,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: