hg: parse dirstate

based on the perl code. this doesn't work, as dirstate is not correct
for the modification state.
close the FILE* from the setmntent call
free the contexts
Add optional directory argument