Tools for three way merge of Python source files?

Gordon McMillan gmcm at hypernet.com
Tue Apr 13 18:10:51 EDT 1999


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 at swl.msd.ray.com>
> Software Engineer, Raytheon Systems Company  -=-  RayComNet 
> 7-225-4728
>       http://amasts.msd.ray.com/~mlh         -=-  ><>  Isaiah 64:6 
>       ><> 
> 
> 

- Gordon




More information about the Python-list mailing list