From 169133e16e316476272878f70980bc03db071dfb Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 6 Oct 2010 15:01:32 -0400 Subject: [PATCH] =?UTF-8?q?Add=20Mercurial=20hook=20hack=20to=20fix=20syml?= =?UTF-8?q?inks=20on=20Windows=C2=AE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .hgignore | 2 ++ common/contrib/fix_symlinks.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 common/contrib/fix_symlinks.py diff --git a/.hgignore b/.hgignore index 93349ece..e55fa075 100644 --- a/.hgignore +++ b/.hgignore @@ -14,6 +14,8 @@ syntax: glob */bak/* downloads/* +*.py[co] + ## Editor backup and swap files *~ .#* diff --git a/common/contrib/fix_symlinks.py b/common/contrib/fix_symlinks.py new file mode 100644 index 00000000..6f4bdf28 --- /dev/null +++ b/common/contrib/fix_symlinks.py @@ -0,0 +1,20 @@ +from mercurial import util +import os + +def fix_symlinks(repo, hooktype, parent1, **kwargs): + revert = hooktype in ('precommit', 'preupdate') + ctxt = repo[parent1] + for filename in ctxt: + file = ctxt[filename] + if 'l' in file.flags(): + path = repo.wjoin(file.path()) + try: + os.unlink(path) + except Exception, e: + print repr(e) + if revert: + repo.wwrite(file.path(), file.data(), '') + else: + target = os.path.join(os.path.dirname(path), file.data()) + util.copyfiles(target, path, True) +