Converting binary<->textual - what to do (hooks?, extension?, custom merge?)

Marcin Kasperski Marcin.Kasperski at softax.com.pl
Wed Feb 6 06:49:40 CST 2008


Well, the not-so-rare (I think) scenario.

There is some app which uses custom binary format to save the files.
But this app is also able to export/import to/from textual readable
format.

  (typical example - exporting some document, spreadsheet
   etc to the XML format, not-so-rare one - bare unzipping
   compressed XML used by some app, my own use case - exporting
   binary chess database to PGN, etc)

In such a situation it is really tempting to version-control the
exported (textual) version instead of native binary. For at least
three reasons:

- normal merge is possible,
- save is usually more compact,
- in multiplatform cases it happens that textual format is portable
  while binary one is not

So - is it possible to have mercurial automatically convert the
data format? And what is the best approach?

Let us assume that we have files *.bin with binary data and command
line tools bin2txt and txt2bin which make the conversions.

My first idea was to use hooks, but their description is rather
tense and I am not sure which hooks I could try and whether attempts
to modify the files will really work there (for some reason all
example hooks are passive and prefer to croak about unnecessary
whitespace instead of correcting it for example). And while I have
some hopes that precommit would do, I am strongly afraid that
converting back on update need not to work always (how to force
it after merge, for example??? - and how to make merge work on
textual format instead of binary)

Or maybe it should be an extension? The only somewhat similar
thing is win32text which is converting newlines (and for some
reason it is extension, not set of hooks)

Or maybe the whole idea is flawed and impossible and I should 
only hunt for some method of converting to the textual format
for the merge operations?



-- 
----------------------------------------------------------------------
| Marcin Kasperski   | If we are to be successful, we must still have
| http://mekk.waw.pl |    the courage to put our faith in people as
|                    |  opposed to a process. (Booch,Martin,Newkirk)
----------------------------------------------------------------------



More information about the Mercurial mailing list