Patchwork [3,of,9,py3,v3] context: work around `long` not existing on Python 3

login
register
mail settings
Submitter Augie Fackler
Date March 12, 2017, 5:59 p.m.
Message ID <c4a50c84504fe6eaae95.1489341551@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/19190/
State Accepted
Headers show

Comments

Augie Fackler - March 12, 2017, 5:59 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489283824 18000
#      Sat Mar 11 20:57:04 2017 -0500
# Node ID c4a50c84504fe6eaae95915f401e9d6826e4d19f
# Parent  d656211a72279aa55428121be114b4059e7117ab
context: work around `long` not existing on Python 3

I can't figure out what this branch is even trying to accomplish, and
it was introduced in ac89a23ca814 which doesn't really shed any
insight into why longs are treated differently from ints.
via Mercurial-devel - March 12, 2017, 6:02 p.m.
On Sun, Mar 12, 2017 at 10:59 AM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1489283824 18000
> #      Sat Mar 11 20:57:04 2017 -0500
> # Node ID c4a50c84504fe6eaae95915f401e9d6826e4d19f
> # Parent  d656211a72279aa55428121be114b4059e7117ab
> context: work around `long` not existing on Python 3
>
> I can't figure out what this branch is even trying to accomplish, and
> it was introduced in ac89a23ca814 which doesn't really shed any
> insight into why longs are treated differently from ints.

I'm guessing it's because longs can't be revnums, so they are assumed
to come from a decimal-only prefix of a nodeid. Just a guess. And of
course there are no tests for it.

>
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -33,6 +33,7 @@ from . import (
>      obsolete as obsmod,
>      patch,
>      phases,
> +    pycompat,
>      repoview,
>      revlog,
>      scmutil,
> @@ -419,7 +420,7 @@ class changectx(basectx):
>                  self._node = repo.changelog.node(changeid)
>                  self._rev = changeid
>                  return
> -            if isinstance(changeid, long):
> +            if not pycompat.ispy3 and isinstance(changeid, long):
>                  changeid = str(changeid)
>              if changeid == 'null':
>                  self._node = nullid
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
via Mercurial-devel - March 12, 2017, 6:15 p.m.
On Sun, Mar 12, 2017 at 11:02 AM, Martin von Zweigbergk
<martinvonz@google.com> wrote:
> On Sun, Mar 12, 2017 at 10:59 AM, Augie Fackler <raf@durin42.com> wrote:
>> # HG changeset patch
>> # User Augie Fackler <augie@google.com>
>> # Date 1489283824 18000
>> #      Sat Mar 11 20:57:04 2017 -0500
>> # Node ID c4a50c84504fe6eaae95915f401e9d6826e4d19f
>> # Parent  d656211a72279aa55428121be114b4059e7117ab
>> context: work around `long` not existing on Python 3
>>
>> I can't figure out what this branch is even trying to accomplish, and
>> it was introduced in ac89a23ca814 which doesn't really shed any
>> insight into why longs are treated differently from ints.
>
> I'm guessing it's because longs can't be revnums, so they are assumed
> to come from a decimal-only prefix of a nodeid. Just a guess. And of
> course there are no tests for it.

I was thinking that hgweb might create a context from something that
looked like a long, but even visiting /rev/252232621165917755727729 in
the hg core repo works fine. I'm done looking into this curiosity :-)

>
>>
>> diff --git a/mercurial/context.py b/mercurial/context.py
>> --- a/mercurial/context.py
>> +++ b/mercurial/context.py
>> @@ -33,6 +33,7 @@ from . import (
>>      obsolete as obsmod,
>>      patch,
>>      phases,
>> +    pycompat,
>>      repoview,
>>      revlog,
>>      scmutil,
>> @@ -419,7 +420,7 @@ class changectx(basectx):
>>                  self._node = repo.changelog.node(changeid)
>>                  self._rev = changeid
>>                  return
>> -            if isinstance(changeid, long):
>> +            if not pycompat.ispy3 and isinstance(changeid, long):
>>                  changeid = str(changeid)
>>              if changeid == 'null':
>>                  self._node = nullid
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@mercurial-scm.org
>> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - March 12, 2017, 6:37 p.m.
On Sun, 12 Mar 2017 11:15:59 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> On Sun, Mar 12, 2017 at 11:02 AM, Martin von Zweigbergk
> <martinvonz@google.com> wrote:
> > On Sun, Mar 12, 2017 at 10:59 AM, Augie Fackler <raf@durin42.com> wrote:
> >> # HG changeset patch
> >> # User Augie Fackler <augie@google.com>
> >> # Date 1489283824 18000
> >> #      Sat Mar 11 20:57:04 2017 -0500
> >> # Node ID c4a50c84504fe6eaae95915f401e9d6826e4d19f
> >> # Parent  d656211a72279aa55428121be114b4059e7117ab
> >> context: work around `long` not existing on Python 3
> >>
> >> I can't figure out what this branch is even trying to accomplish, and
> >> it was introduced in ac89a23ca814 which doesn't really shed any
> >> insight into why longs are treated differently from ints.
> >
> > I'm guessing it's because longs can't be revnums, so they are assumed
> > to come from a decimal-only prefix of a nodeid. Just a guess. And of
> > course there are no tests for it.
> 
> I was thinking that hgweb might create a context from something that
> looked like a long, but even visiting /rev/252232621165917755727729 in
> the hg core repo works fine. I'm done looking into this curiosity :-)

Perhaps it exists just for avoiding exception caused by passing long to
string functions.

https://www.mercurial-scm.org/pipermail/mercurial-devel/2012-May/040438.html

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -33,6 +33,7 @@  from . import (
     obsolete as obsmod,
     patch,
     phases,
+    pycompat,
     repoview,
     revlog,
     scmutil,
@@ -419,7 +420,7 @@  class changectx(basectx):
                 self._node = repo.changelog.node(changeid)
                 self._rev = changeid
                 return
-            if isinstance(changeid, long):
+            if not pycompat.ispy3 and isinstance(changeid, long):
                 changeid = str(changeid)
             if changeid == 'null':
                 self._node = nullid