views:

67

answers:

2

Having read this past question for git, I would like to ask if there exists something like that, but

  1. can be done programmatically (file list) on each machine;
  2. works for Mercurial.

The reason for this is that I would like to include in my public dotfiles repository some configuration files that store password in plaintext. I know I could write a wraparound script for hg(1) but I would like to know if there are alternative approaches, just for the sake of curiosity.

Thank you.

+2  A: 

You could use a pair of pre-commit and post-update hooks to encrypt/decrypt as necessary. See http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html for more details.

However, it's worth pointing out that if you're storing encrypted text in your repo you'll be unable to create meaningful diffs -- essentially everything will be like a binary file but also poorly compressible.

Ry4an
A: 

Mercurial has a filter system that lets you mangle files when they are read from the repository or written back. If you have a program like the SSH agent running that lets you do non-interactive encryption and decryption, then this might just be workable.

As Ryan points out, this will necessarily lead to a bigger repository since each encrypted version of your files will look completely different from the previous version. Mercurial detects this and stores the versions uncompressed (encrypted files cannot be compressed anyway). Since you will use this for dotfiles, you can ignore the space overhead, but it's something to take into consideration if you will be versioning bigger files in encrypted form.

Please post a mail to [email protected] with your experiences so that other users can benefit from them too.

Martin Geisler
Thank you Martin, I didn't have any spare time to test your suggestion; as this question outlines a real problem for me (and I do have an ssh-agent running) rest assured that I will duly report my experience, when I get some time to tinker with my repository. Thanks again.
Emanuele Cipolla
Emanuele: thanks, sounds good!
Martin Geisler