Mailing List Archive

Tools for three way merge of Python source files?
Keywords: diff3, merge, three-way, 3-way

Are there tools to help with 3-way merges of Python sources and/or
indentation conversion?

I'm using Python on a Real Project and I need to do a 3-way merge.
Certain whitespace characters must be ignored -- specifically, carriage
returns. I have a diff tool which ignores blanks but then I run into
problems where a block of code has been indented further (inside a new
block).

I wish I could rely on the parser to catch this sort of thing, but it
won't detect all possible follies, such as this one:

<my file & ancestor are the same>
if foo:
if bar:
baz()
else:
frob()

<other file, important change>
if foo:
if bar:
baz()
else:
frob()

Here, the merge result (using blank ignorance) would not incorporate
the changes from <other file>.

One correct solution seems to be to strip CR from CRLF. But I'm
afraid of having too many conflicting sections (false negatives) where
the spacing difference is actually benign. Perhaps I should just tell
my fellow developers not to change indentation unless they have to.

So, it also appears that I need a Python-aware indentation converter --
something that converts a source file to use a minimal number of tabs (or
perhaps spaces, as long as it were consistent) for block indents.

If anyone has had similar experiences or knows of a solution I'd love
to hear about it. Email is preferred. Thanks.


(I really hope this doesn't start Yet Another Whitespace War.)

--
Milton L. Hankins -=- <mlh@swl.msd.ray.com>
Software Engineer, Raytheon Systems Company -=- RayComNet 7-225-4728
http://amasts.msd.ray.com/~mlh -=- ><> Isaiah 64:6 ><>
Tools for three way merge of Python source files? [ In reply to ]
Milton L. Hankins writes:

> Are there tools to help with 3-way merges of Python sources and/or
> indentation conversion?

I can help with the indentation conversion.

http://www.mcmillan-inc.com/dnld/tabcleaner.py

This converts leading whitespace to whatever tab / spaces
configuration you want. It uses tokenize.py to determine indents and
dedents, so it's Guido doing the parsing, not me.

(Anyone who's had trouble with this before - it's been completely
rewritten, and no longer gets fooled by certain triple-quoted
strings).

Another way (for your purposes) might be to always filter everything
through pindent.py.

> I'm using Python on a Real Project and I need to do a 3-way merge.
> Certain whitespace characters must be ignored -- specifically,
> carriage returns. I have a diff tool which ignores blanks but then
> I run into problems where a block of code has been indented further
> (inside a new block).
>
> I wish I could rely on the parser to catch this sort of thing, but
> it won't detect all possible follies, such as this one:
>
> <my file & ancestor are the same>
> if foo:
> if bar:
> baz()
> else:
> frob()
>
> <other file, important change>
> if foo:
> if bar:
> baz()
> else:
> frob()
>
> Here, the merge result (using blank ignorance) would not incorporate
> the changes from <other file>.
>
> One correct solution seems to be to strip CR from CRLF. But I'm
> afraid of having too many conflicting sections (false negatives)
> where the spacing difference is actually benign. Perhaps I should
> just tell my fellow developers not to change indentation unless they
> have to.
>
> So, it also appears that I need a Python-aware indentation converter
> -- something that converts a source file to use a minimal number of
> tabs (or perhaps spaces, as long as it were consistent) for block
> indents.
>
> If anyone has had similar experiences or knows of a solution I'd
> love to hear about it. Email is preferred. Thanks.
>
>
> (I really hope this doesn't start Yet Another Whitespace War.)
>
> --
> Milton L. Hankins -=-
> <mlh@swl.msd.ray.com>
> Software Engineer, Raytheon Systems Company -=- RayComNet
> 7-225-4728
> http://amasts.msd.ray.com/~mlh -=- ><> Isaiah 64:6
> ><>
>
>

- Gordon
Tools for three way merge of Python source files? [ In reply to ]
"Milton L. Hankins" wrote:
>
> Keywords: diff3, merge, three-way, 3-way
>
You can use the GNU Emacs merge tool.
You will have a color presentation with some nice facilities.
Emacs can translate tabs to white-spaces and reverse and back
(untabify).
http://www.fsf.org

You can also use CVS to store your files
and ask it to merge them when you have several
branches of development.
http://www.cyclic.com

Marcvs [.alias Emacs also have an undo, if to want to get back to the
reverse
of your translation]