[PATCH 2 of 3 V3] journal: add share extension support

Martijn Pieters mj at zopatista.com
Mon Jul 11 09:07:13 EDT 2016


On 8 July 2016 at 16:24, Yuya Nishihara <yuya at tcha.org> wrote:
>> +def _mergeentriesiter(*iterables, **kwargs):
>> +    """Given a set of sorted iterables, yield the next entry in merged order
>> +
>> +    Note that by default entries go from most recent to oldest.
>> +    """
>> +    order = kwargs.pop('order', max)
>> +    iterables = [iter(it) for it in iterables]
>> +    # this tracks still active iterables; iterables are deleted as they are
>> +    # exhausted, which is why this is a dictionary and why each entry also
>> +    # stores the key. Entries are mutable so we can store the next value each
>> +    # time.
>> +    iterable_map = {}
>> +    for key, it in enumerate(iterables):
>> +        try:
>> +            iterable_map[key] = [next(it), key, it]
>> +        except StopIteration:
>> +            # empty entry, can be ignored
>> +            pass
>> +    if not iterable_map:
>> +        # all iterables where empty
>> +        return
>> +
>> +    while True:
>
> Nit: could be "while iterable_map:"

Nice one, that also lets me drop the `if not iterable_map: return` before it.

>> +def unsharejournal(orig, ui, repo, repopath):
>> +    """Copy shared journal entries into this repo when unsharing"""
>> +    if repo.shared() and util.safehasattr(repo, 'journal'):
>> +        sharedrepo = share._getsrcrepo(repo)
>> +        sharedfeatures = _readsharedfeatures(repo)
>> +        if sharedrepo and sharedfeatures > set(['journal']):
>> +            # there is a shared repository and there are shared journal entries
>> +            # to copy. move shared date over from source to destination but
>> +            # move the local file first
>> +            if repo.vfs.exists('journal'):
>> +                journalpath = repo.join('journal')
>> +                util.rename(journalpath, journalpath + '.bak')
>> +            storage = repo.journal
>> +            local = storage._open(
>> +                repo.vfs, filename='journal.bak', _newestfirst=False)
>> +            shared = (
>> +                e for e in storage._open(sharedrepo.vfs, _newestfirst=False)
>> +                if sharednamespaces.get(e.namespace) in sharedfeatures)
>> +            for entry in _mergeentriesiter(local, shared, order=min):
>> +                storage._write(repo.vfs, entry)
>
> "hg clone" of shared repo will add wrong record to the source repo.
>
>   $ hg share foo bar
>   $ hg clone bar baz  # repo=bar, repopath=baz

Ah, of course. I've added a test to see if `repo.path` is the same as
the `repopath` argument.

>> +        # is this working copy using a shared storage?
>> +        self.sharedfeatures = self.svfs = None
>> +        if repo.shared():
>> +            features = _readsharedfeatures(repo)
>> +            sharedrepo = share._getsrcrepo(repo)
>> +            if sharedrepo is not None and 'journal' in features:
>> +                self.svfs = sharedrepo.vfs
>> +                self.sharedfeatures = features
>
> Nit: "svfs" seems confusing since repo.svfs is store, but journal.svfs is
> non-store of shared repo.

Renamed to sharedvfs instead.

-- 
Martijn Pieters


More information about the Mercurial-devel mailing list