707 def revfix(repo, val, defval): |
707 def revfix(repo, val, defval): |
708 if not val and val != 0 and defval is not None: |
708 if not val and val != 0 and defval is not None: |
709 return defval |
709 return defval |
710 return repo[val].rev() |
710 return repo[val].rev() |
711 |
711 |
712 seen, l = set(), revset.baseset([]) |
712 l = revset.baseset([]) |
713 |
713 |
714 revsetaliases = [alias for (alias, _) in |
714 revsetaliases = [alias for (alias, _) in |
715 repo.ui.configitems("revsetalias")] |
715 repo.ui.configitems("revsetalias")] |
716 |
716 |
717 for spec in revs: |
717 for spec in revs: |
718 if l and not seen: |
|
719 seen = set(l) |
|
720 # attempt to parse old-style ranges first to deal with |
718 # attempt to parse old-style ranges first to deal with |
721 # things like old-tag which contain query metacharacters |
719 # things like old-tag which contain query metacharacters |
722 try: |
720 try: |
723 # ... except for revset aliases without arguments. These |
721 # ... except for revset aliases without arguments. These |
724 # should be parsed as soon as possible, because they might |
722 # should be parsed as soon as possible, because they might |
725 # clash with a hash prefix. |
723 # clash with a hash prefix. |
726 if spec in revsetaliases: |
724 if spec in revsetaliases: |
727 raise error.RepoLookupError |
725 raise error.RepoLookupError |
728 |
726 |
729 if isinstance(spec, int): |
727 if isinstance(spec, int): |
730 seen.add(spec) |
|
731 l = l + revset.baseset([spec]) |
728 l = l + revset.baseset([spec]) |
732 continue |
729 continue |
733 |
730 |
734 if _revrangesep in spec: |
731 if _revrangesep in spec: |
735 start, end = spec.split(_revrangesep, 1) |
732 start, end = spec.split(_revrangesep, 1) |
739 start = revfix(repo, start, 0) |
736 start = revfix(repo, start, 0) |
740 end = revfix(repo, end, len(repo) - 1) |
737 end = revfix(repo, end, len(repo) - 1) |
741 if end == nullrev and start < 0: |
738 if end == nullrev and start < 0: |
742 start = nullrev |
739 start = nullrev |
743 rangeiter = repo.changelog.revs(start, end) |
740 rangeiter = repo.changelog.revs(start, end) |
744 if not seen and not l: |
741 if not l: |
745 # by far the most common case: revs = ["-1:0"] |
742 # by far the most common case: revs = ["-1:0"] |
746 l = revset.baseset(rangeiter) |
743 l = revset.baseset(rangeiter) |
747 # defer syncing seen until next iteration |
|
748 continue |
744 continue |
749 newrevs = set(rangeiter) |
745 newrevs = set(rangeiter) |
750 if seen: |
|
751 newrevs.difference_update(seen) |
|
752 seen.update(newrevs) |
|
753 else: |
|
754 seen = newrevs |
|
755 l = l + revset.baseset(sorted(newrevs, reverse=start > end)) |
746 l = l + revset.baseset(sorted(newrevs, reverse=start > end)) |
756 continue |
747 continue |
757 elif spec and spec in repo: # single unquoted rev |
748 elif spec and spec in repo: # single unquoted rev |
758 rev = revfix(repo, spec, None) |
749 rev = revfix(repo, spec, None) |
759 if rev in seen: |
|
760 continue |
|
761 seen.add(rev) |
|
762 l = l + revset.baseset([rev]) |
750 l = l + revset.baseset([rev]) |
763 continue |
751 continue |
764 except error.RepoLookupError: |
752 except error.RepoLookupError: |
765 pass |
753 pass |
766 |
754 |
767 # fall through to new-style queries if old-style fails |
755 # fall through to new-style queries if old-style fails |
768 m = revset.match(repo.ui, spec, repo) |
756 m = revset.match(repo.ui, spec, repo) |
769 if seen or l: |
757 if l: |
770 dl = [r for r in m(repo) if r not in seen] |
758 dl = [r for r in m(repo)] |
771 l = l + revset.baseset(dl) |
759 l = l + revset.baseset(dl) |
772 seen.update(dl) |
|
773 else: |
760 else: |
774 l = m(repo) |
761 l = m(repo) |
775 |
762 |
776 return l |
763 return l |
777 |
764 |