comparison mercurial/scmutil.py @ 25904:fbaa2de13cf6

revrange: drop old-style parser in favor of revset (API) Now revset can parse nullary ":" operator and existing "foo+bar" tags, we don't need the old-style parser. This means scmutil.revsingle(), revpair() and revrange() no longer accept a binary nodeid. An integer revision is still allowed as it isn't ambiguous.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 24 Jan 2015 22:28:14 +0900
parents 5471965af5cb
children 4ee4f7415095
comparison
equal deleted inserted replaced
25903:9bbab9decd71 25904:fbaa2de13cf6
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from i18n import _ 8 from i18n import _
9 from mercurial.node import nullrev, wdirrev 9 from mercurial.node import wdirrev
10 import util, error, osutil, revset, similar, encoding, phases 10 import util, error, osutil, revset, similar, encoding, phases
11 import pathutil 11 import pathutil
12 import match as matchmod 12 import match as matchmod
13 import os, errno, re, glob, tempfile, shutil, stat 13 import os, errno, re, glob, tempfile, shutil, stat
14 14
718 718
719 _revrangesep = ':' 719 _revrangesep = ':'
720 720
721 def revrange(repo, revs): 721 def revrange(repo, revs):
722 """Yield revision as strings from a list of revision specifications.""" 722 """Yield revision as strings from a list of revision specifications."""
723
724 def revfix(repo, val, defval):
725 if not val and val != 0 and defval is not None:
726 return defval
727 return repo[val].rev()
728
729 subsets = [] 723 subsets = []
730
731 revsetaliases = [alias for (alias, _) in
732 repo.ui.configitems("revsetalias")]
733
734 for spec in revs: 724 for spec in revs:
735 # attempt to parse old-style ranges first to deal with 725 if isinstance(spec, int):
736 # things like old-tag which contain query metacharacters 726 spec = revset.formatspec('rev(%d)', spec)
737 try:
738 # ... except for revset aliases without arguments. These
739 # should be parsed as soon as possible, because they might
740 # clash with a hash prefix.
741 if spec in revsetaliases:
742 raise error.RepoLookupError
743
744 if isinstance(spec, int):
745 subsets.append(revset.baseset([spec]))
746 continue
747
748 if _revrangesep in spec:
749 start, end = spec.split(_revrangesep, 1)
750 if start in revsetaliases or end in revsetaliases:
751 raise error.RepoLookupError
752
753 start = revfix(repo, start, 0)
754 end = revfix(repo, end, len(repo) - 1)
755 if end == nullrev and start < 0:
756 start = nullrev
757 if start < end:
758 l = revset.spanset(repo, start, end + 1)
759 else:
760 l = revset.spanset(repo, start, end - 1)
761 subsets.append(l)
762 continue
763 elif spec and spec in repo: # single unquoted rev
764 rev = revfix(repo, spec, None)
765 subsets.append(revset.baseset([rev]))
766 continue
767 except error.RepoLookupError:
768 pass
769
770 # fall through to new-style queries if old-style fails
771 m = revset.match(repo.ui, spec, repo) 727 m = revset.match(repo.ui, spec, repo)
772 subsets.append(m(repo)) 728 subsets.append(m(repo))
773 729
774 return revset._combinesets(subsets) 730 return revset._combinesets(subsets)
775 731