##// END OF EJS Templates
rebase: do not invent successor to skipped changeset...
rebase: do not invent successor to skipped changeset When rebase results in an empty a changeset it is "skipped" and no related changeset is created at all. When we added obsolescence support to rebase (in fc2a6114f0a0) it seemed a good idea to use its parent successor as the successors for such dropped changesets. (see old version of the altered test). This option was chosen because it seems a good way to hint about were the dropped changeset "intended" to be. Such hint would have been used by automatic evolution mechanism to rebase potential unstable children. However, field testing of this version are not conclusive. It very often leads to the creation of (totally unfounded) evolution divergence. This changeset changes this behavior and mark skipped changesets as pruned (obsolete without successors). This prevents the issue and seems semantically better probably a win for obsolescence reading tool. See example bellow for details: User Babar has five changesets of interest: - O, its current base of development. - U, the new upstream - A and C, some development changesets - B another development changeset independent from A O - A - B - C \ U Babar decides that B is more critical than the A and C and rebase it first $ hg rebase --rev B --dest U B is now obsolete (in lower case bellow). Rebase result, B', is its successors.(note, C is unstable) O - A - b - C \ U - B' Babar is now done with B', and want to rebase the rest of its history: $ hg rebase --source A --dest B' hg rebase process A, B and C. B is skipped as all its changes are already contained in B'. O - U - B' - A' - C' Babar have the expected result graph wise, obsolescence marker are as follow: B -> B' (from first rebase) A -> A' (from second rebase) C -> C' (from second rebase) B -> ?? (from second rebase) Before this changeset, the last marker is `B -> A'`. This cause two issues: - This is semantically wrong. B have nothing to do with A' - B has now two successors sets: (B',) and (A',). We detect a divergent rewriting. The B' and A' are reported as "divergent" to Babar, confusion ensues. In addition such divergent situation (divergent changeset are children to each other) is tricky to solve. With this changeset the last marker is `B -> ΓΈ`: - This is semantically better. - B has a single successors set (B',) This scenario is added to the tests suite.

File last commit:

r18443:64848f7f default
r18444:55aff0c2 default
Show More
repoview.py
196 lines | 7.5 KiB | text/x-python | PythonLexer
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 # repoview.py - Filtered view of a localrepo object
#
# Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Logilab SA <contact@logilab.fr>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
import copy
Pierre-Yves David
clfilter: introduce a "unserver" filtering mode...
r18102 import phases
Pierre-Yves David
clfilter: add mutable filtering...
r18245 import util
Pierre-Yves David
performance: speedup computation of hidden revisions...
r18272 import obsolete, bookmarks, revset
Pierre-Yves David
clfilter: introduce a "unserver" filtering mode...
r18102
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293 def hideablerevs(repo):
"""Revisions candidates to be hidden
This is a standalone function to help extensions to wrap it."""
return obsolete.getrevs(repo, 'obsolete')
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242 def computehidden(repo):
"""compute the set of hidden revision to filter
During most operation hidden should be filtered."""
assert not repo.changelog.filteredrevs
Pierre-Yves David
repoview: extract hideable revision computation in a dedicated function...
r18293 hideable = hideablerevs(repo)
Pierre-Yves David
performance: speedup computation of hidden revisions...
r18272 if hideable:
cl = repo.changelog
firsthideable = min(hideable)
revs = cl.revs(start=firsthideable)
blockers = [r for r in revset._children(repo, revs, hideable)
if r not in hideable]
for par in repo[None].parents():
blockers.append(par.rev())
for bm in bookmarks.listbookmarks(repo).values():
blockers.append(repo[bm].rev())
blocked = cl.ancestors(blockers, inclusive=True)
return frozenset(r for r in hideable if r not in blocked)
Pierre-Yves David
clfilter: introduces a hidden filter...
r18242 return frozenset()
Pierre-Yves David
clfilter: introduce a "unserver" filtering mode...
r18102 def computeunserved(repo):
"""compute the set of revision that should be filtered when used a server
Secret and hidden changeset should not pretend to be here."""
assert not repo.changelog.filteredrevs
# fast path in simple case to avoid impact of non optimised code
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 hiddens = filterrevs(repo, 'visible')
Pierre-Yves David
performance: speedup computation of unserved revisions...
r18273 if phases.hassecret(repo):
cl = repo.changelog
secret = phases.secret
getphase = repo._phasecache.phase
first = min(cl.rev(n) for n in repo._phasecache.phaseroots[secret])
revs = cl.revs(start=first)
secrets = set(r for r in revs if getphase(repo, r) >= secret)
return frozenset(hiddens | secrets)
else:
return hiddens
Pierre-Yves David
clfilter: use empty frozenset intead of empty tuple...
r18231 return frozenset()
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Pierre-Yves David
clfilter: add mutable filtering...
r18245 def computemutable(repo):
"""compute the set of revision that should be filtered when used a server
Secret and hidden changeset should not pretend to be here."""
assert not repo.changelog.filteredrevs
# fast check to avoid revset call on huge repo
if util.any(repo._phasecache.phaseroots[1:]):
Pierre-Yves David
performance: speedup computation of mutable revisions...
r18274 getphase = repo._phasecache.phase
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 maymutable = filterrevs(repo, 'base')
Pierre-Yves David
performance: speedup computation of mutable revisions...
r18274 return frozenset(r for r in maymutable if getphase(repo, r))
Pierre-Yves David
clfilter: add mutable filtering...
r18245 return frozenset()
Pierre-Yves David
clfilter: add impactable filter...
r18246 def computeimpactable(repo):
"""Everything impactable by mutable revision
The mutable filter still have some chance to get invalidated. This will
happen when:
- you garbage collect hidden changeset,
- public phase is moved backward,
- something is changed in the filtering (this could be fixed)
This filter out any mutable changeset and any public changeset that may be
impacted by something happening to a mutable revision.
This is achieved by filtered everything with a revision number egal or
higher than the first mutable changeset is filtered."""
assert not repo.changelog.filteredrevs
cl = repo.changelog
firstmutable = len(cl)
for roots in repo._phasecache.phaseroots[1:]:
if roots:
firstmutable = min(firstmutable, min(cl.rev(r) for r in roots))
Pierre-Yves David
repoview: protect `base` computation from weird phase root...
r18443 # protect from nullrev root
firstmutable = max(0, firstmutable)
Pierre-Yves David
clfilter: add impactable filter...
r18246 return frozenset(xrange(firstmutable, len(cl)))
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 # function to compute filtered set
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 filtertable = {'visible': computehidden,
'served': computeunserved,
'immutable': computemutable,
'base': computeimpactable}
Pierre-Yves David
repoview: add a subset table...
r18233 ### Nearest subset relation
# Nearest subset of filter X is a filter Y so that:
# * Y is included in X,
# * X - Y is as small as possible.
# This create and ordering used for branchmap purpose.
# the ordering may be partial
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 subsettable = {None: 'visible',
'visible': 'served',
'served': 'immutable',
'immutable': 'base'}
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 def filterrevs(repo, filtername):
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 """returns set of filtered revision for this filter name"""
Pierre-Yves David
clfilter: add a cache on repo for set of revision to filter for a given set....
r18101 if filtername not in repo.filteredrevcache:
func = filtertable[filtername]
repo.filteredrevcache[filtername] = func(repo.unfiltered())
return repo.filteredrevcache[filtername]
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100
class repoview(object):
"""Provide a read/write view of a repo through a filtered changelog
This object is used to access a filtered version of a repository without
altering the original repository object itself. We can not alter the
original object for two main reasons:
- It prevents the use of a repo with multiple filters at the same time. In
particular when multiple threads are involved.
- It makes scope of the filtering harder to control.
This object behaves very closely to the original repository. All attribute
operations are done on the original repository:
- An access to `repoview.someattr` actually returns `repo.someattr`,
- A write to `repoview.someattr` actually sets value of `repo.someattr`,
- A deletion of `repoview.someattr` actually drops `someattr`
from `repo.__dict__`.
The only exception is the `changelog` property. It is overridden to return
a (surface) copy of `repo.changelog` with some revisions filtered. The
`filtername` attribute of the view control the revisions that need to be
filtered. (the fact the changelog is copied is an implementation detail).
Unlike attributes, this object intercepts all method calls. This means that
all methods are run on the `repoview` object with the filtered `changelog`
property. For this purpose the simple `repoview` class must be mixed with
the actual class of the repository. This ensures that the resulting
`repoview` object have the very same methods than the repo object. This
leads to the property below.
repoview.method() --> repo.__class__.method(repoview)
The inheritance has to be done dynamically because `repo` can be of any
subclasses of `localrepo`. Eg: `bundlerepo` or `httprepo`.
"""
def __init__(self, repo, filtername):
object.__setattr__(self, '_unfilteredrepo', repo)
object.__setattr__(self, 'filtername', filtername)
# not a cacheproperty on purpose we shall implement a proper cache later
@property
def changelog(self):
"""return a filtered version of the changeset
this changelog must not be used for writing"""
# some cache may be implemented later
cl = copy.copy(self._unfilteredrepo.changelog)
Kevin Bullock
filtering: rename filters to their antonyms...
r18382 cl.filteredrevs = filterrevs(self._unfilteredrepo, self.filtername)
Pierre-Yves David
clfilter: add actual repo filtering mechanism...
r18100 return cl
def unfiltered(self):
"""Return an unfiltered version of a repo"""
return self._unfilteredrepo
def filtered(self, name):
"""Return a filtered version of a repository"""
if name == self.filtername:
return self
return self.unfiltered().filtered(name)
# everything access are forwarded to the proxied repo
def __getattr__(self, attr):
return getattr(self._unfilteredrepo, attr)
def __setattr__(self, attr, value):
return setattr(self._unfilteredrepo, attr, value)
def __delattr__(self, attr):
return delattr(self._unfilteredrepo, attr)
# The `requirement` attribut is initialiazed during __init__. But
# __getattr__ won't be called as it also exists on the class. We need
# explicit forwarding to main repo here
@property
def requirements(self):
return self._unfilteredrepo.requirements