mercurial/revset.py
changeset 20526 9ad6dae67845
parent 20525 aa73a6327df4
child 20527 bde426f18e0a
equal deleted inserted replaced
20525:aa73a6327df4 20526:9ad6dae67845
   230     if not m or not n:
   230     if not m or not n:
   231         return baseset([])
   231         return baseset([])
   232     m, n = m[0], n[-1]
   232     m, n = m[0], n[-1]
   233 
   233 
   234     if m < n:
   234     if m < n:
   235         r = range(m, n + 1)
   235         r = spanset(repo, m, n + 1)
   236     else:
   236     else:
   237         r = range(m, n - 1, -1)
   237         r = spanset(repo, m, n - 1)
   238     s = subset.set()
   238     return r & subset
   239     return baseset([x for x in r if x in s])
       
   240 
   239 
   241 def dagrange(repo, subset, x, y):
   240 def dagrange(repo, subset, x, y):
   242     r = baseset(repo)
   241     r = spanset(repo)
   243     xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
   242     xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
   244     s = subset.set()
   243     s = subset.set()
   245     return baseset([r for r in xs if r in s])
   244     return baseset([r for r in xs if r in s])
   246 
   245 
   247 def andset(repo, subset, x, y):
   246 def andset(repo, subset, x, y):
   285     Will return empty list when passed no args.
   284     Will return empty list when passed no args.
   286     Greatest common ancestor of a single changeset is that changeset.
   285     Greatest common ancestor of a single changeset is that changeset.
   287     """
   286     """
   288     # i18n: "ancestor" is a keyword
   287     # i18n: "ancestor" is a keyword
   289     l = getlist(x)
   288     l = getlist(x)
   290     rl = baseset(repo)
   289     rl = spanset(repo)
   291     anc = None
   290     anc = None
   292 
   291 
   293     # (getset(repo, rl, i) for i in l) generates a list of lists
   292     # (getset(repo, rl, i) for i in l) generates a list of lists
   294     rev = repo.changelog.rev
   293     rev = repo.changelog.rev
   295     ancestor = repo.changelog.ancestor
   294     ancestor = repo.changelog.ancestor
   304     if anc is not None and anc in subset:
   303     if anc is not None and anc in subset:
   305         return baseset([anc])
   304         return baseset([anc])
   306     return baseset([])
   305     return baseset([])
   307 
   306 
   308 def _ancestors(repo, subset, x, followfirst=False):
   307 def _ancestors(repo, subset, x, followfirst=False):
   309     args = getset(repo, baseset(repo), x)
   308     args = getset(repo, spanset(repo), x)
   310     if not args:
   309     if not args:
   311         return baseset([])
   310         return baseset([])
   312     s = set(_revancestors(repo, args, followfirst)) | set(args)
   311     s = set(_revancestors(repo, args, followfirst)) | set(args)
   313     return baseset([r for r in subset if r in s])
   312     return baseset([r for r in subset if r in s])
   314 
   313 
   431             if pattern in repo.branchmap():
   430             if pattern in repo.branchmap():
   432                 return lazyset(subset, lambda r: matcher(repo[r].branch()))
   431                 return lazyset(subset, lambda r: matcher(repo[r].branch()))
   433         else:
   432         else:
   434             return lazyset(subset, lambda r: matcher(repo[r].branch()))
   433             return lazyset(subset, lambda r: matcher(repo[r].branch()))
   435 
   434 
   436     s = getset(repo, baseset(repo), x)
   435     s = getset(repo, spanset(repo), x)
   437     b = set()
   436     b = set()
   438     for r in s:
   437     for r in s:
   439         b.add(repo[r].branch())
   438         b.add(repo[r].branch())
   440     s = s.set()
   439     s = s.set()
   441     return lazyset(subset, lambda r: r in s or repo[r].branch() in b)
   440     return lazyset(subset, lambda r: r in s or repo[r].branch() in b)
   594         return ds in encoding.lower(c.description())
   593         return ds in encoding.lower(c.description())
   595 
   594 
   596     return lazyset(subset, matches)
   595     return lazyset(subset, matches)
   597 
   596 
   598 def _descendants(repo, subset, x, followfirst=False):
   597 def _descendants(repo, subset, x, followfirst=False):
   599     args = getset(repo, baseset(repo), x)
   598     args = getset(repo, spanset(repo), x)
   600     if not args:
   599     if not args:
   601         return baseset([])
   600         return baseset([])
   602     s = set(_revdescendants(repo, args, followfirst)) | set(args)
   601     s = set(_revdescendants(repo, args, followfirst)) | set(args)
   603     return baseset([r for r in subset if r in s])
   602     return subset & s
   604 
   603 
   605 def descendants(repo, subset, x):
   604 def descendants(repo, subset, x):
   606     """``descendants(set)``
   605     """``descendants(set)``
   607     Changesets which are descendants of changesets in set.
   606     Changesets which are descendants of changesets in set.
   608     """
   607     """
   618     Changesets that were created by a graft, transplant or rebase operation,
   617     Changesets that were created by a graft, transplant or rebase operation,
   619     with the given revisions specified as the source.  Omitting the optional set
   618     with the given revisions specified as the source.  Omitting the optional set
   620     is the same as passing all().
   619     is the same as passing all().
   621     """
   620     """
   622     if x is not None:
   621     if x is not None:
   623         args = getset(repo, baseset(repo), x).set()
   622         args = getset(repo, spanset(repo), x).set()
   624     else:
   623     else:
   625         args = getall(repo, baseset(repo), x).set()
   624         args = getall(repo, spanset(repo), x).set()
   626 
   625 
   627     dests = set()
   626     dests = set()
   628 
   627 
   629     # subset contains all of the possible destinations that can be returned, so
   628     # subset contains all of the possible destinations that can be returned, so
   630     # iterate over them and see if their source(s) were provided in the args.
   629     # iterate over them and see if their source(s) were provided in the args.
   941             lim = int(getstring(l[1], _("limit requires a number")))
   940             lim = int(getstring(l[1], _("limit requires a number")))
   942     except (TypeError, ValueError):
   941     except (TypeError, ValueError):
   943         # i18n: "limit" is a keyword
   942         # i18n: "limit" is a keyword
   944         raise error.ParseError(_("limit expects a number"))
   943         raise error.ParseError(_("limit expects a number"))
   945     ss = subset.set()
   944     ss = subset.set()
   946     os = getset(repo, baseset(repo), l[0])
   945     os = getset(repo, spanset(repo), l[0])
   947     bs = baseset([])
   946     bs = baseset([])
   948     it = iter(os)
   947     it = iter(os)
   949     for x in xrange(lim):
   948     for x in xrange(lim):
   950         try:
   949         try:
   951             y = it.next()
   950             y = it.next()
   968             lim = int(getstring(l[1], _("last requires a number")))
   967             lim = int(getstring(l[1], _("last requires a number")))
   969     except (TypeError, ValueError):
   968     except (TypeError, ValueError):
   970         # i18n: "last" is a keyword
   969         # i18n: "last" is a keyword
   971         raise error.ParseError(_("last expects a number"))
   970         raise error.ParseError(_("last expects a number"))
   972     ss = subset.set()
   971     ss = subset.set()
   973     os = getset(repo, baseset(repo), l[0])[-lim:]
   972     os = getset(repo, spanset(repo), l[0])[-lim:]
   974     return baseset([r for r in os if r in ss])
   973     return baseset([r for r in os if r in ss])
   975 
   974 
   976 def maxrev(repo, subset, x):
   975 def maxrev(repo, subset, x):
   977     """``max(set)``
   976     """``max(set)``
   978     Changeset with highest revision number in set.
   977     Changeset with highest revision number in set.
   979     """
   978     """
   980     os = getset(repo, baseset(repo), x)
   979     os = getset(repo, spanset(repo), x)
   981     if os:
   980     if os:
   982         m = max(os)
   981         m = max(os)
   983         if m in subset:
   982         if m in subset:
   984             return baseset([m])
   983             return baseset([m])
   985     return baseset([])
   984     return baseset([])
  1012 
  1011 
  1013 def minrev(repo, subset, x):
  1012 def minrev(repo, subset, x):
  1014     """``min(set)``
  1013     """``min(set)``
  1015     Changeset with lowest revision number in set.
  1014     Changeset with lowest revision number in set.
  1016     """
  1015     """
  1017     os = getset(repo, baseset(repo), x)
  1016     os = getset(repo, spanset(repo), x)
  1018     if os:
  1017     if os:
  1019         m = min(os)
  1018         m = min(os)
  1020         if m in subset:
  1019         if m in subset:
  1021             return baseset([m])
  1020             return baseset([m])
  1022     return baseset([])
  1021     return baseset([])
  1076     same as passing all().  If a changeset created by these operations is itself
  1075     same as passing all().  If a changeset created by these operations is itself
  1077     specified as a source for one of these operations, only the source changeset
  1076     specified as a source for one of these operations, only the source changeset
  1078     for the first operation is selected.
  1077     for the first operation is selected.
  1079     """
  1078     """
  1080     if x is not None:
  1079     if x is not None:
  1081         args = getset(repo, baseset(repo), x).set()
  1080         args = getset(repo, spanset(repo), x).set()
  1082     else:
  1081     else:
  1083         args = getall(repo, baseset(repo), x).set()
  1082         args = getall(repo, spanset(repo), x).set()
  1084 
  1083 
  1085     def _firstsrc(rev):
  1084     def _firstsrc(rev):
  1086         src = _getrevsource(repo, rev)
  1085         src = _getrevsource(repo, rev)
  1087         if src is None:
  1086         if src is None:
  1088             return None
  1087             return None
  1128         p = repo[x].p1().rev()
  1127         p = repo[x].p1().rev()
  1129         return baseset([r for r in subset if r == p])
  1128         return baseset([r for r in subset if r == p])
  1130 
  1129 
  1131     ps = set()
  1130     ps = set()
  1132     cl = repo.changelog
  1131     cl = repo.changelog
  1133     for r in getset(repo, baseset(repo), x):
  1132     for r in getset(repo, spanset(repo), x):
  1134         ps.add(cl.parentrevs(r)[0])
  1133         ps.add(cl.parentrevs(r)[0])
  1135     return subset & ps
  1134     return subset & ps
  1136 
  1135 
  1137 def p2(repo, subset, x):
  1136 def p2(repo, subset, x):
  1138     """``p2([set])``
  1137     """``p2([set])``
  1146         except IndexError:
  1145         except IndexError:
  1147             return baseset([])
  1146             return baseset([])
  1148 
  1147 
  1149     ps = set()
  1148     ps = set()
  1150     cl = repo.changelog
  1149     cl = repo.changelog
  1151     for r in getset(repo, baseset(repo), x):
  1150     for r in getset(repo, spanset(repo), x):
  1152         ps.add(cl.parentrevs(r)[1])
  1151         ps.add(cl.parentrevs(r)[1])
  1153     return subset & ps
  1152     return subset & ps
  1154 
  1153 
  1155 def parents(repo, subset, x):
  1154 def parents(repo, subset, x):
  1156     """``parents([set])``
  1155     """``parents([set])``
  1160         ps = tuple(p.rev() for p in repo[x].parents())
  1159         ps = tuple(p.rev() for p in repo[x].parents())
  1161         return subset & ps
  1160         return subset & ps
  1162 
  1161 
  1163     ps = set()
  1162     ps = set()
  1164     cl = repo.changelog
  1163     cl = repo.changelog
  1165     for r in getset(repo, baseset(repo), x):
  1164     for r in getset(repo, spanset(repo), x):
  1166         ps.update(cl.parentrevs(r))
  1165         ps.update(cl.parentrevs(r))
  1167     return subset & ps
  1166     return subset & ps
  1168 
  1167 
  1169 def parentspec(repo, subset, x, n):
  1168 def parentspec(repo, subset, x, n):
  1170     """``set^0``
  1169     """``set^0``