-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a27f2ff
commit 6e3d690
Showing
4 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env python | ||
# Export the current stash (or a specific revision) as a .tgz archive | ||
from __future__ import print_function | ||
|
||
import os, sys, subprocess, shutil | ||
from optparse import OptionParser | ||
|
||
def resolve_commit(rev): | ||
return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() | ||
|
||
def get_commit(cwd, rev): | ||
if rev is not None: | ||
return resolve_commit(rev) | ||
|
||
env = os.environ.copy() | ||
env['GIT_AUTHOR_NAME'] = 'nobody' | ||
env['GIT_AUTHOR_EMAIL'] = 'nobody@example.org' | ||
env['GIT_AUTHOR_DATE'] = '1970-01-01T00:00:00Z' | ||
env['GIT_COMMITTER_NAME'] = 'nobody' | ||
env['GIT_COMMITTER_EMAIL'] = 'nobody@example.org' | ||
env['GIT_COMMITTER_DATE'] ='1970-01-01T00:00:00Z' | ||
out = subprocess.check_output(['git', 'stash', 'create'], env=env).strip() | ||
if out == '': | ||
return resolve_commit('HEAD') | ||
else: | ||
return out | ||
|
||
def get_current_tar_commit(path): | ||
gunzip = subprocess.Popen(['gunzip', '-c', path], stdout = subprocess.PIPE) | ||
get_tar_commit = subprocess.Popen(['git', 'get-tar-commit-id'], stdin=gunzip.stdout) | ||
current_commit, _ = get_tar_commit.communicate() | ||
if not all([status == 0 for status in [ gunzip.wait(), get_tar_commit.wait() ]]): | ||
print("WARN: unable to determine commit of existing file: %s" % (path,), file=sys.stderr) | ||
return None | ||
else: | ||
return current_commit.strip() | ||
|
||
def export_commit(commit, dest, target, cwd): | ||
subprocess.check_call(['gup', '--always']) | ||
checksum_proc = subprocess.Popen(['gup', '--contents'], stdin=subprocess.PIPE) | ||
checksum_proc.communicate(commit) | ||
assert checksum_proc.wait() == 0, "gup --contents failed" | ||
|
||
if os.path.exists(target): | ||
current_commit = get_current_tar_commit(target) | ||
if current_commit == commit: | ||
# Don't regenerate archive; we just end up with the same contents but different mtimes | ||
# (https://blog.lnx.cx/2015/05/15/getting-consistent-fingerprints-from-git-archive/) | ||
shutil.copyfile(target, dest) | ||
else: | ||
with open(dest, 'w') as dest_f: | ||
subprocess.check_call(['git', 'archive', commit, '--format=tar.gz', '--prefix=git-export/'], stdout=dest_f, cwd=cwd) | ||
|
||
def main(): | ||
try: | ||
p = OptionParser() | ||
p.add_option('--rev', help='export specific commit') | ||
opts, args = p.parse_args() | ||
dest, target = args | ||
|
||
dest_dir = os.path.dirname(dest) or '.' | ||
git_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], cwd=dest_dir).strip() | ||
commit = get_commit(cwd=git_root, rev=opts.rev) | ||
export_commit(commit, dest, target, cwd=git_root) | ||
except KeyboardInterrupt: | ||
sys.exit(1) | ||
except subprocess.CalledProcessError as e: | ||
print(str(e), file=sys.stderr) | ||
sys.exit(1) | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ stdenv.mkDerivation { | |
installPhase = '' | ||
mkdir $out | ||
cp -r python/bin $out/bin | ||
cp builders/* $out/bin/ | ||
''; | ||
} |