contrib/fast-import/import-zips.py: use spaces instead of tabs
Follow the conventional Python style by using 4-space indents instead of hard tabs. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
61a7aaccf4
commit
e257f0551f
@ -14,13 +14,13 @@ from time import mktime
|
|||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
if hexversion < 0x01060000:
|
if hexversion < 0x01060000:
|
||||||
# The limiter is the zipfile module
|
# The limiter is the zipfile module
|
||||||
stderr.write("import-zips.py: requires Python 1.6.0 or later.\n")
|
stderr.write("import-zips.py: requires Python 1.6.0 or later.\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if len(argv) < 2:
|
if len(argv) < 2:
|
||||||
print 'usage:', argv[0], '<zipfile>...'
|
print 'usage:', argv[0], '<zipfile>...'
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
branch_ref = 'refs/heads/import-zips'
|
branch_ref = 'refs/heads/import-zips'
|
||||||
committer_name = 'Z Ip Creator'
|
committer_name = 'Z Ip Creator'
|
||||||
@ -28,51 +28,51 @@ committer_email = 'zip@example.com'
|
|||||||
|
|
||||||
fast_import = popen('git fast-import --quiet', 'w')
|
fast_import = popen('git fast-import --quiet', 'w')
|
||||||
def printlines(list):
|
def printlines(list):
|
||||||
for str in list:
|
for str in list:
|
||||||
fast_import.write(str + "\n")
|
fast_import.write(str + "\n")
|
||||||
|
|
||||||
for zipfile in argv[1:]:
|
for zipfile in argv[1:]:
|
||||||
commit_time = 0
|
commit_time = 0
|
||||||
next_mark = 1
|
next_mark = 1
|
||||||
common_prefix = None
|
common_prefix = None
|
||||||
mark = dict()
|
mark = dict()
|
||||||
|
|
||||||
zip = ZipFile(zipfile, 'r')
|
zip = ZipFile(zipfile, 'r')
|
||||||
for name in zip.namelist():
|
for name in zip.namelist():
|
||||||
if name.endswith('/'):
|
if name.endswith('/'):
|
||||||
continue
|
continue
|
||||||
info = zip.getinfo(name)
|
info = zip.getinfo(name)
|
||||||
|
|
||||||
if commit_time < info.date_time:
|
if commit_time < info.date_time:
|
||||||
commit_time = info.date_time
|
commit_time = info.date_time
|
||||||
if common_prefix == None:
|
if common_prefix == None:
|
||||||
common_prefix = name[:name.rfind('/') + 1]
|
common_prefix = name[:name.rfind('/') + 1]
|
||||||
else:
|
else:
|
||||||
while not name.startswith(common_prefix):
|
while not name.startswith(common_prefix):
|
||||||
last_slash = common_prefix[:-1].rfind('/') + 1
|
last_slash = common_prefix[:-1].rfind('/') + 1
|
||||||
common_prefix = common_prefix[:last_slash]
|
common_prefix = common_prefix[:last_slash]
|
||||||
|
|
||||||
mark[name] = ':' + str(next_mark)
|
mark[name] = ':' + str(next_mark)
|
||||||
next_mark += 1
|
next_mark += 1
|
||||||
|
|
||||||
printlines(('blob', 'mark ' + mark[name], \
|
printlines(('blob', 'mark ' + mark[name], \
|
||||||
'data ' + str(info.file_size)))
|
'data ' + str(info.file_size)))
|
||||||
fast_import.write(zip.read(name) + "\n")
|
fast_import.write(zip.read(name) + "\n")
|
||||||
|
|
||||||
committer = committer_name + ' <' + committer_email + '> %d +0000' % \
|
committer = committer_name + ' <' + committer_email + '> %d +0000' % \
|
||||||
mktime(commit_time + (0, 0, 0))
|
mktime(commit_time + (0, 0, 0))
|
||||||
|
|
||||||
printlines(('commit ' + branch_ref, 'committer ' + committer, \
|
printlines(('commit ' + branch_ref, 'committer ' + committer, \
|
||||||
'data <<EOM', 'Imported from ' + zipfile + '.', 'EOM', \
|
'data <<EOM', 'Imported from ' + zipfile + '.', 'EOM', \
|
||||||
'', 'deleteall'))
|
'', 'deleteall'))
|
||||||
|
|
||||||
for name in mark.keys():
|
for name in mark.keys():
|
||||||
fast_import.write('M 100644 ' + mark[name] + ' ' +
|
fast_import.write('M 100644 ' + mark[name] + ' ' +
|
||||||
name[len(common_prefix):] + "\n")
|
name[len(common_prefix):] + "\n")
|
||||||
|
|
||||||
printlines(('', 'tag ' + path.basename(zipfile), \
|
printlines(('', 'tag ' + path.basename(zipfile), \
|
||||||
'from ' + branch_ref, 'tagger ' + committer, \
|
'from ' + branch_ref, 'tagger ' + committer, \
|
||||||
'data <<EOM', 'Package ' + zipfile, 'EOM', ''))
|
'data <<EOM', 'Package ' + zipfile, 'EOM', ''))
|
||||||
|
|
||||||
if fast_import.close():
|
if fast_import.close():
|
||||||
exit(1)
|
exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user