drop repo.addobsolete
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 07 Aug 2012 18:26:13 +0200
changeset 444 aedb6b8ace86
parent 443 3f8c11865ed2
child 445 52b5e14c63d5
drop repo.addobsolete We now use createmarkers directly. No black magic with nullid is done anymore.
hgext/evolve.py
hgext/obsolete.py
tests/test-amend.t
tests/test-evolve.t
tests/test-obsolete-rebase.t
tests/test-stabilize-result.t
--- a/hgext/evolve.py	Tue Aug 07 18:05:41 2012 +0200
+++ b/hgext/evolve.py	Tue Aug 07 18:26:13 2012 +0200
@@ -159,13 +159,14 @@
             repo.ui.write_err(_('/!\\ use "hg up -C . ; hg stabilize --dry-run" /!\\\n'))
             raise
         oldbookmarks = repo.nodebookmarks(nodesrc)
+        obsolete = extensions.find('obsolete')
         if nodenew is not None:
             phases.retractboundary(repo, destphase, [nodenew])
-            repo.addobsolete(nodenew, nodesrc)
+            obsolete.createmarkers(repo, [(repo[nodesrc], (repo[nodenew],))])
             for book in oldbookmarks:
                 repo._bookmarks[book] = nodenew
         else:
-            repo.addobsolete(node.nullid, nodesrc)
+            obsolete.createmarkers(repo, [(repo[nodesrc], ())])
             # Behave like rebase, move bookmarks to dest
             for book in oldbookmarks:
                 repo._bookmarks[book] = dest.node()
