Commits

WAKAYAMA shirou committed 870d622

make a wrap function which can get a function is in the repo's capabilies or not.

  • Participants
  • Parent commits 05b5ec0

Comments (0)

Files changed (1)

         return peer(ui, opts, source)
     return hg.repository(ui, source)
 
-def getcaps(other):
-    return (getattr(other, '_caps', None) or
-            getattr(other, '_capabilities', None) or set())
+def capable(repo, name):
+    try:
+        return repo.capable(name)
+    except AttributeError:
+        # pre-2.3
+        if name in repo.capabilities:
+            return True
+        else:
+            return False
 
 def rdiff(ui, repo, url, lrev=None, rrev=None, *pats, **opts):
     def rui():
     ui.status(_('comparing with %s\n') % url)
 
     if rrev:
-        if 'lookup' in getcaps(other):
+        if capable(other, 'lookup'):
             rrev = other.lookup(rrev)
         else:
             error = _("Other repository doesn't support revision lookup, so a rev cannot be specified.")
     if not incoming:
         # remote is a subset of local
         if not rrev:
-            if 'lookup' in getcaps(other):
+            if capable(other, 'lookup'):
                 rrev = other.lookup('tip')
             else:
                 raise util.Abort(_('cannot determine remote tip'))
             if not rrev:
                 cg = other.changegroup(incoming, "incoming")
             else:
-                if 'changegroupsubset' not in other.capabilities:
+                if capable(other, 'changegroupsubset'):
                     raise util.Abort(_("Partial incoming cannot be done because other repository doesn't support changegroupsubset."))
                 cg = other.changegroupsubset(incoming, rrev and [rrev] or [],
                                              'incoming')