debian/bin/genorig.py: Defuse `export-subst'
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 22 Feb 2018 18:11:39 +0000 (18:11 +0000)
committerHans van Kranenburg <hans@knorrie.org>
Thu, 22 Feb 2018 20:06:49 +0000 (21:06 +0100)
The Xen upstream tree has .gitattributes which cause `git archive' to
change things in .gitarchive-info.  This is troublesome because it
means that tarballs generated by genorig are not identical to the git
trees.

Work around this by temporarily creating a .gitattributes which
disables export-subst.  We move aside any existing .gitattributes, so
that this works whether we are in a Debian packaging branch with
upstream files in, or an upstream branch, or a bare-packaging branch.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
debian/bin/genorig.py

index 5a0d435f69cf4a9a2129b0d92affee4be972e9ec..8128a33ee1ff12b12783f78e0bd613375228cc61 100755 (executable)
@@ -57,9 +57,14 @@ class Main(object):
         except OSError:
             pass
 
+        ga_exists = os.path.exists('.gitattributes')
         try:
+            if ga_exists:
+                os.rename('.gitattributes','.gitattributes.genorig-saved')
+            with open('.gitattributes', 'w') as ga:
+                print('* -export-subst\n', file=ga)
             with open(out, 'wb') as f:
-                _cmd = ('git', 'archive', '--prefix', '%s/' % self.orig_dir, treeish)
+                _cmd = ('git', 'archive', '--worktree-attributes', '--prefix', '%s/' % self.orig_dir, treeish)
                 p1 = subprocess.Popen(_cmd, stdout=subprocess.PIPE, cwd=self.repo)
                 subprocess.check_call(('xz', ), stdin=p1.stdout, stdout=f)
                 if p1.wait():
@@ -68,6 +73,13 @@ class Main(object):
             os.unlink(out)
             raise
 
+        try:
+            if ga_exists:
+                os.rename('.gitattributes.genorig-saved','.gitattributes')
+            else:
+                os.unlink('.gitattributes')
+        except Exception: pass
+
         try:
             os.symlink(os.path.join('orig', self.orig_tar), os.path.join('..', self.orig_tar))
         except OSError: