obsolete: simplify rebase wrapping code and change relation creation
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 08 Aug 2012 16:51:45 +0200
changeset 455 f46a41006136
parent 454 4e34a723115b
child 456 79aacd34bf1e
obsolete: simplify rebase wrapping code and change relation creation We have don't have changeset simply pruned by rebase. When they disapeared, that means that destination is a valid successors for them.
hgext/evolve.py
hgext/obsolete.py
tests/test-obsolete-rebase.t
tests/test-obsolete.t
--- a/hgext/evolve.py	Wed Aug 08 15:40:09 2012 +0200
+++ b/hgext/evolve.py	Wed Aug 08 16:51:45 2012 +0200
@@ -17,12 +17,11 @@
 from mercurial import commands
 from mercurial import bookmarks
 from mercurial import phases
-from mercurial import commands
 from mercurial import context
 from mercurial import copies
 from mercurial import util
 from mercurial.i18n import _
-from mercurial.commands import walkopts, commitopts, commitopts2, logopts
+from mercurial.commands import walkopts, commitopts, commitopts2
 from mercurial import hg
 
 ### util function
--- a/hgext/obsolete.py	Wed Aug 08 15:40:09 2012 +0200
+++ b/hgext/obsolete.py	Wed Aug 08 16:51:45 2012 +0200
@@ -988,35 +988,28 @@
                     # targetrev. If a source revision is mapped to targetrev
                     # or to another rebased revision, it must have been
                     # removed.
-                    targetrev = repo[repo._rebasetarget].rev()
-                    newrevs = set([targetrev])
-                    replacements = {}
-                    for rev, newrev in sorted(repo._rebasestate.items()):
-                        oldnode = repo[rev].node()
-                        if newrev not in newrevs:
-                            newnode = repo[newrev].node()
-                            newrevs.add(newrev)
-                        else:
-                            newnode = nullid
-                        replacements[oldnode] = newnode
-
+                    markers = []
                     if kwargs.get('collapse'):
-                        newnodes = set(n for n in replacements.values() if n != nullid)
-                        if newnodes:
-                            # Collapsing into more than one revision?
-                            assert len(newnodes) == 1, newnodes
-                            newnode = newnodes.pop()
-                            markers = [(repo[r], (repo[newnode],))
-                                       for r in replacements]
+                        # collapse assume revision disapear because they are all
+                        # in the created revision
+                        newrevs = set(repo._rebasestate.values())
+                        newrevs.remove(repo._rebasetarget)
+                        if newrevs:
+                            # we create new revision.
+                            # A single one by --collapse design
+                            assert len(newrevs) == 1
+                            new = tuple(repo[n] for n in newrevs)
                         else:
-                            newnode = nullid
-                            markers = [(repo[r], ())
-                                       for r in replacements]
-                        createmarkers(repo, markers)
-                    elif replacements:
-                        markers = [(repo[o], (() if n == nullid else (repo[n],)))
-                                   for o, n in replacements.iteritems()]
-                        createmarkers(repo, markers)
+                            # every body died. no new changeset created
+                            new = (repo[repo._rebasetarget],)
+                        for rev, newrev in sorted(repo._rebasestate.items()):
+                            markers.append((repo[rev], new))
+                    else:
+                        # no collapse assume revision disapear because they are
+                        # contained in parent
+                        for rev, newrev in sorted(repo._rebasestate.items()):
+                            markers.append((repo[rev], (repo[newrev],)))
+                    createmarkers(repo, markers)
             return res
         finally:
             l.release()
--- a/tests/test-obsolete-rebase.t	Wed Aug 08 15:40:09 2012 +0200
+++ b/tests/test-obsolete-rebase.t	Wed Aug 08 16:51:45 2012 +0200
@@ -106,7 +106,7 @@
   
   $ hg debugobsolete
   98e4a024635e8c50928144c9277a4388d26bd786 9c54949497631abfb5a255d96746bbd3a42ed2ba 0 {'date': '* *', 'user': 'test'} (glob)
