Revise hg Repo

From JoBaPedia
Revision as of 12:14, 14 October 2011 by Joachim (talk | contribs) (New page: == Revise a HG Repository == I have a mercurial repository, that I wanted to publish for a long time. But it contains some infos in its history (files, author, commit messages) that are n...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Revise a HG Repository

I have a mercurial repository, that I wanted to publish for a long time. But it contains some infos in its history (files, author, commit messages) that are not intended for public audience.

How do I get rid of this in the entire repositories history and not just at tip?

Ok, this literally took months to figure out, but in the end it was so easy.

Prerequisites are

  • you have full control over all clones, because they have to be deleted and replaced by the revised repository or the revised info will come back during syncs.
  • merges need to be checked manually (worked for me, but may not work)
  • no branching (perhaps needs manual intervention)
start=5 (no changes needed up to and including this revision)
end=10 (last repository revision)
hg clone originalrepo revisedrepo --rev $start
cd originalrepo
hg log -gp >/tmp/toxic-repo-history-unfolded.txt
i=$((start + 1))
while [ $i -le $end ]; do 
   hg export --rev $i -g >/tmp/changelist-$i.export
   sed -i 's/toxic-pattern/good-pattern/g' /tmp/changelist-$i.export
   i=$((i+1))
done
cd -
cd revisedrepo
i=$((start + 1))
while [ $i -le $end ]; do 
   hg import /tmp/changelist-$i.export
   i=$((i+1))
done
hg log -gp >/tmp/good-repo-history-unfolded.txt
cd -

That's it. Check thoroughly if it worked:

Check changes between toxic and good repo. Should only output lines expected to changed from toxic to good.

diff -U0 /tmp/toxic-repo-history-unfolded.txt /tmp/good-repo-history-unfolded.txt

Check for toxic patterns in good repo history. Should not output anything

grep toxic-pattern /tmp/good-repo-history-unfolded.txt

If checks are ok, remove the old repo(s) and all intermediate files in /tmp