From 32bf51cd2438847aa183a59a776add7db948eb22 Mon Sep 17 00:00:00 2001 From: smerten Date: Sat, 13 Nov 2010 15:26:09 +0000 Subject: [PATCH] Some elements which may not be doubled by a replacement because they must be single by definition propagate a replacement up if their siblings also could propagate a replacement up. This way for instance sections which are complete replacements are recognized and marked up properly. Added README and man page `rstdiff.pod`. Upgraded tests to filterunit V0.7.1. Adapted expected test output to Docutils 0.8. git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk@6481 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- sandbox/rstdiff/MANIFEST.in | 2 + sandbox/rstdiff/README | 3 + sandbox/rstdiff/global.log | 482 +++++++++++++++++++++ sandbox/rstdiff/rstdiff.pod | 44 ++ sandbox/rstdiff/rstdiff.py | 110 +++-- sandbox/rstdiff/setup.py | 17 + sandbox/rstdiff/tag.log | 2 +- sandbox/rstdiff/tests/html/expected/contents.html | 16 +- sandbox/rstdiff/tests/html/expected/footnote.html | 16 +- sandbox/rstdiff/tests/html/expected/reference.html | 16 +- .../rstdiff/tests/html/expected/textDifferent.html | 16 +- sandbox/rstdiff/tests/html/filterunit.cfg | 3 +- .../rstdiff/tests/simple/expected/attributes.xml | 2 +- .../rstdiff/tests/simple/expected/inlineStyles.xml | 2 +- sandbox/rstdiff/tests/simple/expected/section.xml | 2 +- .../tests/simple/expected/textDifferent.xml | 2 +- .../rstdiff/tests/simple/expected/textEqual.xml | 2 +- sandbox/rstdiff/tests/simple/expected/textOnly.xml | 2 +- sandbox/rstdiff/tests/simple/filterunit.cfg | 3 +- sandbox/rstdiff/tests/simple/source/section.rst | 1 - .../tests/simpleHtml/expected/attributes.html | 18 +- .../tests/simpleHtml/expected/inlineStyles.html | 22 +- .../rstdiff/tests/simpleHtml/expected/section.html | 18 +- .../tests/simpleHtml/expected/textDifferent.html | 18 +- .../tests/simpleHtml/expected/textEqual.html | 18 +- .../tests/simpleHtml/expected/textOnly.html | 18 +- sandbox/rstdiff/tests/simpleHtml/filterunit.cfg | 3 +- .../simpleNoSource/expected/attributesNoSource.xml | 2 +- .../tests/simpleNoSource/expected/onceOnly.xml | 46 +- .../tests/simpleNoSource/expected/pcdataOnly.xml | 2 +- .../tests/simpleNoSource/expected/references.xml | 2 +- .../tests/simpleNoSource/expected/section.xml | 41 ++ .../rstdiff/tests/simpleNoSource/filterunit.cfg | 3 +- .../tests/simpleNoSource/input/onceOnly.new.rst | 2 + .../tests/simpleNoSource/input/onceOnly.old.rst | 3 + .../tests/simpleNoSource/input/section.new.rst | 14 + .../tests/simpleNoSource/input/section.old.rst | 14 + sandbox/rstdiff/version.py | 1 + 38 files changed, 889 insertions(+), 99 deletions(-) create mode 100644 sandbox/rstdiff/MANIFEST.in create mode 100644 sandbox/rstdiff/README create mode 100644 sandbox/rstdiff/rstdiff.pod create mode 100755 sandbox/rstdiff/setup.py create mode 100644 sandbox/rstdiff/tests/simpleNoSource/expected/section.xml create mode 100644 sandbox/rstdiff/tests/simpleNoSource/input/section.new.rst create mode 100644 sandbox/rstdiff/tests/simpleNoSource/input/section.old.rst create mode 100644 sandbox/rstdiff/version.py diff --git a/sandbox/rstdiff/MANIFEST.in b/sandbox/rstdiff/MANIFEST.in new file mode 100644 index 000000000..d7a52a82f --- /dev/null +++ b/sandbox/rstdiff/MANIFEST.in @@ -0,0 +1,2 @@ +include tests.tgz +include version.py diff --git a/sandbox/rstdiff/README b/sandbox/rstdiff/README new file mode 100644 index 000000000..2567ac770 --- /dev/null +++ b/sandbox/rstdiff/README @@ -0,0 +1,3 @@ +`rstdiff.py` generates a structural diff from two reStructuredText +input documents and produces an annotated result. Use the `--writer` +option to select a writer for the result. diff --git a/sandbox/rstdiff/global.log b/sandbox/rstdiff/global.log index 0c25347bc..0a72b6387 100644 --- a/sandbox/rstdiff/global.log +++ b/sandbox/rstdiff/global.log @@ -1,4 +1,486 @@ ************************************** +Date: Sat Nov 13 16:08:34 CET 2010 +Author: stefan +Tag: rstdiff_1_90 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Added Files: + README + +-------------------------------------- +Log Message: +Added README. +************************************** +Date: Sat Nov 13 16:03:42 CET 2010 +Author: stefan +Tag: rstdiff_1_89 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple +In directory rosalu:/home/stefan/free/rstdiff/tests/simple + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple/input +In directory rosalu:/home/stefan/free/rstdiff/tests/simple/input + +Modified Files: + section.new.rst section.old.rst + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple/source +In directory rosalu:/home/stefan/free/rstdiff/tests/simple/source + +Modified Files: + section.rst + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleHtml +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource/expected +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource/expected + +Modified Files: + onceOnly.xml +Added Files: + section.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource/input +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource/input + +Modified Files: + onceOnly.new.rst onceOnly.old.rst +Added Files: + section.new.rst section.old.rst + +-------------------------------------- +Log Message: +Adapted tests to run again. +************************************** +Date: Sat Nov 13 15:17:18 CET 2010 +Author: stefan +Tag: rstdiff_1_88 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource + +Modified Files: + filterunit.cfg + +-------------------------------------- +Log Message: +Implemented up propagation for replacement of elements which may +propagate up if their siblings also may propagate a replacement up. +Tests need to be considered. +************************************** +Date: Sat Nov 13 14:13:48 CET 2010 +Author: stefan +Tag: rstdiff_1_87 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple/input +In directory rosalu:/home/stefan/free/rstdiff/tests/simple/input + +Modified Files: + section.new.rst section.old.rst + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple/source +In directory rosalu:/home/stefan/free/rstdiff/tests/simple/source + +Modified Files: + section.rst + +-------------------------------------- +Log Message: +One more step for proper replacement of complex elements. Expected +tests fail. +************************************** +Date: Sat Nov 13 11:17:24 CET 2010 +Author: stefan +Tag: rstdiff_1_86 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Refactoring: Prepared code for up-propagation for handling +section/title. +************************************** +Date: Sun Nov 7 20:10:28 CET 2010 +Author: stefan +Tag: rstdiff_1_85 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html +In directory rosalu:/home/stefan/free/rstdiff/tests/html + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret +In directory rosalu:/home/stefan/free/rstdiff/tests/secret + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml +In directory rosalu:/home/stefan/free/rstdiff/tests/secretHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple +In directory rosalu:/home/stefan/free/rstdiff/tests/simple + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleHtml +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleNoSource + +Modified Files: + filterunit.cfg + +-------------------------------------- +Log Message: +Upgraded tests to filterunit V0.7.1. +************************************** +Date: Mon Nov 1 19:33:50 CET 2010 +Author: stefan +Tag: rstdiff_1_84 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + Makefile +Added Files: + rstdiff.pod + +-------------------------------------- +Log Message: +Added man page. +************************************** +Date: Sun Oct 31 20:53:50 CET 2010 +Author: stefan +Tag: rstdiff_1_83 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/studies +In directory rosalu:/home/stefan/free/rstdiff/studies + +Added Files: + .cvsignore + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/html +In directory rosalu:/home/stefan/free/rstdiff/tests/html + +Added Files: + .cvsignore + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple +In directory rosalu:/home/stefan/free/rstdiff/tests/simple + +Added Files: + .cvsignore + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleHtml +In directory rosalu:/home/stefan/free/rstdiff/tests/simpleHtml + +Added Files: + .cvsignore + +-------------------------------------- +Log Message: +Removed created `.cvsignore`. +************************************** +Date: Mon Oct 18 12:30:28 CEST 2010 +Author: stefan +Tag: rstdiff_1_82 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Added Files: + setup.py + +-------------------------------------- +Log Message: +Added `setup.py`. +************************************** +Date: Mon Oct 18 12:14:54 CEST 2010 +Author: stefan +Tag: rstdiff_1_81 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Modified Files: + Makefile + +-------------------------------------- +Log Message: +Added library sources. +************************************** +Date: Mon Oct 18 12:02:16 CEST 2010 +Author: stefan +Tag: rstdiff_1_80 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory theowa:/home/stefan/free/rstdiff + +Modified Files: + Makefile + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret +In directory theowa:/home/stefan/free/rstdiff/tests/secret + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml +In directory theowa:/home/stefan/free/rstdiff/tests/secretHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml/expected +In directory theowa:/home/stefan/free/rstdiff/tests/secretHtml/expected + +Modified Files: + transaktionsbehandlung.html + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simple +In directory theowa:/home/stefan/free/rstdiff/tests/simple + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleHtml +In directory theowa:/home/stefan/free/rstdiff/tests/simpleHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Log Message: +Added tags to some tests. + +Adapted expected output to Docutils 0.8. +************************************** +Date: Mon Oct 11 10:48:34 CEST 2010 +Author: stefan +Tag: rstdiff_1_79 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret/expected +In directory theowa:/home/stefan/free/rstdiff/tests/secret/expected + +Modified Files: + transaktionsbehandlung.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/simpleNoSource/expected +In directory theowa:/home/stefan/free/rstdiff/tests/simpleNoSource/expected + +Modified Files: + attributesNoSource.xml onceOnly.xml pcdataOnly.xml + references.xml + +-------------------------------------- +Log Message: +Adapted comments in tests to newer docutils version. +************************************** +Date: Sun Oct 10 16:41:51 CEST 2010 +Author: stefan +Tag: rstdiff_1_78 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + Makefile + +-------------------------------------- +Log Message: +Switched to using `packageSupport`. +************************************** +Date: Sun Aug 22 14:24:03 CEST 2010 +Author: stefan +Tag: rstdiff_1_77 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret +In directory rosalu:/home/stefan/free/rstdiff/tests/secret + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret/expected +In directory rosalu:/home/stefan/free/rstdiff/tests/secret/expected + +Modified Files: + transaktionsbehandlung.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret/input +In directory rosalu:/home/stefan/free/rstdiff/tests/secret/input + +Added Files: + transaktionsbehandlung.opt + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml +In directory rosalu:/home/stefan/free/rstdiff/tests/secretHtml + +Modified Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml/expected +In directory rosalu:/home/stefan/free/rstdiff/tests/secretHtml/expected + +Modified Files: + transaktionsbehandlung.html + +-------------------------------------- +Log Message: +Corrected expected results. +************************************** +Date: Sun Aug 22 13:43:23 CEST 2010 +Author: stefan +Tag: rstdiff_1_76 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff +In directory rosalu:/home/stefan/free/rstdiff + +Modified Files: + rstdiff.py + +-------------------------------------- +Log Message: +Debugging. + +Moved debug flag to a parameter. + +Removed some debugging code again. +************************************** +Date: Fri Aug 13 10:43:23 CEST 2010 +Author: stefan +Tag: rstdiff_1_75 + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret +In directory theowa:/home/stefan/free/rstdiff/tests/secret + +Added Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret/expected +In directory theowa:/home/stefan/free/rstdiff/tests/secret/expected + +Added Files: + transaktionsbehandlung.xml + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secret/input +In directory theowa:/home/stefan/free/rstdiff/tests/secret/input + +Added Files: + transaktionsbehandlung.new.rst transaktionsbehandlung.old.rst + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml +In directory theowa:/home/stefan/free/rstdiff/tests/secretHtml + +Added Files: + filterunit.cfg + +-------------------------------------- +Update of /home/stefan/vault/sm/rstdiff/tests/secretHtml/expected +In directory theowa:/home/stefan/free/rstdiff/tests/secretHtml/expected + +Added Files: + transaktionsbehandlung.html + +-------------------------------------- +Log Message: +Added directories for tests with secret input files. Added test for +new bug. +************************************** Date: Sun Aug 8 14:23:27 CEST 2010 Author: stefan Tag: rstdiff_1_74 diff --git a/sandbox/rstdiff/rstdiff.pod b/sandbox/rstdiff/rstdiff.pod new file mode 100644 index 000000000..d1d4061d8 --- /dev/null +++ b/sandbox/rstdiff/rstdiff.pod @@ -0,0 +1,44 @@ +=head1 NAME + +rstdiff - Generate a diff from two reStructuredText input files + +=head1 SYNOPSIS + +B [I]... I [I [I]] + +=head1 DESCRIPTION + +Generates a structural diff from two reStructuredText input documents +and produces an annotated result. + +=head1 OPTIONS + +Try + + rstdiff.py --help + +for an explanation of all options. + +=head1 SEE ALSO + +=over 4 + +=item Docutils + +http://docutils.sourceforge.net/ + +=item reStructuredText + +http://docutils.sourceforge.net/rst.html + +=back + +=head1 AVAILABILITY + +B is available from + +http://www.merten-home.de/FreeSoftware/rstdiff/ + +and the Docutils sandbox + +svn://svn.berlios.de/docutils/trunk/sandbox/rstdiff diff --git a/sandbox/rstdiff/rstdiff.py b/sandbox/rstdiff/rstdiff.py index 61b6c4f5a..3c2d9ee29 100755 --- a/sandbox/rstdiff/rstdiff.py +++ b/sandbox/rstdiff/rstdiff.py @@ -280,8 +280,8 @@ class Words2Text(Transform): class Words2TextVisitor(nodes.SparseNodeVisitor): - def visit_Word(self, word): - parent = word.parent + def visit_Text(self, text): + parent = text.parent # Find this node and the first node of the sequence it belongs to first = None for i in range(len(parent)): @@ -289,13 +289,13 @@ class Words2TextVisitor(nodes.SparseNodeVisitor): first = None elif first is None: first = i - # ``parent.index(word)`` uses value equality - can not be - # used here to find `word` - if id(parent[i]) == id(word): + # ``parent.index(text)`` uses value equality - can not be + # used here to find `text` + if id(parent[i]) == id(text): end = i + 1 break else: - raise IndexError("Can not find %r in its parent" % ( word, )) + raise IndexError("Can not find %r in its parent" % ( text, )) if (len(parent) > end and isinstance(parent[end], nodes.Text)): @@ -303,11 +303,13 @@ class Words2TextVisitor(nodes.SparseNodeVisitor): # deleted - so work for last node of a sequence return - text = nodes.Text(reduce(lambda s, node: s + node.astext(), + texts = nodes.Text(reduce(lambda s, node: s + node.astext(), parent[first:end], "")) - parent[first:end] = ( text, ) + parent[first:end] = ( texts, ) + + visit_White = visit_Text - visit_White = visit_Word + visit_Word = visit_Text ############################################################################### ############################################################################### @@ -486,8 +488,8 @@ class DocutilsDispatcher(HashableNodeImpl): elif command == Opcode.Replace: # TODO Replacement doubles elements. This needs to be # reflected by creation of unique @ids for replaced - # elements. This needs to be reflected in referring @refid - # and @backrefs. + # elements. This needs also to be reflected in referring + # @refid and @backrefs. for newChild in self.copyRange(oldRoot, oldRange, self.NewReplaced): self.addChild(diffRoot, newChild) @@ -818,8 +820,8 @@ def buildTree(dispatcher, diffRoot, opcodes, oldRoot, newRoot): dispatcher.mergeChildren(diffRoot, oldRoot, newRoot, command, oldRange, newRange) -# A change in certain elements must not be propagated up since they -# may occur only once +# A replacement in certain elements must not be propagated up since +# they may occur only once and replacement would double them replaceNotUp = ( nodes.title, nodes.subtitle, nodes.term, nodes.field_name, nodes.attribution, nodes.caption, # (%text.model) nodes.header, nodes.footer, nodes.definition, @@ -830,9 +832,31 @@ replaceNotUp = ( nodes.title, nodes.subtitle, nodes.term, nodes.field_name, nodes.tbody, # different content model ) +# A replacement in certain elements normally not subject to up +# propagation and contained in certain elements may propagate up if +# all their siblings are also replacements and would propagate up +replaceUpSiblings = ( + ( nodes.title, nodes.section, ), + ( nodes.subtitle, nodes.section, ), + ( nodes.term, nodes.definition_list_item, ), + ( nodes.field_name, nodes.field, ), + ( nodes.attribution, nodes.block_quote, ), + ( nodes.caption, nodes.figure, ), + ( nodes.definition, nodes.definition_list_item, ), + ( nodes.field_body, nodes.field, ), + ( nodes.description, nodes.option_list_item, ), + ( nodes.legend, nodes.figure, ), + ( nodes.option_group, nodes.option_list_item, ), + ) + +# TODO If much text is replaced in a text element the whole element +# should be replaced. This makes more sense to people than two large +# replaced/replacement blocks where the only equality is in words like +# "the". The exact meaning of "much" should be an option. def cleanOpcodes(opcodes, dispatcher, oldList, newList): """Replace some nasty results in `opcodes` by cleaner versions. Opcodes create `newList` from `oldList`.""" + mightReplaceUpSiblings = [ ] for i in range(len(opcodes)): opcode = Opcode(opcodes[i]) ( command, oldRange, newRange, subOpcodes, @@ -864,39 +888,55 @@ def cleanOpcodes(opcodes, dispatcher, oldList, newList): opcode.setSubOpcodes(subOpcodes) if len(subOpcodes) == 1: subOpcode = Opcode(subOpcodes[0]) - if (subOpcode.getCommand() != Opcode.Replace - or not reduce(lambda last, cls: - last or isinstance(oldNode, cls), - replaceNotUp, False)): - # TODO If a section/title would propagate up the - # propagation needs to be done if all siblings would - # propagate, too; this way a section replacement - # should work again - # - # This applies to section/title, section/subtitle, - # definition_list_item/term, field/field_name, - # block_quote/attribution, figure/caption, - # definition_list_item/definition, field/field_body, - # option_list_item/description, figure/legend, - # option_list_item/option_group - if subOpcode.getCommand() != Opcode.Descend: - # Propagate 1-element sequences up - opcode.setCommand(subOpcode.getCommand()) + if subOpcode.getCommand() == Opcode.Descend: + propagateUp = False + elif subOpcode.getCommand() == Opcode.Replace: + if any([ isinstance(oldNode, cls) + for cls in replaceNotUp ]): + propagateUp = False + # TODO FIXME `container` must be considered + if any([ isinstance(oldNode, cls) + for ( cls, container, ) in replaceUpSiblings ]): + # If for instance a section/title would + # propagate a replacement up the propagation + # needs to be done if all siblings would + # also propagate a replacement up + mightReplaceUpSiblings.append(i) + else: + propagateUp = True + else: + propagateUp = True + if propagateUp: + # Propagate 1-element sequences up + opcode.setCommand(subOpcode.getCommand()) opcodes[i] = opcode.asTuple() -def createDiff(oldTree, newTree): + if mightReplaceUpSiblings: + # There are entries which might propagate a replace up if all + # siblings could do as well + if all([ i in mightReplaceUpSiblings + or Opcode(opcodes[i]).getCommand() == Opcode.Replace + for i in range(len(opcodes)) ]): + # All entries are replacements which may propagate up - + # actually propagate elements which may propagate + for i in mightReplaceUpSiblings: + opcode = Opcode(opcodes[i]) + opcode.setCommand(Opcode.Replace) + opcodes[i] = opcode.asTuple() + +def createDiff(oldTree, newTree, debug=False): """Create and return a diff document from `oldTree` to `newTree`.""" dispatcher = DocutilsDispatcher() - #dispatcher.debug = True + dispatcher.debug = debug opcodes = doDiff(dispatcher, oldTree, newTree) - if dispatcher.debug: + if debug: from pprint import pprint print(oldTree.asdom().toprettyxml()) print(newTree.asdom().toprettyxml()) pprint(opcodes, sys.stdout, 2, 40, None) print("^^^ Before cleaning vvv After cleaning") cleanOpcodes(opcodes, dispatcher, [ oldTree ], [ newTree ]) - if dispatcher.debug: + if debug: from pprint import pprint pprint(opcodes, sys.stdout, 2, 40, None) if len(opcodes) != 1: diff --git a/sandbox/rstdiff/setup.py b/sandbox/rstdiff/setup.py new file mode 100755 index 000000000..39049a109 --- /dev/null +++ b/sandbox/rstdiff/setup.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +from distutils.core import setup + +from version import version + +setup(name='rstdiff', + version=version, + description='Tool for creating a diff highlighting changes from two reStructuredText input files', + author='Stefan Merten', + author_email='smerten@oekonux.de', + url='http://docutils.sourceforge.net/sandbox/rstdiff/', + license='GPL 2', + requires=[ 'docutils' ], + scripts=[ 'rstdiff.py' ], + packages=[ 'treediff' ], + ) diff --git a/sandbox/rstdiff/tag.log b/sandbox/rstdiff/tag.log index df0f4e962..14ab371bc 100644 --- a/sandbox/rstdiff/tag.log +++ b/sandbox/rstdiff/tag.log @@ -1 +1 @@ -rstdiff_1_74 +rstdiff_1_90 diff --git a/sandbox/rstdiff/tests/html/expected/contents.html b/sandbox/rstdiff/tests/html/expected/contents.html index fa9e52651..751964c11 100644 --- a/sandbox/rstdiff/tests/html/expected/contents.html +++ b/sandbox/rstdiff/tests/html/expected/contents.html @@ -3,7 +3,7 @@ - +