views:

37

answers:

1

I have a project, where I'm forced to use ftp as a means of deploying the files to the live server. I'm developing on linux, so I hacked together a bash script that makes a backup of the ftp server's contents, deletes all the files on the ftp, and uploads all the fresh files from the mercurial repository. (and taking care of user uploaded files and folders, and making post-deploy changes, etc)

It's working well, but the project is starting to get big enough to make the deployment process too long.

I'd like to modify the script to look up which files have changed, and only deploy the modified files. (the backup is fine atm as it is)

I'm using mercurial as a VCS, so my idea is to somehow request the changed files between two revisions from it, iterate over the changed files, and upload each modified file, and delete each removed file.

I can use hg log -vr rev1:rev2, and from the output, I can carve out the changed files with grep/sed/etc.

Two problems:

I have heard the horror stories that parsing the output of ls leads to insanity, so my guess is that the same applies to here, if I try to parse the output of hg log, the variables will undergo word-splitting, and all kinds of transformations.

hg log doesn't tell me a file is modified/added/deleted. Differentiating between modified and deleted files would be the least.

So, what would be the correct way to do this? I'm using yafc as an ftp client, in case it's needed, but willing to switch.

+3  A: 

You could use a custom style that does the parsing for you.

hg log --rev rev1:rev2 --style mystyle

Then pipe it to sort -u to get a unique list of files. The file "mystyle" would look like this:

changeset = '{file_mods}{file_adds}\n'
file_mod = '{file_mod}\n'
file_add = '{file_add}\n'

The mods and adds templates are files modified or added. There is a similar file_dels and file_del template for deleted files.

Alternatively, you could use hg status -ma --rev rev1-1:rev2 which adds an M or an A before modified/added files. You need to pass a different revision range, one less than rev1, as it is the status since that "baseline". Deleted files are similar - you need the -d flag and a D is added before each deleted file.

rq
Your hg status solution is much better since it combines the lists from all the changesets in the range instead of listing them separately.
Ry4an
But if I use the output of hg st, the same problems wouldn't arise? Like looking out for spaces in filenames?
WishCow
`hg st -ma --rev a:b | cut -c3- | while read file ; do stuff with "$file" ; done` will not give you problems with spaces in file names as you aren't splitting on spaces, only on newlines.
rq