Mercurial > evolve
annotate docs/test2rst.py @ 3846:f9dad99a90d5
evolve: create a new commit instead of amending one of the divergents
This patch changes the behavior of evolve command while resolving
content-divergence to create a new commit instead of amending one of the
divergent ones.
In past, I have made this change, backed out this change and now today again I
am doing this change, so let's dive in some history.
Using cmdrewrite.amend() was never a good option as that requires hack to delete
the evolvestate and also gives us less control over things. We can't make the
commit on top of different parents as that of content-divergent ones. Due to all
these, I first made this change to create a new commit instead of amending one.
But, after few days, there was flakiness observed in the tests and turned out
that we need to do some dirstate dance as repo.dirstate.setparents() does not
always fix the dirstate. That flakiness was a blocker for progress at that time
and we decided to switch to amend back so that we can have things working with
some hacks and we can later fix the implementation part.
Now, yesterday while tackling resolving content-divergence of a stack which is
as follows:
C1 C2
| |
B1 B2
| |
A1 A2
\/
base
where, A1-A2, B1-B2, C1-C2 are content-divergent with each other. Now we can
resolve A1-A2 very well because they have the same parent and let's say that
resolution leads to A3.
Now, we want to resolve B1-B2 and make the new resolution commit on top of A3 so
that we can end up something like:
C3
|
B3
|
A3
|
base
however, amending one of the divergent changesets, it's not possible to create a
commit on a different parent like A3 here without some relocation. We should
prevent relocation as that may leads to some conflicts and should change the
parent before committing.
So, looking ahead, we can't move with using amend as still using that we will
need some relocation hacks making code ugly and prone to bad behaviors, bugs.
Let's change back to creating a new commit so that we can move forward in a good
way.
About repo.dirstate.setparents() not setting the dirstate, I have researched
yesterday night about how we can do that and found out that we can use
cmdrewrite._uncommitdirstate() here. Expect upcoming patches to improve the
documentation of that function.
There are lot of test changes because of change in hash but there is no behavior
change. The only behavior change is in test-evolve-abort-contentdiv.t which is
nice because creating a new commit helps us in stripping that while aborting.
We have a lot of testing of content-divergence and no behavior change gives
enough confidence for making this change.
I reviewed the patch carefully to make sure there is no behavior change and I
suggest reviewer to do the same.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 13 Jun 2018 17:15:10 +0530 |
parents | 1a4f26eec0af |
children | 16c1398b0063 |
rev | line source |
---|---|
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
1 #!/usr/bin/env python |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
2 |
2960
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
3 import re |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
4 import os |
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
5 import os.path as op |
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
6 import sys |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
7 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
8 INDEX = ''' |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
9 Mercurial tests |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
10 =============== |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
11 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
12 .. toctree:: |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
13 :maxdepth: 1 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
14 ''' |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
15 |
2960
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
16 ignored_patterns = [ |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
17 re.compile('^#if'), |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
18 re.compile('^#else'), |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
19 re.compile('^#endif'), |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
20 re.compile('#rest-ignore$'), |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
21 ] |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
22 |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
23 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
24 def rstify(orig, name): |
2825 | 25 newlines = [] |
26 | |
27 code_block_mode = False | |
2959
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
28 sphinx_directive_mode = False |
2825 | 29 |
30 for line in orig.splitlines(): | |
31 | |
32 # Emtpy lines doesn't change output | |
33 if not line: | |
34 newlines.append(line) | |
2959
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
35 code_block_mode = False |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
36 sphinx_directive_mode = False |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
37 continue |
2958
1cb715257130
doc: add a special flag for content to ignore in the rst
Boris Feld <boris.feld@octobus.net>
parents:
2951
diff
changeset
|
38 |
2960
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
39 ignored = False |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
40 for pattern in ignored_patterns: |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
41 if pattern.search(line): |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
42 ignored = True |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
43 break |
1a4f26eec0af
test2rst: ignore the #if/#endif line in the output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
2959
diff
changeset
|
44 if ignored: |
2825 | 45 continue |
46 | |
2959
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
47 # Sphinx directives mode |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
48 if line.startswith(' .. '): |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
49 |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
50 # Insert a empty line to makes sphinx happy |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
51 newlines.append("") |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
52 |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
53 # And unindent the directive |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
54 line = line[2:] |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
55 sphinx_directive_mode = True |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
56 |
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
57 # Code mode |
2825 | 58 codeline = line.startswith(' ') |
2959
ef361938dfa1
doc: integrate graphviz graphs in tutorials
Boris Feld <boris.feld@octobus.net>
parents:
2958
diff
changeset
|
59 if codeline and not sphinx_directive_mode: |
2825 | 60 if code_block_mode is False: |
61 newlines.extend(['::', '']) | |
62 | |
63 code_block_mode = True | |
64 | |
65 newlines.append(line) | |
66 | |
67 return "\n".join(newlines) | |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
68 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
69 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
70 def main(base): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
71 if os.path.isdir(base): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
72 one_dir(base) |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
73 else: |
525
a0327c78a5d3
doc: remove spurious print in test2rest.py
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
235
diff
changeset
|
74 one_file(base) |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
75 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
76 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
77 def one_dir(base): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
78 index = INDEX |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
79 # doc = lambda x: op.join(op.dirname(__file__), 'docs', x) |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
80 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
81 for fn in sorted(os.listdir(base)): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
82 if not fn.endswith('.t'): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
83 continue |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
84 name = os.path.splitext(fn)[0] |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
85 content = one_file(op.join(base, fn)) |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
86 target = op.join(base, name + '.rst') |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
87 # with file(doc(name + '.rst'), 'w') as f: |
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
88 with open(target, 'w') as f: |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
89 f.write(content) |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
90 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
91 index += '\n ' + name |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
92 |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
93 # with file(doc('index.rst'), 'w') as f: |
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
94 # f.write(index) |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
95 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
96 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
97 def one_file(path): |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
98 name = os.path.basename(path)[:-2] |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
99 return rstify(open(path).read(), name) |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
100 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
101 |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
102 if __name__ == '__main__': |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
103 if len(sys.argv) != 2: |
2035
94fe2cc9cd41
flake8: fix error in 'test2rst.py'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
525
diff
changeset
|
104 print('Please supply a path to tests dir as parameter') |
235
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
105 sys.exit() |
8469ccb9550f
[doc] add `.t` to `.rst` converteur
Pierre-Yves.David@ens-lyon.org
parents:
diff
changeset
|
106 main(sys.argv[1]) |