Saturday, October 20, 2012

Finding changes in ugly XML with git and xmllint

This is probably not going to be useful to very many people, but it helped me track down a small bug, and I'm preserving it mostly incase I need something similar later.

So the key issue here is that we have some XML that is stored in git. Unfortunately this generated XML is not nicely formatted. Thus changes in git don't show nicely using git log or git diff.

My technique was this:

  1. Find the commits that changed the file of interest.

    git log --oneline afile.xml | awk '{print $1}'
  2. Get the file at that revision.

    git show $REVISION:afile.xml
  3. Get the file at the previous revision

    git show $REVISION~1:afile.xml
  4. Pass these through xmllint --format to clean them up

  5. diff the cleaned up versions

This sounds pretty complex, but it can be wrapped up into a concise piece of bash script.
Now its not going to work across merges etc, but the general technique can be handy.

I suspect a similar thing may have been obtainable by setting a custom diff tool in git but I couldn't see an easy way to get exactly what I wanted.

No comments:

Post a Comment