changeset 2825:7608f1e04205 stable

doc: fix test2rst Previous versions used to break on multi-lines texts and miss entirely single lines of texts. Use a simplest version without regex.
author Boris Feld <boris.feld@octobus.net>
date Thu, 27 Jul 2017 17:16:02 +0200
parents d0e3a8e0b62c
children 93588d219f2f
files docs/test2rst.py tests/test-topic-tutorial.t
diffstat 2 files changed, 52 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/docs/test2rst.py	Thu Jul 27 11:39:51 2017 +0200
+++ b/docs/test2rst.py	Thu Jul 27 17:16:02 2017 +0200
@@ -2,14 +2,8 @@
 
 import os
 import os.path as op
-import re
 import sys
 
-# line starts with two chars one of which is not a space (and both are not
-# newlines obviously) and ends with one or more newlines followed by two spaces
-# on a next line (indented text)
-CODEBLOCK = re.compile(r'()\n(([^ \n][^\n]|[^\n][^ \n])[^\n]*)\n+  ')
-
 INDEX = '''
 Mercurial tests
 ===============
@@ -20,10 +14,29 @@
 
 
 def rstify(orig, name):
-    header = '%s\n%s\n\n' % (name, '=' * len(name))
-    content = header + orig
-    content = CODEBLOCK.sub(r'\n\1\n\n::\n\n  ', content)
-    return content
+    newlines = []
+
+    code_block_mode = False
+
+    for line in orig.splitlines():
+
+        # Emtpy lines doesn't change output
+        if not line:
+            newlines.append(line)
+            continue
+
+        codeline = line.startswith('  ')
+        if codeline:
+            if code_block_mode is False:
+                newlines.extend(['::', ''])
+
+            code_block_mode = True
+        else:
+            code_block_mode = False
+
+        newlines.append(line)
+
+    return "\n".join(newlines)
 
 
 def main(base):
--- a/tests/test-topic-tutorial.t	Thu Jul 27 11:39:51 2017 +0200
+++ b/tests/test-topic-tutorial.t	Thu Jul 27 17:16:02 2017 +0200
@@ -42,7 +42,7 @@
 Topic Basics
 ============
 
-Let's say we use Mercurial to manage our shopping list::
+Let's say we use Mercurial to manage our shopping list:
 
   $ hg log --graph
   @  changeset:   0:38da43f0a2ea
@@ -52,13 +52,13 @@
      summary:     Shopping list
   
 
-We are about to make some additions to this list and would like to do them
-within a topic. Creating a new topic is done using the ``topic`` command::
+We are about to make some additions to this list and would like to do them 
+within a topic. Creating a new topic is done using the ``topic`` command:
 
   $ hg topic food
 
 Much like a named branch, our topic is active but it does not contain any
-changesets yet::
+changesets yet:
 
   $ hg topic
    * food
@@ -77,7 +77,7 @@
      summary:     Shopping list
   
 
-Our next commit will be part of the active topic::
+Our next commit will be part of the active topic:
 
   $ cat >> shopping << EOF
   > Egg
@@ -95,7 +95,7 @@
      summary:     adding condiments
   
 
-And future commits will be part of that topic too::
+And future commits will be part of that topic too:
 
   $ cat >> shopping << EOF
   > Bananas
@@ -119,7 +119,7 @@
   
 
 We can get a compact view of the content of our topic using the ``stack``
-command::
+command:
 
   $ hg stack
   ### topic: food
@@ -128,7 +128,7 @@
   t1: adding condiments
   t0^ Shopping list (base)
 
-The topic deactivates when we update away from it::
+The topic deactivates when we update away from it:
 
   $ hg up default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -136,7 +136,7 @@
      food
 
 Note that ``default`` (name of the branch) now refers to the tipmost
-changeset of default without a topic::
+changeset of default without a topic:
 
   $ hg log --graph
   o  changeset:   2:287de11b401f
@@ -157,7 +157,7 @@
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     Shopping list
   
-And updating back to the topic reactivates it::
+And updating back to the topic reactivates it:
 
   $ hg up food
   switching to topic food
@@ -166,7 +166,7 @@
    * food
 
 Updating to any changeset that is part of a topic activates the topic
-regardless of how the revision was specified::
+regardless of how the revision was specified:
 
   $ hg up default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -176,7 +176,7 @@
   $ hg topic
    * food
 
-.. server side activity::
+.. server side activity:
 
   $ cd ../server/
   $ cat > shopping << EOF
@@ -194,7 +194,7 @@
   $ cd ../client
 
 The topic will also affect the rebase and the merge destinations. Let's pull
-the latest update from the main server::
+the latest update from the main server:
 
   $ hg pull
   pulling from $TESTTMP/server (glob)
@@ -231,7 +231,7 @@
   
 
 The topic head will not be considered when merging from the new head of the
-branch::
+branch:
 
   $ hg up default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -240,7 +240,7 @@
   (run 'hg heads' to see all heads)
   [255]
 
-But the topic will see that branch head as a valid destination::
+But the topic will see that branch head as a valid destination:
 
   $ hg up food
   switching to topic food
@@ -277,7 +277,7 @@
      summary:     Shopping list
   
 
-The topic information will disappear when we publish the changesets::
+The topic information will disappear when we publish the changesets:
 
   $ hg topic
    * food
@@ -325,7 +325,7 @@
 multiple features at the same time.
 
 We might go shopping in a hardware store in the same go, so let's add some
-tools to the shopping list within a new topic::
+tools to the shopping list within a new topic:
 
   $ hg topic tools
   $ echo hammer >> shopping
@@ -337,7 +337,7 @@
 
 But we are not sure we will actually go to the hardware store, so in the
 meantime, we want to extend the list with drinks. We go back to the official
-default branch and start a new topic::
+default branch and start a new topic:
 
   $ hg up default
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -347,13 +347,13 @@
   $ echo 'orange juice' >> shopping
   $ hg ci -m 'Adding orange juice'
 
-We now have two topics::
+We now have two topics:
 
   $ hg topic
    * drinks
      tools
 
-The information displayed by ``hg stack`` adapts to the active topic::
+The information displayed by ``hg stack`` adapts to the active topic:
 
   $ hg stack
   ### topic: drinks
@@ -373,13 +373,13 @@
   t0^ adding fruits (base)
 
 They are seen as independent branches by Mercurial. No rebase or merge
-between them will be attempted by default::
+between them will be attempted by default:
 
   $ hg rebase
   nothing to rebase
   [1]
 
-.. server activity::
+.. server activity:
 
   $ cd ../server
   $ hg up
@@ -395,7 +395,7 @@
   $ hg ci -m 'add a pair of shoes'
   $ cd ../client
 
-Let's see what other people did in the meantime::
+Let's see what other people did in the meantime:
 
   $ hg pull
   pulling from $TESTTMP/server (glob)
@@ -407,7 +407,7 @@
   (run 'hg heads' to see heads)
 
 There are new changes! We can simply use ``hg rebase`` to update our
-changeset on top of the latest::
+changeset on top of the latest:
 
   $ hg rebase
   rebasing 6:183984ef46d1 "Adding hammer"
@@ -419,7 +419,7 @@
   merging shopping
 
 But what about the other topic? You can use 'hg topic --verbose' to see
-information about all the topics::
+information about all the topics:
 
   $ hg topic --verbose
      drinks (on branch: default, 2 changesets, 2 behind)
@@ -428,7 +428,7 @@
 The "2 behind" is telling you that there are 2 new changesets on the named
 branch of the topic. You need to merge or rebase to incorporate them.
 
-Pushing that topic would create a new head, and therefore will be prevented::
+Pushing that topic would create a new head, and therefore will be prevented:
 
   $ hg push --rev drinks
   pushing to $TESTTMP/server (glob)
@@ -439,7 +439,7 @@
 
 
 Even after a rebase, pushing all active topics at the same time will complain
-about the multiple heads it would create on that branch::
+about the multiple heads it would create on that branch:
 
   $ hg rebase -b drinks
   rebasing 9:8dfa45bd5e0c "Adding apple juice"
@@ -456,7 +456,7 @@
   [255]
 
 Publishing only one of them is allowed (as long as it does not create a new
-branch head as we just saw in the previous case)::
+branch head as we just saw in the previous case):
 
   $ hg push -r drinks
   pushing to $TESTTMP/server (glob)
@@ -468,7 +468,7 @@
   2 new obsolescence markers
 
 The published topic has now disappeared, and the other is now marked as
-"behind"::
+"behind":
 
   $ hg topic --verbose
    * tools (on branch: default, 3 changesets, 2 behind)