From 4792912cecf52d63fdcc89e6f852e3a32f37c49c Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Mon, 4 May 2020 19:48:13 +0100 Subject: lorry,{g,}zip-importer: Move top-level code into functions Split the top-level code of each script into: * export: Exports a single file to a 'git fast-import' pipe * main: Spawns 'git fast-import' and calls export for each file --- lorry.gzip-importer | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'lorry.gzip-importer') diff --git a/lorry.gzip-importer b/lorry.gzip-importer index 8bc18ed..8d482b7 100755 --- a/lorry.gzip-importer +++ b/lorry.gzip-importer @@ -9,19 +9,11 @@ import struct import sys -if len(sys.argv) < 2: - print('usage:', sys.argv[0], '...') - sys.exit(1) - branch_name = 'master' branch_ref = 'refs/heads/%s' % branch_name committer_name = 'Lorry Gzip Importer' committer_email = 'lorry-gzip-importer@lorry' -fast_import = os.popen('git fast-import --quiet', 'w') -def printlines(list): - for str in list: - fast_import.write(str + "\n") # The size of a gzip file is stored in the last 4 bytes def uncompressedsize(filename): @@ -29,7 +21,11 @@ def uncompressedsize(filename): f.seek(-4, 2) return struct.unpack('I', f.read(4))[0] -for zipfile in sys.argv[1:]: + +def export(zipfile, fast_import): + def printlines(list): + for str in list: + fast_import.write(str + "\n") # Gzip does have an encoded mtime, however Python's GzipFile # just ignores it, so we just yank the mtime of the zip file itself. @@ -57,5 +53,17 @@ for zipfile in sys.argv[1:]: 'from ' + branch_ref, 'tagger ' + committer, \ 'data <...') + sys.exit(1) + + fast_import = os.popen('git fast-import --quiet', 'w') + for zipfile in sys.argv[1:]: + export(zipfile, fast_import) + if fast_import.close(): + sys.exit(1) + + +main() -- cgit v1.2.1