This is an archive of the discontinued Mercurial Phabricator instance.

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

Authored by martinvonz on Aug 1 2018, 5:57 PM.

Details

Summary

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

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

martinvonz created this revision.Aug 1 2018, 5:57 PM
lothiraldan accepted this revision.Aug 3 2018, 5:14 AM
pulkit added a subscriber: pulkit.Aug 3 2018, 5:48 PM
pulkit added inline comments.
mercurial/scmutil.py
496

This looks unrelated here.

martinvonz marked an inline comment as done.Aug 3 2018, 5:50 PM
martinvonz added inline comments.
mercurial/scmutil.py
496

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).

pulkit accepted this revision.Aug 3 2018, 5:52 PM
yuja added a subscriber: yuja.Aug 3 2018, 11:10 PM

+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.

martinvonz marked an inline comment as done.Aug 4 2018, 12:27 AM
In 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.

martinvonz updated this revision to Diff 9888.Aug 4 2018, 1:26 AM
This revision was automatically updated to reflect the committed changes.