summaryrefslogtreecommitdiffstats
path: root/testing/make-archives
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-17 07:38:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-17 07:38:11 +0000
commitd1801d1e6f670f245e0deb5edde46e1daf131c78 (patch)
tree87972441ed083bdd8ae4f511388bd4acc0a85988 /testing/make-archives
parentAdding upstream version 2.12.1. (diff)
downloadpre-commit-d1801d1e6f670f245e0deb5edde46e1daf131c78.tar.xz
pre-commit-d1801d1e6f670f245e0deb5edde46e1daf131c78.zip
Adding upstream version 2.13.0.upstream/2.13.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/make-archives')
-rwxr-xr-xtesting/make-archives42
1 files changed, 29 insertions, 13 deletions
diff --git a/testing/make-archives b/testing/make-archives
index b2b288c..cb0b0a4 100755
--- a/testing/make-archives
+++ b/testing/make-archives
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import argparse
+import gzip
import os.path
import shutil
import subprocess
@@ -14,25 +15,24 @@ from typing import Sequence
REPOS = (
- ('rbenv', 'git://github.com/rbenv/rbenv', '0843745'),
- ('ruby-build', 'git://github.com/rbenv/ruby-build', '500863c'),
+ ('rbenv', 'https://github.com/rbenv/rbenv', '585ed84'),
+ ('ruby-build', 'https://github.com/rbenv/ruby-build', 'e9fa4bf'),
(
'ruby-download',
- 'git://github.com/garnieretienne/rvm-download',
+ 'https://github.com/garnieretienne/rvm-download',
'09bd7c6',
),
)
+def reset(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
+ tarinfo.uid = tarinfo.gid = 0
+ tarinfo.uname = tarinfo.gname = 'root'
+ tarinfo.mtime = 0
+ return tarinfo
+
+
def make_archive(name: str, repo: str, ref: str, destdir: str) -> str:
- """Makes an archive of a repository in the given destdir.
-
- :param text name: Name to give the archive. For instance foo. The file
- that is created will be called foo.tar.gz.
- :param text repo: Repository to clone.
- :param text ref: Tag/SHA/branch to check out.
- :param text destdir: Directory to place archives in.
- """
output_path = os.path.join(destdir, f'{name}.tar.gz')
with tempfile.TemporaryDirectory() as tmpdir:
# this ensures that the root directory has umask permissions
@@ -47,8 +47,24 @@ def make_archive(name: str, repo: str, ref: str, destdir: str) -> str:
# runtime
shutil.rmtree(os.path.join(gitdir, '.git'))
- with tarfile.open(output_path, 'w|gz') as tf:
- tf.add(gitdir, name)
+ arcs = [(name, gitdir)]
+ for root, dirs, filenames in os.walk(gitdir):
+ for filename in dirs + filenames:
+ abspath = os.path.abspath(os.path.join(root, filename))
+ relpath = os.path.relpath(abspath, gitdir)
+ arcs.append((os.path.join(name, relpath), abspath))
+ arcs.sort()
+
+ with gzip.GzipFile(output_path, 'wb', mtime=0) as gzipf:
+ # https://github.com/python/typeshed/issues/5491
+ with tarfile.open(fileobj=gzipf, mode='w') as tf: # type: ignore
+ for arcname, abspath in arcs:
+ tf.add(
+ abspath,
+ arcname=arcname,
+ recursive=False,
+ filter=reset,
+ )
return output_path