@@ -355,25 +356,30 @@
     """
     wlock = repo.wlock()
     try:
-        new = set(noderange(repo, opts['new']))
-        targetnodes = set(noderange(repo, revs))
-        if not new:
-            new = [node.nullid]
-        for n in targetnodes:
-            if not repo[n].mutable():
-                ui.warn(_("cannot kill immutable changeset %s\n") % repo[n])
+        lock = repo.lock()
+        try:
+            new = set(noderange(repo, opts['new']))
+            targetnodes = set(noderange(repo, revs))
+            if new:
+                sucs = tuple(repo[n] for n in new)
             else:
-                for ne in new:
-                    repo.addobsolete(ne, n)
-        # update to an unkilled parent
-        wdp = repo['.']
-        newnode = wdp
-        while newnode.obsolete():
-            newnode = newnode.parents()[0]
-        if newnode.node() != wdp.node():
-            commands.update(ui, repo, newnode.rev())
-            ui.status(_('working directory now at %s\n') % newnode)
+                sucs = ()
+            markers = []
+            for n in targetnodes:
+                markers.append((repo[n], sucs))
+            obsolete = extensions.find('obsolete')
+            obsolete.createmarkers(repo, markers)
 
+            # update to an unkilled parent
+            wdp = repo['.']
+            newnode = wdp
+            while newnode.obsolete():
+                newnode = newnode.parents()[0]
+            if newnode.node() != wdp.node():
+                commands.update(ui, repo, newnode.rev())
+                ui.status(_('working directory now at %s\n') % newnode)
+        finally:
+            lock.release()
     finally:
         wlock.release()
 
@@ -465,7 +471,8 @@
                     # the intermediate revision if any. No need to update
                     # phases or parents.
                     if tempid is not None:
-                        repo.addobsolete(node.nullid, tempid)
+                        obsolete = extensions.find('obsolete')
+                        obsolete.createmarkers(repo, [(repo[tempid], ())])
                     # XXX: need another message in collapse case.
                     tr.close()
                     raise error.Abort(_('no updates found'))
@@ -601,7 +608,8 @@
             if newid is None:
                 raise util.Abort(_('nothing to uncommit'))
             # Move local changes on filtered changeset
-            repo.addobsolete(newid, old.node())
+            obsolete = extensions.find('obsolete')
+            obsolete.createmarkers(repo, [(old, (repo[newid],))])
             phases.retractboundary(repo, oldphase, [newid])
             repo.dirstate.setparents(newid, node.nullid)
             _uncommitdirstate(repo, old, match)
@@ -624,9 +632,13 @@
         if not result: # commit successed
             new = repo['-1']
             oldbookmarks = []
+            obsolete = extensions.find('obsolete')
+            markers = []
             for old in obsoleted:
                 oldbookmarks.extend(repo.nodebookmarks(old.node()))
-                repo.addobsolete(new.node(), old.node())
+                markers.append((old, (new,)))
+            if markers:
+                obsolete.createmarkers(repo, markers)
             for book in oldbookmarks:
                 repo._bookmarks[book] = new.node()
             if oldbookmarks:
--- a/hgext/obsolete.py	Tue Aug 07 18:05:41 2012 +0200
+++ b/hgext/obsolete.py	Tue Aug 07 18:26:13 2012 +0200
@@ -591,26 +591,6 @@
     finally:
         tr.release()
 
-@eh.reposetup
-def _repoobsutilsetup(ui, repo):
-    if not repo.local():
-        return
-
-    class obsoletingrepo(repo.__class__):
-
-        # XXX kill me
-        def addobsolete(self, sub, obj):
-            """Add a relation marking that node <sub> is a new version of <obj>"""
-            prec = repo[obj]
-            sucs = (sub == nullid) and [] or [repo[sub]]
-            lock = self.lock()
-            try:
-                createmarkers(self, [(prec, sucs)])
-            finally:
-                lock.release()
-
-    repo.__class__ = obsoletingrepo
-
 #####################################################################
 ### Extending revset and template                                 ###
 #####################################################################
@@ -901,9 +881,10 @@
                             markers = [(repo[r], ())
                                        for r in replacements]
                         createmarkers(repo, markers)
-                    else:
-                        for oldnode, newnode in replacements.iteritems():
-                            repo.addobsolete(newnode, oldnode)
+                    elif replacements:
+                        markers = [(repo[o], (() if n == nullid else (repo[n],)))
+                                   for o, n in replacements.iteritems()]
+                        createmarkers(repo, markers)
             return res
         finally:
             l.release()
--- a/tests/test-amend.t	Tue Aug 07 18:05:41 2012 +0200
+++ b/tests/test-amend.t	Tue Aug 07 18:26:13 2012 +0200
@@ -91,7 +91,7 @@
   $ hg debugobsolete
   bd19cbe78fbfbd87eb33420c63986fe5f3154f2c a34b93d251e49c93d5685ebacad785c73a7e8605 0 {'date': '* *', 'user': 'test'} (glob)
   07f4944404050f47db2e5c5071e0e84e7a27bba9 a34b93d251e49c93d5685ebacad785c73a7e8605 0 {'date': '* *', 'user': 'test'} (glob)
-  7384bbcba36fde1a789cd00f9cd6f9b919ab5910 0000000000000000000000000000000000000000 0 {'date': '* *', 'user': 'test'} (glob)
+  7384bbcba36fde1a789cd00f9cd6f9b919ab5910 0 {'date': '* *', 'user': 'test'} (glob)
   $ glog
   @  6@foo(draft) amends a34b93d251e49c93d5685ebacad785c73a7e8605
   |
--- a/tests/test-evolve.t	Tue Aug 07 18:05:41 2012 +0200
+++ b/tests/test-evolve.t	Tue Aug 07 18:26:13 2012 +0200
@@ -59,7 +59,8 @@
   $ hg log -r 1 --template '{rev} {phase} {obsolete}\n'
   1 public stable
   $ hg kill 1
-  cannot kill immutable changeset 7c3bad9141dc
+  abort: Cannot obsolete immutable changeset: 7c3bad9141dc
+  [255]
   $ hg log -r 1 --template '{rev} {phase} {obsolete}\n'
   1 public stable
 
--- a/tests/test-obsolete-rebase.t	Tue Aug 07 18:05:41 2012 +0200
+++ b/tests/test-obsolete-rebase.t	Tue Aug 07 18:26:13 2012 +0200
@@ -106,7 +106,7 @@
   
   $ hg debugobsolete
   98e4a024635e8c50928144c9277a4388d26bd786 9c54949497631abfb5a255d96746bbd3a42ed2ba 0 {'date': '* *', 'user': 'test'} (glob)
-  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0000000000000000000000000000000000000000 0 {'date': '* *', 'user': 'test'} (glob)
+  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
 
 Test rebase --collapse
 
@@ -141,7 +141,7 @@
   
   $ hg debugobsolete
   98e4a024635e8c50928144c9277a4388d26bd786 9c54949497631abfb5a255d96746bbd3a42ed2ba 0 {'date': '* *', 'user': 'test'} (glob)
-  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0000000000000000000000000000000000000000 0 {'date': '* *', 'user': 'test'} (glob)
+  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
   076e9b2ffbe11c7bcb9ee97f5c0c8b88a1a10b93 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
   03f31481307aaf5275d07ec28c1c59931759ccd2 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
 
@@ -209,7 +209,7 @@
   --- ../successors.old* (glob)
   +++ ../successors.new* (glob)
   @@ -2,3 +2,5 @@
-   4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0000000000000000000000000000000000000000 0 {'date': '* *', 'user': 'test'} (glob)
+   4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
    076e9b2ffbe11c7bcb9ee97f5c0c8b88a1a10b93 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
    03f31481307aaf5275d07ec28c1c59931759ccd2 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
   +4b9d80f48523e296f4402cc8e37236b768dfb981 1951ead9710803dbf117e95901954d5ed717f80b 0 {'date': '* *', 'user': 'test'} (glob)
--- a/tests/test-stabilize-result.t	Tue Aug 07 18:05:41 2012 +0200
+++ b/tests/test-stabilize-result.t	Tue Aug 07 18:26:13 2012 +0200
@@ -48,4 +48,4 @@
   $ hg debugobsolete
   41ad4fe8c79565a06c89f032ef0937b3cbd68a04 1447e1c4828d2347df8f858aa041305fa4cf7db1 0 {'date': '* *', 'user': 'test'} (glob)
   102a90ea7b4a3361e4082ed620918c261189a36a 1447e1c4828d2347df8f858aa041305fa4cf7db1 0 {'date': '* *', 'user': 'test'} (glob)
-  cce2c55b896511e0b6e04173c9450ba822ebc740 0000000000000000000000000000000000000000 0 {'date': '* *', 'user': 'test'} (glob)
+  cce2c55b896511e0b6e04173c9450ba822ebc740 0 {'date': '* *', 'user': 'test'} (glob)