comparison mercurial/revset.py @ 12928:a5f7f1e9340e

revsets: let p1() and p2() return parents of working dir This patch makes the 'set' argument to revset functions p1() and p2() optional. If no argument is given, p1() and p2() return the first or second parent of the working directory. If the working directory is not an in-progress merge (no 2nd parent), p2() returns the empty set. For a checkout of the null changeset, both p1() and p2() return the empty set.
author Kevin Bullock <kbullock@ringworld.org>
date Thu, 04 Nov 2010 16:59:03 -0500
parents 76066903ae08
children 515c2786e1cf
comparison
equal deleted inserted replaced
12927:b6245c2470a9 12928:a5f7f1e9340e
200 # i18n: "rev" is a keyword 200 # i18n: "rev" is a keyword
201 raise error.ParseError(_("rev expects a number")) 201 raise error.ParseError(_("rev expects a number"))
202 return [r for r in subset if r == l] 202 return [r for r in subset if r == l]
203 203
204 def p1(repo, subset, x): 204 def p1(repo, subset, x):
205 """``p1(set)`` 205 """``p1([set])``
206 First parent of changesets in set. 206 First parent of changesets in set, or the working directory.
207 """ 207 """
208 if x is None:
209 return [repo[x].parents()[0].rev()]
210
208 ps = set() 211 ps = set()
209 cl = repo.changelog 212 cl = repo.changelog
210 for r in getset(repo, range(len(repo)), x): 213 for r in getset(repo, range(len(repo)), x):
211 ps.add(cl.parentrevs(r)[0]) 214 ps.add(cl.parentrevs(r)[0])
212 return [r for r in subset if r in ps] 215 return [r for r in subset if r in ps]
213 216
214 def p2(repo, subset, x): 217 def p2(repo, subset, x):
215 """``p2(set)`` 218 """``p2([set])``
216 Second parent of changesets in set. 219 Second parent of changesets in set, or the working directory.
217 """ 220 """
221 if x is None:
222 ps = repo[x].parents()
223 try:
224 return [ps[1].rev()]
225 except IndexError:
226 return []
227
218 ps = set() 228 ps = set()
219 cl = repo.changelog 229 cl = repo.changelog
220 for r in getset(repo, range(len(repo)), x): 230 for r in getset(repo, range(len(repo)), x):
221 ps.add(cl.parentrevs(r)[1]) 231 ps.add(cl.parentrevs(r)[1])
222 return [r for r in subset if r in ps] 232 return [r for r in subset if r in ps]