Mercurial > hg
view tests/test-releasenotes-formatting.t @ 39764:e4e881572382
localrepo: iteratively derive local repository type
This commit implements the dynamic local repository type derivation
that was explained in the recent commit
bfeab472e3c0 "localrepo: create new function for instantiating a local
repo object."
Instead of a static localrepository class/type which must be customized
after construction, we now dynamically construct a type by building up
base classes/types to represent specific repository interfaces.
Conceptually, the end state is similar to what was happening when
various extensions would monkeypatch the __class__ of newly-constructed
repo instances. However, the approach is inverted. Instead of making
the instance then customizing it, we do the customization up front
by influencing the behavior of the type then we instantiate that
custom type.
This approach gives us much more flexibility. For example, we can
use completely separate classes for implementing different aspects
of the repository. For example, we could have one class representing
revlog-based file storage and another representing non-revlog based
file storage. When then choose which implementation to use based on
the presence of repo requirements.
A concern with this approach is that it creates a lot more types
and complexity and that complexity adds overhead. Yes, it is true that
this approach will result in more types being created. Yes, this is
more complicated than traditional "instantiate a static type." However,
I believe the alternatives to supporting alternate storage backends
are just as complicated. (Before I arrived at this solution, I had
patches storing factory functions on local repo instances for e.g.
constructing a file storage instance. We ended up having a handful
of these. And this was logically identical to assigning custom
methods. Since we were logically changing the type of the instance,
I figured it would be better to just use specialized types instead
of introducing levels of abstraction at run-time.)
On the performance front, I don't believe that having N base classes
has any significant performance overhead compared to just a single base
class. Intuition says that Python will need to iterate the base classes
to find an attribute. However, CPython caches method lookups: as long as
the __class__ or MRO isn't changing, method attribute lookup should be
constant time after first access. And non-method attributes are stored
in __dict__, of which there is only 1 per object, so the number of
base classes for __dict__ is irrelevant.
Anyway, this commit splits up the monolithic completelocalrepository
interface into sub-interfaces: 1 for file storage and 1 representing
everything else.
We've taught ``makelocalrepository()`` to call a series of factory
functions which will produce types implementing specific interfaces.
It then calls type() to create a new type from the built-up list of
base types.
This commit should be considered a start and not the end state. I
suspect we'll hit a number of problems as we start to implement
alternate storage backends:
* Passing custom arguments to __init__ and setting custom attributes
on __dict__.
* Customizing the set of interfaces that are needed. e.g. the
"readonly" intent could translate to not requesting an interface
providing methods related to writing.
* More ergonomic way for extensions to insert themselves so their
callbacks aren't unconditionally called.
* Wanting to modify vfs instances, other arguments passed to __init__.
That being said, this code is usable in its current state and I'm
convinced future commits will demonstrate the value in this approach.
Differential Revision: https://phab.mercurial-scm.org/D4642
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 18 Sep 2018 15:29:42 -0700 |
parents | a5891e94bfe1 |
children | df470e764770 |
line wrap: on
line source
#require fuzzywuzzy $ cat >> $HGRCPATH << EOF > [extensions] > releasenotes= > EOF $ hg init simple-repo $ cd simple-repo A fix with a single line results in a bullet point in the appropriate section $ touch fix1 $ hg -q commit -A -l - << EOF > single line fix > > .. fix:: > > Simple fix with a single line content entry. > EOF $ hg releasenotes -r . $TESTTMP/relnotes-single-line $ cat $TESTTMP/relnotes-single-line Bug Fixes ========= * Simple fix with a single line content entry. A fix with multiple lines is handled correctly $ touch fix2 $ hg -q commit -A -l - << EOF > multi line fix > > .. fix:: > > First line of fix entry. > A line after it without a space. > > A new paragraph in the fix entry. And this is a really long line. It goes on for a while. > And it wraps around to a new paragraph. > EOF $ hg releasenotes -r . $TESTTMP/relnotes-multi-line $ cat $TESTTMP/relnotes-multi-line Bug Fixes ========= * First line of fix entry. A line after it without a space. A new paragraph in the fix entry. And this is a really long line. It goes on for a while. And it wraps around to a new paragraph. A release note with a title results in a sub-section being written $ touch fix3 $ hg -q commit -A -l - << EOF > fix with title > > .. fix:: Fix Title > > First line of fix with title. > > Another paragraph of fix with title. But this is a paragraph > with multiple lines. > EOF $ hg releasenotes -r . $TESTTMP/relnotes-fix-with-title $ cat $TESTTMP/relnotes-fix-with-title Bug Fixes ========= Fix Title --------- First line of fix with title. Another paragraph of fix with title. But this is a paragraph with multiple lines. $ cd .. Formatting of multiple bullet points works $ hg init multiple-bullets $ cd multiple-bullets $ touch fix1 $ hg -q commit -A -l - << EOF > commit 1 > > .. fix:: > > first fix > EOF $ touch fix2 $ hg -q commit -A -l - << EOF > commit 2 > > .. fix:: > > second fix > > Second paragraph of second fix. > EOF $ touch fix3 $ hg -q commit -A -l - << EOF > commit 3 > > .. fix:: > > third fix > EOF $ hg releasenotes -r 'all()' $TESTTMP/relnotes-multiple-bullets $ cat $TESTTMP/relnotes-multiple-bullets Bug Fixes ========= * first fix * second fix Second paragraph of second fix. * third fix $ cd .. Formatting of multiple sections works $ hg init multiple-sections $ cd multiple-sections $ touch fix1 $ hg -q commit -A -l - << EOF > commit 1 > > .. fix:: > > first fix > EOF $ touch feature1 $ hg -q commit -A -l - << EOF > commit 2 > > .. feature:: > > description of the new feature > EOF $ touch fix2 $ hg -q commit -A -l - << EOF > commit 3 > > .. fix:: > > second fix > EOF $ hg releasenotes -r 'all()' $TESTTMP/relnotes-multiple-sections $ cat $TESTTMP/relnotes-multiple-sections New Features ============ * description of the new feature Bug Fixes ========= * first fix * second fix $ cd .. Section with subsections and bullets $ hg init multiple-subsections $ cd multiple-subsections $ touch fix1 $ hg -q commit -A -l - << EOF > commit 1 > > .. fix:: Title of First Fix > > First paragraph of first fix. > > Second paragraph of first fix. > EOF $ touch fix2 $ hg -q commit -A -l - << EOF > commit 2 > > .. fix:: Title of Second Fix > > First paragraph of second fix. > > Second paragraph of second fix. > EOF $ hg releasenotes -r 'all()' $TESTTMP/relnotes-multiple-subsections $ cat $TESTTMP/relnotes-multiple-subsections Bug Fixes ========= Title of First Fix ------------------ First paragraph of first fix. Second paragraph of first fix. Title of Second Fix ------------------- First paragraph of second fix. Second paragraph of second fix. Now add bullet points to sections having sub-sections $ touch fix3 $ hg -q commit -A -l - << EOF > commit 3 > > .. fix:: > > Short summary of fix 3 > EOF $ hg releasenotes -r 'all()' $TESTTMP/relnotes-multiple-subsections-with-bullets $ cat $TESTTMP/relnotes-multiple-subsections-with-bullets Bug Fixes ========= Title of First Fix ------------------ First paragraph of first fix. Second paragraph of first fix. Title of Second Fix ------------------- First paragraph of second fix. Second paragraph of second fix. Other Changes ------------- * Short summary of fix 3 $ cd .. Multiple 'Other Changes' sub-sections for every section $ hg init multiple-otherchanges $ cd multiple-otherchanges $ touch fix1 $ hg -q commit -A -l - << EOF > commit 1 > > .. fix:: Title of First Fix > > First paragraph of fix 1. > EOF $ touch feature1 $ hg -q commit -A -l - << EOF > commit 2 > > .. feature:: Title of First Feature > > First paragraph of feature 1. > EOF $ touch feature2 $ hg -q commit -A -l - << EOF > commit 3 > > .. feature:: > > Short summary of feature 2. > EOF $ touch fix2 $ hg -q commit -A -l - << EOF > commit 4 > > .. fix:: > > Short summary of fix 2 > EOF $ hg releasenotes -r 'all()' $TESTTMP/relnotes-multiple-otherchanges $ cat $TESTTMP/relnotes-multiple-otherchanges New Features ============ Title of First Feature ---------------------- First paragraph of feature 1. Other Changes ------------- * Short summary of feature 2. Bug Fixes ========= Title of First Fix ------------------ First paragraph of fix 1. Other Changes ------------- * Short summary of fix 2 $ cd .. Using custom sections in notes $ hg init custom-section $ cd custom-section $ cat >> .hgreleasenotes << EOF > [sections] > testsection=Name of Section > EOF $ touch a $ hg -q commit -A -l - << EOF > commit 1 > > .. testsection:: > > First paragraph under this admonition. > EOF $ hg releasenotes -r . $TESTTMP/relnotes-custom-section $ cat $TESTTMP/relnotes-custom-section Name of Section =============== * First paragraph under this admonition. Overriding default sections (For eg. by default feature = New Features) $ cat >> .hgreleasenotes << EOF > [sections] > feature=Feature Additions > EOF $ touch b $ hg -q commit -A -l - << EOF > commit 2 > > .. feature:: > > Adds a new feature. > EOF $ hg releasenotes -r . $TESTTMP/relnotes-override-section $ cat $TESTTMP/relnotes-override-section Feature Additions ================= * Adds a new feature. $ cd .. Testing output for the --check (-c) flag $ hg init check-flag $ cd check-flag $ touch a $ hg -q commit -A -l - << EOF > .. asf:: > > First paragraph under this admonition. > EOF Suggest similar admonition in place of the invalid one. $ hg releasenotes -r . -c Invalid admonition 'asf' present in changeset 4026fe9e1c20 $ touch b $ hg -q commit -A -l - << EOF > .. fixes:: > > First paragraph under this admonition. > EOF $ hg releasenotes -r . -c Invalid admonition 'fixes' present in changeset 0e7130d2705c (did you mean fix?) $ cd .. Usage of --list flag $ hg init relnotes-list $ cd relnotes-list $ hg releasenotes -l feature: New Features bc: Backwards Compatibility Changes fix: Bug Fixes perf: Performance Improvements api: API Changes $ cd .. Raise error on simultaneous usage of flags $ hg init relnotes-raise-error $ cd relnotes-raise-error $ hg releasenotes -r . -l abort: cannot use both '--list' and '--rev' [255] $ hg releasenotes -l -c abort: cannot use both '--list' and '--check' [255] Display release notes for specified revs if no file is mentioned $ hg init relnotes-nofile $ cd relnotes-nofile $ touch fix1 $ hg -q commit -A -l - << EOF > commit 1 > > .. fix:: Title of First Fix > > First paragraph of fix 1. > EOF $ hg releasenote -r . Bug Fixes ========= Title of First Fix ------------------ First paragraph of fix 1. $ cd .. Using multiple admonitions in same changeset $ hg init relnotes-multiadmon $ cd relnotes-multiadmon $ touch file1 $ hg -q commit -A -l - << EOF > commit 1 > > .. feature:: > > Details about new feature. > > .. perf:: > > Improves the execution by 2x > EOF $ hg releasenotes -r . $TESTTMP/relnotes-multiple-admonitions $ cat $TESTTMP/relnotes-multiple-admonitions New Features ============ * Details about new feature. Performance Improvements ======================== * Improves the execution by 2x