D4040: shortest: make isrev() a top-level function

2018-08-04 Thread martinvonz (Martin von Zweigbergk)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG531b86cc8fb3: shortest: make isrev() a top-level function 
(authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4040?vs=9888=9895

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -462,6 +462,19 @@
 repo.changelog.rev(node)  # make sure node isn't filtered
 return node
 
+def mayberevnum(repo, prefix):
+"""Checks if the given prefix may be mistaken for a revision number"""
+try:
+i = int(prefix)
+# if we are a pure int, then starting with zero will not be
+# confused as a rev; or, obviously, if the int is larger
+# than the value of the tip rev
+if prefix[0:1] == b'0' or i > len(repo):
+return False
+return True
+except ValueError:
+return False
+
 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
 """Find the shortest unambiguous prefix that matches hexnode.
 
@@ -471,28 +484,16 @@
 # _partialmatch() of filtered changelog could take O(len(repo)) time,
 # which would be unacceptably slow. so we look for hash collision in
 # unfiltered space, which means some hashes may be slightly longer.
-cl = repo.unfiltered().changelog
-
-def isrev(prefix):
-try:
-i = int(prefix)
-# if we are a pure int, then starting with zero will not be
-# confused as a rev; or, obviously, if the int is larger
-# than the value of the tip rev
-if prefix[0:1] == b'0' or i > len(cl):
-return False
-return True
-except ValueError:
-return False
 
 def disambiguate(prefix):
 """Disambiguate against revnums."""
 hexnode = hex(node)
 for length in range(len(prefix), len(hexnode) + 1):
 prefix = hexnode[:length]
-if not isrev(prefix):
+if not mayberevnum(repo, prefix):
 return prefix
 
+cl = repo.unfiltered().changelog
 revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
 if revset:
 revs = None



To: martinvonz, #hg-reviewers, lothiraldan, pulkit
Cc: yuja, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-03 Thread martinvonz (Martin von Zweigbergk)
martinvonz updated this revision to Diff 9888.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4040?vs=9756=9888

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -462,6 +462,19 @@
 repo.changelog.rev(node)  # make sure node isn't filtered
 return node
 
+def mayberevnum(repo, prefix):
+"""Checks if the given prefix may be mistaken for a revision number"""
+try:
+i = int(prefix)
+# if we are a pure int, then starting with zero will not be
+# confused as a rev; or, obviously, if the int is larger
+# than the value of the tip rev
+if prefix[0:1] == b'0' or i > len(repo):
+return False
+return True
+except ValueError:
+return False
+
 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
 """Find the shortest unambiguous prefix that matches hexnode.
 
@@ -471,28 +484,16 @@
 # _partialmatch() of filtered changelog could take O(len(repo)) time,
 # which would be unacceptably slow. so we look for hash collision in
 # unfiltered space, which means some hashes may be slightly longer.
-cl = repo.unfiltered().changelog
-
-def isrev(prefix):
-try:
-i = int(prefix)
-# if we are a pure int, then starting with zero will not be
-# confused as a rev; or, obviously, if the int is larger
-# than the value of the tip rev
-if prefix[0:1] == b'0' or i > len(cl):
-return False
-return True
-except ValueError:
-return False
 
 def disambiguate(prefix):
 """Disambiguate against revnums."""
 hexnode = hex(node)
 for length in range(len(prefix), len(hexnode) + 1):
 prefix = hexnode[:length]
-if not isrev(prefix):
+if not mayberevnum(repo, prefix):
 return prefix
 
+cl = repo.unfiltered().changelog
 revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
 if revset:
 revs = None



To: martinvonz, #hg-reviewers, lothiraldan, pulkit
Cc: yuja, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-03 Thread martinvonz (Martin von Zweigbergk)
martinvonz marked an inline comment as done.
martinvonz added a comment.


  In https://phab.mercurial-scm.org/D4040#63462, @yuja wrote:
  
  > > +def mayberevnum(repo, prefix):
  > >  +"""Checks if the given prefix may be mistaken for a revision 
number"""
  > >  +try:
  > >  +i = int(prefix)
  > >  +# if we are a pure int, then starting with zero will not be
  > >  +# confused as a rev; or, obviously, if the int is larger
  > >  +# than the value of the tip rev
  > >  +if prefix[0:1] == b'0' or i > len(repo.changelog):
  >
  > `len(repo)` should be better since `repo.changelog` over repoview isn't
  >  instant. Another option is to pass in an unfiltered repo as before.
  
  
  Good catch, I didn't mean to change that. Will fix.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

To: martinvonz, #hg-reviewers, lothiraldan, pulkit
Cc: yuja, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D4040: shortest: make isrev() a top-level function

2018-08-03 Thread Yuya Nishihara
> +def mayberevnum(repo, prefix):
> +"""Checks if the given prefix may be mistaken for a revision number"""
> +try:
> +i = int(prefix)
> +# if we are a pure int, then starting with zero will not be
> +# confused as a rev; or, obviously, if the int is larger
> +# than the value of the tip rev
> +if prefix[0:1] == b'0' or i > len(repo.changelog):

`len(repo)` should be better since `repo.changelog` over repoview isn't
instant. Another option is to pass in an unfiltered repo as before.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-03 Thread yuja (Yuya Nishihara)
yuja added a comment.


  > +def mayberevnum(repo, prefix):
  >  +"""Checks if the given prefix may be mistaken for a revision number"""
  >  +try:
  >  +i = int(prefix)
  >  +# if we are a pure int, then starting with zero will not be
  >  +# confused as a rev; or, obviously, if the int is larger
  >  +# than the value of the tip rev
  >  +if prefix[0:1] == b'0' or i > len(repo.changelog):
  
  `len(repo)` should be better since `repo.changelog` over repoview isn't
  instant. Another option is to pass in an unfiltered repo as before.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

To: martinvonz, #hg-reviewers, lothiraldan, pulkit
Cc: yuja, pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-03 Thread martinvonz (Martin von Zweigbergk)
martinvonz marked an inline comment as done.
martinvonz added inline comments.

INLINE COMMENTS

> pulkit wrote in scmutil.py:492
> This looks unrelated here.

Not completely unrelated. I moved it down here because it's no longer needed 
until here. It was used on line 478 before (and given Python scoping rules, it 
could have been moved down even before this patch, but that makes it harder to 
read IMO).

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

To: martinvonz, #hg-reviewers, lothiraldan
Cc: pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-03 Thread pulkit (Pulkit Goyal)
pulkit added inline comments.

INLINE COMMENTS

> scmutil.py:492
>  
> +cl = repo.unfiltered().changelog
>  revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')

This looks unrelated here.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

To: martinvonz, #hg-reviewers, lothiraldan
Cc: pulkit, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D4040: shortest: make isrev() a top-level function

2018-08-01 Thread martinvonz (Martin von Zweigbergk)
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I'm going to add another caller in the next patch.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4040

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -462,33 +462,34 @@
 repo.changelog.rev(node)  # make sure node isn't filtered
 return node
 
+def mayberevnum(repo, prefix):
+"""Checks if the given prefix may be mistaken for a revision number"""
+try:
+i = int(prefix)
+# if we are a pure int, then starting with zero will not be
+# confused as a rev; or, obviously, if the int is larger
+# than the value of the tip rev
+if prefix[0:1] == b'0' or i > len(repo.changelog):
+return False
+return True
+except ValueError:
+return False
+
 def shortesthexnodeidprefix(repo, node, minlength=1):
 """Find the shortest unambiguous prefix that matches hexnode."""
 # _partialmatch() of filtered changelog could take O(len(repo)) time,
 # which would be unacceptably slow. so we look for hash collision in
 # unfiltered space, which means some hashes may be slightly longer.
-cl = repo.unfiltered().changelog
-
-def isrev(prefix):
-try:
-i = int(prefix)
-# if we are a pure int, then starting with zero will not be
-# confused as a rev; or, obviously, if the int is larger
-# than the value of the tip rev
-if prefix[0:1] == b'0' or i > len(cl):
-return False
-return True
-except ValueError:
-return False
 
 def disambiguate(prefix):
 """Disambiguate against revnums."""
 hexnode = hex(node)
 for length in range(len(prefix), len(hexnode) + 1):
 prefix = hexnode[:length]
-if not isrev(prefix):
+if not mayberevnum(repo, prefix):
 return prefix
 
+cl = repo.unfiltered().changelog
 revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
 if revset:
 if not util.safehasattr(repo, '_cacheddisambiguationrevs'):



To: martinvonz, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel