Reputation: 4114
I need to manage XML documents in Subversion but don't want to manage the formatting which may turn out differently depending on who is editing the file.
I see two solutions: Either format the file each time with a known formatting before checking in. Or give svn a diff program that actively dismisses formatting from the diff algorithm. Ultimately the diff should of course support three-way merge actively ignoring the XML formatting.
What do you recommend?
(The same reasoning usually applies to code source files, but the problem is more difficult.)
Upvotes: 4
Views: 2305
Reputation: 35519
I don't have a lot of personal experience with such a setup.
For the second method (a custom diff), what I've found is an example, "API description for Netopeer repository library" which is a detailed description of a setup with Subversion and, among other things, xmldiff.
For the other approach, converting to a know format before storing in Subversion, I recommend Canonical XML as the format. The xmllint tool, for instance, can convert to this format:
% cat complique.xml
<?xml version="1.0" encoding="utf-8"?>
<toto >
<truc a="1" >Machin C </truc >café</toto>
% xmllint --c14n complique.xml
<toto>
<truc a="1">Machin C </truc>café</toto>
To integrate with Subversion, you could test in pre-commit that the submitted file is equal to the canonical file. A possible such script is my pre-commit using xmllint. See also the enforcer script for an example.
Upvotes: 3
Reputation: 3989
Just get all your developers on the same page. They should all be coding to the same standard anyway. If your coders are all using different formatting standards, you've got bigger problems to solve.
Upvotes: 0
Reputation: 11564
Do you consider the following two xml fragments to be the same...?
Fragment1:
<foo xmlns="http://foo.com/foo">
<bar>Hello</bar>
</foo>
Fragment2:
<ns1:foo xmlns:ns1="http://foo.com/foo">
<ns1:bar>Hello</ns1:bar>
</ns1:foo>
... because if you do (as these fragments have the same xml infoset) then you need to consider writing your own diff tool.
Upvotes: 1
Reputation: 17522
If by "formatting" you mean "whitespace" you can configure svn diff
to ignore whitespace with the -w
switch in the diff
command:
$ svn diff -x -w [file]
See svn help diff
for more information.
Upvotes: 0