obsolete: reports the number of local changeset obsoleted when unbundling
This is a first basic visible usage of the changes tracking in the transaction.
We adds a new function computing the pre-existing changesets obsoleted by a
transaction and a transaction call back displaying this information.
Example output:
added 1 changesets with 1 changes to 1 files (+1 heads)
3 new obsolescence markers
obsoleted 1 changesets
The goal is to evolve the transaction summary into something bigger, gathering
existing output there and adding new useful one. This patch is a good first step
on this road. The new output is basic but give a user to the content of
tr.changes['obsmarkers'] and give an idea of the new options we haves. I expect
to revisit the message soon.
The caller recording the transaction summary should also be moved into a more
generic location but further refactoring is needed before it can happen.
--- a/mercurial/bundle2.py Tue Jun 27 02:45:09 2017 +0200
+++ b/mercurial/bundle2.py Wed Jun 28 03:54:19 2017 +0200
@@ -161,6 +161,7 @@
phases,
pushkey,
pycompat,
+ scmutil,
tags,
url,
util,
@@ -1810,6 +1811,7 @@
if new:
op.repo.ui.status(_('%i new obsolescence markers\n') % new)
op.records.add('obsmarkers', {'new': new})
+ scmutil.registersummarycallback(op.repo, tr)
if op.reply is not None:
rpart = op.reply.newpart('reply:obsmarkers')
rpart.addparam('in-reply-to', str(inpart.id), mandatory=False)
--- a/mercurial/obsutil.py Tue Jun 27 02:45:09 2017 +0200
+++ b/mercurial/obsutil.py Wed Jun 28 03:54:19 2017 +0200
@@ -7,6 +7,10 @@
from __future__ import absolute_import
+from . import (
+ phases,
+)
+
class marker(object):
"""Wrap obsolete marker raw data"""
@@ -285,6 +289,28 @@
foreground = set(repo.set('%ln::', known))
return set(c.node() for c in foreground)
+def getobsoleted(repo, tr):
+ """return the set of pre-existing revisions obsoleted by a transaction"""
+ torev = repo.unfiltered().changelog.nodemap.get
+ phase = repo._phasecache.phase
+ succsmarkers = repo.obsstore.successors.get
+ public = phases.public
+ addedmarkers = tr.changes.get('obsmarkers')
+ addedrevs = tr.changes.get('revs')
+ seenrevs = set(addedrevs)
+ obsoleted = set()
+ for mark in addedmarkers:
+ node = mark[0]
+ rev = torev(node)
+ if rev is None or rev in seenrevs:
+ continue
+ seenrevs.add(rev)
+ if phase(repo, rev) == public:
+ continue
+ if set(succsmarkers(node)).issubset(addedmarkers):
+ obsoleted.add(rev)
+ return obsoleted
+
def successorssets(repo, initialnode, cache=None):
"""Return set of all latest successors of initial nodes
--- a/mercurial/scmutil.py Tue Jun 27 02:45:09 2017 +0200
+++ b/mercurial/scmutil.py Wed Jun 28 03:54:19 2017 +0200
@@ -13,6 +13,7 @@
import os
import re
import socket
+import weakref
from .i18n import _
from .node import (
@@ -22,11 +23,13 @@
wdirrev,
)
+from .i18n import _
from . import (
encoding,
error,
match as matchmod,
obsolete,
+ obsutil,
pathutil,
phases,
pycompat,
@@ -1059,3 +1062,15 @@
lines.append("%s=%s\n" % (k, v))
with self.vfs(self.path, mode='wb', atomictemp=True) as fp:
fp.write(''.join(lines))
+
+def registersummarycallback(repo, otr):
+ """register a callback to issue a summary after the transaction is closed
+ """
+ reporef = weakref.ref(repo)
+ def reportsummary(tr):
+ """the actual callback reporting the summary"""
+ repo = reporef()
+ obsoleted = obsutil.getobsoleted(repo, tr)
+ if obsoleted:
+ repo.ui.status(_('obsoleted %i changesets\n') % len(obsoleted))
+ otr.addpostclose('00-txnreport', reportsummary)
--- a/tests/test-bookmarks-pushpull.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-bookmarks-pushpull.t Wed Jun 28 03:54:19 2017 +0200
@@ -484,6 +484,7 @@
remote: adding file changes
remote: added 2 changesets with 2 changes to 1 files (+1 heads)
remote: 2 new obsolescence markers
+ remote: obsoleted 1 changesets
updating bookmark Y
$ hg -R ../a book
@ 1:0d2164f0ce0d
--- a/tests/test-exchange-obsmarkers-case-A3.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-exchange-obsmarkers-case-A3.t Wed Jun 28 03:54:19 2017 +0200
@@ -212,6 +212,7 @@
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files (+1 heads)
remote: 1 new obsolescence markers
+ remote: obsoleted 1 changesets
## post push state
# obstore: main
28b51eb45704506b5c603decd6bf7ac5e0f6a52f e5ea8f9c73143125d36658e90ef70c6d2027a5b7 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
@@ -227,6 +228,7 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
(run 'hg heads' to see heads, 'hg merge' to merge)
## post pull state
# obstore: main
--- a/tests/test-exchange-obsmarkers-case-A6.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-exchange-obsmarkers-case-A6.t Wed Jun 28 03:54:19 2017 +0200
@@ -97,6 +97,7 @@
searching for changes
no changes found
remote: 1 new obsolescence markers
+ remote: obsoleted 1 changesets
## post push state
# obstore: main
28b51eb45704506b5c603decd6bf7ac5e0f6a52f e5ea8f9c73143125d36658e90ef70c6d2027a5b7 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
@@ -107,6 +108,7 @@
pulling from main
no changes found
1 new obsolescence markers
+ obsoleted 1 changesets
## post pull state
# obstore: main
28b51eb45704506b5c603decd6bf7ac5e0f6a52f e5ea8f9c73143125d36658e90ef70c6d2027a5b7 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
@@ -130,6 +132,7 @@
searching for changes
no changes found
remote: 1 new obsolescence markers
+ remote: obsoleted 1 changesets
## post push state
# obstore: main
28b51eb45704506b5c603decd6bf7ac5e0f6a52f e5ea8f9c73143125d36658e90ef70c6d2027a5b7 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
@@ -141,6 +144,7 @@
searching for changes
no changes found
1 new obsolescence markers
+ obsoleted 1 changesets
## post pull state
# obstore: main
28b51eb45704506b5c603decd6bf7ac5e0f6a52f e5ea8f9c73143125d36658e90ef70c6d2027a5b7 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'}
--- a/tests/test-obsmarker-template.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-obsmarker-template.t Wed Jun 28 03:54:19 2017 +0200
@@ -735,6 +735,7 @@
adding file changes
added 1 changesets with 0 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 1 changesets
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg log --hidden -G
o changeset: 2:7a230b46bf61
--- a/tests/test-obsolete-bundle-strip.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-obsolete-bundle-strip.t Wed Jun 28 03:54:19 2017 +0200
@@ -205,6 +205,7 @@
# unbundling: adding file changes
# unbundling: added 1 changesets with 1 changes to 1 files (+1 heads)
# unbundling: 2 new obsolescence markers
+ # unbundling: obsoleted 1 changesets
# unbundling: (run 'hg heads' to see heads)
$ testrevs 'desc("C-A")'
@@ -366,6 +367,7 @@
# unbundling: adding file changes
# unbundling: added 1 changesets with 1 changes to 1 files (+1 heads)
# unbundling: 1 new obsolescence markers
+ # unbundling: obsoleted 1 changesets
# unbundling: (run 'hg heads' to see heads)
bundling multiple revisions
@@ -957,6 +959,7 @@
# unbundling: adding file changes
# unbundling: added 1 changesets with 1 changes to 1 files (+1 heads)
# unbundling: 6 new obsolescence markers
+ # unbundling: obsoleted 3 changesets
# unbundling: (run 'hg heads' to see heads)
Bundle multiple revisions
@@ -1057,6 +1060,7 @@
# unbundling: adding file changes
# unbundling: added 2 changesets with 2 changes to 2 files (+2 heads)
# unbundling: 7 new obsolescence markers
+ # unbundling: obsoleted 2 changesets
# unbundling: (run 'hg heads' to see heads)
* top one and initial precursors
@@ -1122,6 +1126,7 @@
# unbundling: adding file changes
# unbundling: added 2 changesets with 2 changes to 2 files (+2 heads)
# unbundling: 6 new obsolescence markers
+ # unbundling: obsoleted 3 changesets
# unbundling: (run 'hg heads' to see heads)
* top one and one of the split
@@ -1189,6 +1194,7 @@
# unbundling: adding file changes
# unbundling: added 2 changesets with 2 changes to 2 files (+2 heads)
# unbundling: 7 new obsolescence markers
+ # unbundling: obsoleted 2 changesets
# unbundling: (run 'hg heads' to see heads)
* all
--- a/tests/test-obsolete.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-obsolete.t Wed Jun 28 03:54:19 2017 +0200
@@ -613,6 +613,7 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
test relevance computation
---------------------------------------
--- a/tests/test-push-checkheads-pruned-B1.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B1.t Wed Jun 28 03:54:19 2017 +0200
@@ -68,5 +68,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B2.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B2.t Wed Jun 28 03:54:19 2017 +0200
@@ -81,5 +81,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B3.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B3.t Wed Jun 28 03:54:19 2017 +0200
@@ -81,6 +81,7 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B4.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B4.t Wed Jun 28 03:54:19 2017 +0200
@@ -82,5 +82,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B5.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B5.t Wed Jun 28 03:54:19 2017 +0200
@@ -88,5 +88,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
3 new obsolescence markers
+ obsoleted 3 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B6.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B6.t Wed Jun 28 03:54:19 2017 +0200
@@ -74,5 +74,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B7.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B7.t Wed Jun 28 03:54:19 2017 +0200
@@ -73,5 +73,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-pruned-B8.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-pruned-B8.t Wed Jun 28 03:54:19 2017 +0200
@@ -94,5 +94,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
4 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A1.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A1.t Wed Jun 28 03:54:19 2017 +0200
@@ -65,5 +65,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A2.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A2.t Wed Jun 28 03:54:19 2017 +0200
@@ -83,5 +83,6 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A3.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A3.t Wed Jun 28 03:54:19 2017 +0200
@@ -86,5 +86,6 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A4.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A4.t Wed Jun 28 03:54:19 2017 +0200
@@ -70,5 +70,6 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../../
--- a/tests/test-push-checkheads-superceed-A5.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A5.t Wed Jun 28 03:54:19 2017 +0200
@@ -70,6 +70,7 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A6.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A6.t Wed Jun 28 03:54:19 2017 +0200
@@ -94,5 +94,6 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A7.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A7.t Wed Jun 28 03:54:19 2017 +0200
@@ -94,5 +94,6 @@
adding file changes
added 2 changesets with 2 changes to 2 files (+1 heads)
2 new obsolescence markers
+ obsoleted 2 changesets
$ cd ../..
--- a/tests/test-push-checkheads-superceed-A8.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-superceed-A8.t Wed Jun 28 03:54:19 2017 +0200
@@ -75,5 +75,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
2 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-unpushed-D4.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-unpushed-D4.t Wed Jun 28 03:54:19 2017 +0200
@@ -118,5 +118,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-unpushed-D5.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-unpushed-D5.t Wed Jun 28 03:54:19 2017 +0200
@@ -103,5 +103,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files
1 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-checkheads-unpushed-D7.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-checkheads-unpushed-D7.t Wed Jun 28 03:54:19 2017 +0200
@@ -92,5 +92,6 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
3 new obsolescence markers
+ obsoleted 1 changesets
$ cd ../..
--- a/tests/test-push-race.t Tue Jun 27 02:45:09 2017 +0200
+++ b/tests/test-push-race.t Wed Jun 28 03:54:19 2017 +0200
@@ -1665,6 +1665,7 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
(run 'hg heads .' to see heads, 'hg merge' to merge)
$ hg -R ./client-other pull
pulling from ssh://user@dummy/server
@@ -1674,6 +1675,7 @@
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
1 new obsolescence markers
+ obsoleted 1 changesets
(run 'hg heads .' to see heads, 'hg merge' to merge)
$ hg -R ./client-racy pull
pulling from ssh://user@dummy/server
@@ -1770,6 +1772,7 @@
remote: adding file changes
remote: added 1 changesets with 0 changes to 1 files (+1 heads)
remote: 1 new obsolescence markers
+ remote: obsoleted 1 changesets
$ release $TESTTMP/watchfile