-  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
+  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 540395c442253af3b991be882b539e7e198b5808 0 {'date': '* *', 'user': 'test'} (glob)
 
 Test rebase --collapse
 
@@ -141,7 +141,7 @@
   
   $ hg debugobsolete
   98e4a024635e8c50928144c9277a4388d26bd786 9c54949497631abfb5a255d96746bbd3a42ed2ba 0 {'date': '* *', 'user': 'test'} (glob)
-  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
+  4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 540395c442253af3b991be882b539e7e198b5808 0 {'date': '* *', 'user': 'test'} (glob)
   076e9b2ffbe11c7bcb9ee97f5c0c8b88a1a10b93 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
   03f31481307aaf5275d07ec28c1c59931759ccd2 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
 
@@ -209,9 +209,9 @@
   --- ../successors.old* (glob)
   +++ ../successors.new* (glob)
   @@ -2,3 +2,5 @@
-   4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 0 {'date': '* *', 'user': 'test'} (glob)
+   4e322f7ce8e3e4203950eac9ece27bf7e45ffa6c 540395c442253af3b991be882b539e7e198b5808 0 {'date': '* *', 'user': 'test'} (glob)
    076e9b2ffbe11c7bcb9ee97f5c0c8b88a1a10b93 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
    03f31481307aaf5275d07ec28c1c59931759ccd2 a7773ffa7edcfac27b5dcdb2d5c1036e15a49861 0 {'date': '* *', 'user': 'test'} (glob)
+  +a31943eabc4327df16f9eca71bf7779c32f815f7 03f165c84ea8889fc35a64a392caa7a0084dd212 0 {'date': '* *', 'user': 'test'} (glob)
   +4b9d80f48523e296f4402cc8e37236b768dfb981 1951ead9710803dbf117e95901954d5ed717f80b 0 {'date': '* *', 'user': 'test'} (glob)
-  +a31943eabc4327df16f9eca71bf7779c32f815f7 03f165c84ea8889fc35a64a392caa7a0084dd212 0 {'date': '* *', 'user': 'test'} (glob)
   [1]
--- a/tests/test-obsolete.t	Wed Aug 08 15:40:09 2012 +0200
+++ b/tests/test-obsolete.t	Wed Aug 08 16:51:45 2012 +0200
@@ -601,8 +601,8 @@
   909a0fb57e5d909f353d89e394ffd7e0890fec88 159dfc9fa5d334d7e03a0aecfc7f7ab4c3431fea 0 {'date': '', 'user': 'test'} (glob)
   1f0dee641bb7258c56bd60e93edfa2405381c41e 83b5778897adafb967ef2f75be3aaa4fce49a4cc 0 {'date': '', 'user': 'test'} (glob)
   83b5778897adafb967ef2f75be3aaa4fce49a4cc 0 {'date': '', 'user': 'test'} (glob)
+  0d3f46688ccc6e756c7e96cf64c391c411309597 2033b4e494742365851fac84d276640cbf52833e 0 {'date': '* *', 'user': 'test'} (glob)
   159dfc9fa5d334d7e03a0aecfc7f7ab4c3431fea 9468a5f5d8b2c5d91e17474e95ae4791e9718fdf 0 {'date': '* *', 'user': 'test'} (glob)
-  0d3f46688ccc6e756c7e96cf64c391c411309597 2033b4e494742365851fac84d276640cbf52833e 0 {'date': '* *', 'user': 'test'} (glob)
   9468a5f5d8b2c5d91e17474e95ae4791e9718fdf 6db5e282cb91df5c43ff1f1287c119ff83230d42 0 {'date': '', 'user': 'test'} (glob)
   0b1b6dd009c037985363e2290a0b579819f659db 3734a65252e69ddcced85901647a4f335d40de1e 0 {'date': '* *', 'user': 'test'} (glob)