From b86ec60cbaad8eeaec3855b4dc8ceff6958fcf5a Mon Sep 17 00:00:00 2001
From: Robert Bradshaw <robertwb@math.washington.edu>
Date: Sun, 22 Nov 2009 02:29:16 -0800
Subject: [PATCH] Remove repo from sdist, autogenerate .hgrev

---
 MANIFEST.in |  3 +--
 setup.py    | 11 +++++++++++
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index ff6720dde..a7133cf46 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,7 +1,6 @@
 include MANIFEST.in README.txt INSTALL.txt ToDo.txt USAGE.txt
 include COPYING.txt LICENSE.txt Makefile
-recursive-include .hg *
-include .hgignore .hgtags
+include .hgrev
 include setup.py
 include bin/*
 include cython.py
diff --git a/setup.py b/setup.py
index 3c8b0d9fc..90c125f4e 100644
--- a/setup.py
+++ b/setup.py
@@ -3,6 +3,17 @@ from distutils.sysconfig import get_python_lib
 import os, os.path
 import sys
 
+if 'sdist' in sys.argv:
+    # Record the current revision in .hgrev
+    import subprocess # os.popen is cleaner but depricated
+    changset = subprocess.Popen("hg log --rev tip | grep changeset", 
+                                shell=True,
+                                stdout=subprocess.PIPE).stdout.read()
+    rev = changset.split(':')[-1].strip()
+    hgrev = open('.hgrev', 'w')
+    hgrev.write(rev)
+    hgrev.close()
+
 compiler_dir = os.path.join(get_python_lib(prefix=''), 'Cython/Compiler')
 if sys.platform == "win32":
     compiler_dir = compiler_dir[len(sys.prefix)+1:]
-- 
2.30.9