changeset 74:c7dd26dec7fc

[obsolete] update docstring
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 13 Sep 2011 22:19:28 +0200
parents c0143040693b
children d7b11772f0b5
files hgext/obsolete.py
diffstat 1 files changed, 55 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/obsolete.py	Tue Sep 13 21:40:37 2011 +0200
+++ b/hgext/obsolete.py	Tue Sep 13 22:19:28 2011 +0200
@@ -101,6 +101,9 @@
 
 ohidden = context.changectx.hidden
 def hidden(ctx):
+    """hacked version fo hidden that also initialize hiddenrevs set
+
+    XXX we need something cleaner"""
     # hack to fill hiddenrevs
     # compute hidden (XXX should move elsewhere)
     if not getattr(ctx._repo.changelog, 'hiddeninit', False):
@@ -116,45 +119,53 @@
 #############################
 
 def revsetobsolete(repo, subset, x):
+    """filter obsolet entry"""
     args = revset.getargs(x, 0, 0, 'publicheads takes no arguments')
-    return [r for r in subset if repo[r].obsolete()] # XXX slow
+    # XXX slow stop using context
+    return [r for r in subset if repo[r].obsolete()]
 
 ### Other Extension compat
 ############################
 
 def concludenode(orig, repo, rev, *args, **kwargs):
+    """wrapper for rebase 's concludenode that set obsolete relation"""
     newrev = orig(repo, rev, *args, **kwargs)
     oldnode = repo[rev].node()
     newnode = repo[newrev].node()
     repo.addobsolete(newnode, oldnode)
     return newrev
 
+### Filter obsolet changeset
+############################
+
+def filterobsoleteout(orig, repo, remote, *args,**kwargs):
+    """wrapper for findcommonoutgoing that remove obsolete changeset
+
+    This behaviour is temporary"""
+    common, heads = orig(repo, remote, *args, **kwargs)
+
+    # filter obsolete
+    heads = set(map(repo.changelog.rev, heads))
+    obsoletes = set()
+    for obj in repo._obsobjrels:
+        try:
+            obsoletes.add(repo.changelog.rev(obj))
+        except error.LookupError:
+            pass # we don't have this node locally
+
+    outgoing = set(repo.changelog.ancestors(*heads))
+    outgoing.update(heads)
+
+    selected = outgoing - obsoletes
+    heads = sorted(map(repo.changelog.node, selected))
+
+    return common, heads
 
 def extsetup(ui):
     revset.symbols["obsolete"] = revsetobsolete
 
-    def filterobsoleteout(orig, repo, remote, *args,**kwargs):
-        common, heads = orig(repo, remote, *args, **kwargs)
+    extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout)
 
-        # filter obsolete
-        heads = set(map(repo.changelog.rev, heads))
-        obsoletes = set()
-        for obj in repo._obsobjrels:
-            try:
-                obsoletes.add(repo.changelog.rev(obj))
-            except error.LookupError:
-                pass # we don't have this node locally
-
-        outgoing = set(repo.changelog.ancestors(*heads))
-        outgoing.update(heads)
-
-        selected = outgoing - obsoletes
-        heads = sorted(map(repo.changelog.node, selected))
-
-        return common, heads
-
-    extensions.wrapfunction(discovery, 'findcommonoutgoing', filterobsoleteout)
-    
     try:
         rebase = extensions.find('rebase')
         if rebase:
@@ -166,6 +177,7 @@
 #########################################
 
 def pushobsolete(repo, key, old, raw):
+    """push obsolete relation through pushkey"""
     assert key == "relations"
     w = repo.wlock()
     try:
@@ -184,6 +196,9 @@
         w.release()
 
 def listobsolete(repo):
+    """dump all obsolete relation in
+
+    XXX this have be improved"""
     tmp = StringIO()
     _obsserialise(repo._obssubrels, tmp)
     return {'relations': tmp.getvalue()}
@@ -196,7 +211,7 @@
 
 def cmddebugobsolete(ui, repo, subject, object):
     """Add an obsolete relation between a too node
-    
+
     The subject is expected to be a newer version of the object"""
     sub = repo[subject]
     obj = repo[object]
@@ -209,11 +224,21 @@
 #############################
 
 def _obsserialise(obssubrels, flike):
+    """serialise an obsolete relation mapping in a plain text one
+
+    this is for subject -> [objects] mapping
+
+    format is::
+
+        <subject-full-hex> <object-full-hex>\n"""
     for sub, objs in obssubrels.iteritems():
         for obj in objs:
             flike.write('%s %s\n' % (hex(sub), hex(obj)))
 
 def _obsdeserialise(flike):
+    """read a file like object serialised with _obsserialise
+
+    this desierialize into a {subject -> objects} mapping"""
     rels = {}
     for line in flike:
         subhex, objhex = line.split()
@@ -229,6 +254,7 @@
     opush = repo.push
     orollback = repo.rollback
     o_writejournal = repo._writejournal
+    ocancopy = repo.cancopy
 
     class obsoletingrepo(repo.__class__):
 
@@ -298,11 +324,13 @@
         ### local clone support
 
         def cancopy(self):
-            return not bool(self._obsobjrels) # you can't copy if there is obsolete
+            """wrapper on cancopy that deny copy if there is obsolete relation"""
+            return ocancopy() and not bool(self._obsobjrels)  # you can't copy if there is obsolete
 
         ### pull // push support
 
         def pull(self, remote, *args, **kwargs):
+            """wrapper around push that push obsolete relation"""
             result = opull(remote, *args, **kwargs)
             if 'obsolete' in remote.listkeys('namespaces'):
                 tmp = StringIO()
@@ -315,6 +343,7 @@
             return result
 
         def push(self, remote, *args, **opts):
+            """wrapper around pull that pull obsolete relation"""
             result = opush(remote, *args, **opts)
             if 'obsolete' in remote.listkeys('namespaces'):
                 tmp = StringIO()
@@ -328,6 +357,7 @@
         ### rollback support
 
         def _writejournal(self, desc):
+            """wrapped version of _writejournal that save obsolete data"""
             entries = list(o_writejournal(desc))
             filename = 'obsolete-relations'
             filepath = self.join(filename)
@@ -339,6 +369,7 @@
             return tuple(entries)
 
         def rollback(self, dryrun=False):
+            """wrapped version of rollback that restore obsolete data"""
             wlock = lock = None
             try:
                 wlock = self.wlock()