#!/usr/bin/env python # gzip archive frontend for git-fast-import from os import popen, path from os.path import splitext from os.path import getmtime from sys import argv, exit, hexversion, stderr from gzip import GzipFile import struct if len(argv) < 2: print 'usage:', argv[0], '...' 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 = 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): with open(filename) as f: f.seek(-4, 2) return struct.unpack('I', f.read(4))[0] for zipfile in argv[1:]: # Gzip does have an encoded mtime, however Python's GzipFile # just ignores it, so we just yank the mtime of the zip file itself. mtime = getmtime (zipfile); file_size = uncompressedsize (zipfile); zip = GzipFile(zipfile, 'rb') printlines(('blob', 'mark :1', 'data ' + str(file_size))) fast_import.write(zip.read() + "\n") committer = committer_name + ' <' + committer_email + '> %d +0000' % \ mtime zipfile_basename = path.basename(zipfile) printlines(('commit ' + branch_ref, 'committer ' + committer, \ 'data <