~ubuntu-branches/ubuntu/precise/mercurial/precise-updates

« back to all changes in this revision

Viewing changes to mercurial/revset.py

  • Committer: Bazaar Package Importer
  • Author(s): Javi Merino
  • Date: 2011-03-06 16:01:58 UTC
  • mto: (28.1.2 sid) (1.1.14)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20110306160158-y94pzpmtd7b1xgjk
Tags: upstream-1.8
ImportĀ upstreamĀ versionĀ 1.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
import re
9
9
import parser, util, error, discovery
 
10
import bookmarks as bookmarksmod
10
11
import match as matchmod
11
12
from i18n import _, gettext
12
13
 
202
203
    return [r for r in subset if r == l]
203
204
 
204
205
def p1(repo, subset, x):
205
 
    """``p1(set)``
206
 
    First parent of changesets in set.
 
206
    """``p1([set])``
 
207
    First parent of changesets in set, or the working directory.
207
208
    """
 
209
    if x is None:
 
210
        p = repo[x].parents()[0].rev()
 
211
        return [r for r in subset if r == p]
 
212
 
208
213
    ps = set()
209
214
    cl = repo.changelog
210
215
    for r in getset(repo, range(len(repo)), x):
212
217
    return [r for r in subset if r in ps]
213
218
 
214
219
def p2(repo, subset, x):
215
 
    """``p2(set)``
216
 
    Second parent of changesets in set.
 
220
    """``p2([set])``
 
221
    Second parent of changesets in set, or the working directory.
217
222
    """
 
223
    if x is None:
 
224
        ps = repo[x].parents()
 
225
        try:
 
226
            p = ps[1].rev()
 
227
            return [r for r in subset if r == p]
 
228
        except IndexError:
 
229
            return []
 
230
 
218
231
    ps = set()
219
232
    cl = repo.changelog
220
233
    for r in getset(repo, range(len(repo)), x):
222
235
    return [r for r in subset if r in ps]
223
236
 
224
237
def parents(repo, subset, x):
225
 
    """``parents(set)``
226
 
    The set of all parents for all changesets in set.
 
238
    """``parents([set])``
 
239
    The set of all parents for all changesets in set, or the working directory.
227
240
    """
 
241
    if x is None:
 
242
        ps = tuple(p.rev() for p in repo[x].parents())
 
243
        return [r for r in subset if r in ps]
 
244
 
228
245
    ps = set()
229
246
    cl = repo.changelog
230
247
    for r in getset(repo, range(len(repo)), x):
648
665
def tagged(repo, subset, x):
649
666
    return tag(repo, subset, x)
650
667
 
 
668
def bookmark(repo, subset, x):
 
669
    """``bookmark([name])``
 
670
    The named bookmark or all bookmarks.
 
671
    """
 
672
    # i18n: "bookmark" is a keyword
 
673
    args = getargs(x, 0, 1, _('bookmark takes one or no arguments'))
 
674
    if args:
 
675
        bm = getstring(args[0],
 
676
                       # i18n: "bookmark" is a keyword
 
677
                       _('the argument to bookmark must be a string'))
 
678
        bmrev = bookmarksmod.listbookmarks(repo).get(bm, None)
 
679
        if bmrev:
 
680
            bmrev = repo[bmrev].rev()
 
681
        return [r for r in subset if r == bmrev]
 
682
    bms = set([repo[r].rev()
 
683
               for r in bookmarksmod.listbookmarks(repo).values()])
 
684
    return [r for r in subset if r in bms]
 
685
 
651
686
symbols = {
652
687
    "adds": adds,
653
688
    "all": getall,
654
689
    "ancestor": ancestor,
655
690
    "ancestors": ancestors,
656
691
    "author": author,
 
692
    "bookmark": bookmark,
657
693
    "branch": branch,
658
694
    "children": children,
659
695
    "closed": closed,
699
735
}
700
736
 
701
737
def optimize(x, small):
702
 
    if x == None:
 
738
    if x is None:
703
739
        return 0, x
704
740
 
705
741
    smallbonus = 1
758
794
            w = 100 # very slow
759
795
        elif f == "ancestor":
760
796
            w = 1 * smallbonus
761
 
        elif f == "reverse limit":
 
797
        elif f in "reverse limit":
762
798
            w = 0
763
799
        elif f in "sort":
764
800
            w = 10 # assume most sorts look at changelog