Commits

Dan Villiom Podlaski Christiansen  committed a171231

add a revset and a template keyword

  • Participants
  • Parent commits d7b724e

Comments (0)

Files changed (1)

     util_setflags = util.set_flags
     revpair = cmdutil.revpair
 
+from mercurial import revset
+from mercurial import templatekw
+
 def uisetup(ui):
     '''monkeypatch pull and push for p4:// support'''
 
 
     ui.write("%s\n" % ' '.join(output))
 
+def revsetp4(repo, subset, x):
+    """``p4([changelist])``
+    Matches all changesets from Perforce, or the ones from the given changelist.
+    """
+    args = revset.getargs(x, 0, 1, 'p4 takes one or no arguments')
+    if args:
+        changelist = revset.getstring(args[0],
+                                      'the argument to p4 must be a string')
+
+        return [r for r in subset if repo[r].extra().get('p4') == changelist]
+    else:
+        return [r for r in subset if repo[r].extra().get('p4')]
+
+def kwp4changelist(repo, ctx, **args):
+    """:p4changelist: String. Converted Perforce changelist, if any."""
+    return ctx.extra().get('p4') or ''
+
+def extsetup(ui):
+    revset.symbols['p4'] = revsetp4
+    templatekw.keywords['p4changelist'] = kwp4changelist
 
 cmdtable = {
     # 'command-name': (function-call, options-list, help-string)