diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -2529,6 +2529,17 @@ def debugwalk(ui, repo, *pats, **opts): line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '') ui.write("%s\n" % line.rstrip()) +@command('debugwhyunstable', [], _('REV')) +def debugwhyunstable(ui, repo, rev): + """explain instabilities of a changeset""" + for entry in obsutil.whyunstable(repo, repo[rev]): + dnodes = '' + if entry.get('divergentnodes'): + dnodes = ' '.join('%s (%s)' % (ctx.hex(), ctx.phasestr()) + for ctx in entry['divergentnodes']) + ' ' + ui.write('%s: %s%s %s\n' % (entry['instability'], dnodes, + entry['reason'], entry['node'])) + @command('debugwireargs', [('', 'three', '', 'three'), ('', 'four', '', 'four'), diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py --- a/mercurial/obsutil.py +++ b/mercurial/obsutil.py @@ -923,3 +923,55 @@ def _getfilteredreason(repo, changeid, c args = (changeid, firstsuccessors, remainingnumber) return filteredmsgtable['superseded_split_several'] % args + +def divergentsets(repo, ctx): + """Compute sets of commits divergent with a given one""" + cache = {} + base = {} + for n in allpredecessors(repo.obsstore, [ctx.node()]): + if n == ctx.node(): + # a node can't be a base for divergence with itself + continue + nsuccsets = successorssets(repo, n, cache) + for nsuccset in nsuccsets: + if ctx.node() in nsuccset: + # we are only interested in *other* successor sets + continue + if tuple(nsuccset) in base: + # we already know the latest base for this divergency + continue + base[tuple(nsuccset)] = n + return [{'divergentnodes': divset, 'commonpredecessor': b} + for divset, b in base.iteritems()] + +def whyunstable(repo, ctx): + result = [] + if ctx.orphan(): + for parent in ctx.parents(): + kind = None + if parent.orphan(): + kind = 'orphan' + elif parent.obsolete(): + kind = 'obsolete' + if kind is not None: + result.append({'instability': 'orphan', + 'reason': '%s parent' % kind, + 'node': parent.hex()}) + if ctx.phasedivergent(): + predecessors = allpredecessors(repo.obsstore, [ctx.node()], + ignoreflags=bumpedfix) + immutable = [repo[p] for p in predecessors + if p in repo and not repo[p].mutable()] + for predecessor in immutable: + result.append({'instability': 'phase-divergent', + 'reason': 'immutable predecessor', + 'node': predecessor.hex()}) + if ctx.contentdivergent(): + dsets = divergentsets(repo, ctx) + for dset in dsets: + divnodes = [repo[n] for n in dset['divergentnodes']] + result.append({'instability': 'content-divergent', + 'divergentnodes': divnodes, + 'reason': 'predecessor', + 'node': nodemod.hex(dset['commonpredecessor'])}) + return result diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -122,6 +122,7 @@ Show debug commands if there are no othe debugupdatecaches debugupgraderepo debugwalk + debugwhyunstable debugwireargs debugwireproto @@ -306,6 +307,7 @@ Show all commands + options debugupdatecaches: debugupgraderepo: optimize, run debugwalk: include, exclude + debugwhyunstable: debugwireargs: three, four, five, ssh, remotecmd, insecure debugwireproto: localssh, peer, noreadstderr, ssh, remotecmd, insecure files: rev, print0, include, exclude, template, subrepos diff --git a/tests/test-help.t b/tests/test-help.t --- a/tests/test-help.t +++ b/tests/test-help.t @@ -985,6 +985,8 @@ Test list of internal help commands debugupgraderepo upgrade a repository to use different features debugwalk show how files match on given patterns + debugwhyunstable + explain instabilities of a changeset debugwireargs (no help text available) debugwireproto diff --git a/tests/test-obsolete-divergent.t b/tests/test-obsolete-divergent.t --- a/tests/test-obsolete-divergent.t +++ b/tests/test-obsolete-divergent.t @@ -717,3 +717,6 @@ Use scmutil.cleanupnodes API to create d a178212c3433c4e77b573f6011e29affb8aefa33 1a2a9b5b0030632400aa78e00388c20f99d3ec44 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '1', 'operation': 'amend', 'user': 'test'} a178212c3433c4e77b573f6011e29affb8aefa33 ad6478fb94ecec98b86daae98722865d494ac561 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '13', 'operation': 'test', 'user': 'test'} ad6478fb94ecec98b86daae98722865d494ac561 70d5a63ca112acb3764bc1d7320ca90ea688d671 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '9', 'operation': 'test', 'user': 'test'} + + $ hg debugwhyunstable 1a2a9b5b0030 + content-divergent: 70d5a63ca112acb3764bc1d7320ca90ea688d671 (draft) predecessor a178212c3433c4e77b573f6011e29affb8aefa33 diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t --- a/tests/test-obsolete.t +++ b/tests/test-obsolete.t @@ -1033,6 +1033,12 @@ test summary output orphan: 2 changesets phase-divergent: 1 changesets +test debugwhyunstable output + + $ hg debugwhyunstable 50c51b361e60 + orphan: obsolete parent 3de5eca88c00aa039da7399a220f4a5221faa585 + phase-divergent: immutable predecessor 245bde4270cd1072a27757984f9cda8ba26f08ca + #if serve $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -A access.log -E errors.log