views:

100

answers:

2

I'm using Mercurial (specifically TortoiseHg on Windows) to do version control of VBA code. Anybody who's tried this knows that VBA changes the case of every variable throughout a project whenever any declaration of that variable is changed anywhere in the project (regardless of scope). It makes version control a nightmare.

I would like to ignore case changes in my source code when performing diffs. What is the easiest way to do this? (some option for diff that I'm missing, an external diff utility, something else?)

NOTE: I am not talking about dealing with 'case-insensitive filenames' (yes, I'm talking to you Google...)

A: 

You can do that when diffing for your on-screen consumption using the ExtDiff Extension.

  [extensions]
  hgext.extdiff =

  [extdiff]
  # add new command that runs GNU diff(1) in case-insensitive mode
  cmd.mydiff = diff
  opts.mydiff = -i

Then you'd run hg mydiff from the command line. That, of course, requires you have a diff binary installed be it gnu's or other.

However, that's not going to be as helpful as you might like because internally, of course, Mercurial can't ignore case -- it's taking the cryptographic hash of the file contents, and those don't allow for wiggle room. So if you get this set up you'll do hg mydiff, and see no changes, and then do hg commit and see changes all over the place.

So you can make this work on-screen, but not fundamentally.

One option would be to find a visual basic code-cleaner, similar to indent for C-like languages, that normalizes variable case and run that in a mercurial commit hook. Then at least all the code going into source control will be consistent and you can diff across revisions accurately.

Ry4an
Sounds like some sort of code-cleaner will be my only option. Thanks for your help.
mwolfe02
A: 

If you are okay with having your code in all lower-case, say, then you could employ the encode/decode hooks for this. It would work like this:

[encode]
*.vba = tr A-Z a-z

This will encode the file content in lower-case whenever you do a commit. The diffs are also computed based on the encoded (repository) version of the files.

Consider a file that contains

hello

Changing it in your working copy to

Hello World

will give a diff of

% hg diff
diff --git a/a.txt b/a.txt
--- a/a.txt
+++ b/a.txt
@@ -1,1 +1,1 @@
-hello
+hello world

Notice how the capital "H" and "W" has been ignored.

I don't really know anything about VBA code, so I'm not 100% sure this solution works for you. But I hope it can be a starting point.

One drawback is that you'll need to set this encode rule for all your repositories. The reposettings extension can help you here.

Martin Geisler
That wouldn't really work for me in this case, but it's a great tip that I'll try to remember for the future. Thanks for the help.
mwolfe02