{"thread":{"id":"14228","subject":"[PATCH] Add another fast-import example, this time for .zip files","startedAt":"2008-06-30T18:50:44Z","lastAt":"2008-06-30T22:53:52Z","messageCount":2,"participants":["Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"81767","messageId":"alpine.DEB.1.00.0806301948130.9925@racer","threadId":"14228","inReplyTo":null,"subject":"[PATCH] Add another fast-import example, this time for .zip files","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-06-30T18:50:44Z","receivedAt":"2008-06-30T18:50:44Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tI needed that today.\n\n contrib/fast-import/import-zip.py |   66 +++++++++++++++++++++++++++++++++++++\n 1 files changed, 66 insertions(+), 0 deletions(-)\n create mode 100755 contrib/fast-import/import-zip.py\n\ndiff --git a/contrib/fast-import/import-zip.py b/contrib/fast-import/import-zip.py\nnew file mode 100755\nindex 0000000..de677e4\n--- /dev/null\n+++ b/contrib/fast-import/import-zip.py\n@@ -0,0 +1,66 @@\n+#!/usr/bin/python\n+\n+## zip archive frontend for git-fast-import\n+##\n+## For example:\n+##\n+##  mkdir project; cd project; git init\n+##  python import-zips.py *.zip\n+##  git log --stat import-zips\n+\n+from os import popen, path\n+from sys import argv, exit\n+from time import mktime\n+from zipfile import ZipFile\n+\n+if len(argv) < 2:\n+\tprint 'Usage:', argv[0], '<zipfile>...'\n+\texit(1)\n+\n+branch_ref = 'refs/heads/import-zips'\n+committer_name = 'Z Ip Creator'\n+committer_email = 'zip@example.com'\n+\n+fast_import = popen('git fast-import --quiet', 'w')\n+def printlines(list):\n+\tfor str in list:\n+\t\tfast_import.write(str + \"\\n\")\n+\n+for zipfile in argv[1:]:\n+\tcommit_time = 0\n+\tnext_mark = 1\n+\tcommon_prefix = None\n+\tmark = dict()\n+\t\n+\tzip = ZipFile(zipfile, 'r')\n+\tfor name in zip.namelist():\n+\t\tif name.endswith('/'):\n+\t\t\tcontinue\n+\t\tinfo = zip.getinfo(name)\n+\n+\t\tif commit_time < info.date_time:\n+\t\t\tcommit_time = info.date_time\n+\n+\t\tmark[name] = ':' + str(next_mark)\n+\t\tnext_mark += 1\n+\n+\t\tprintlines(('blob', 'mark ' + mark[name], \\\n+\t\t\t\t\t'data ' + str(info.file_size)))\n+\t\tfast_import.write(zip.read(name) + \"\\n\")\n+\n+\tcommitter = committer_name + ' <' + committer_email + '> %d +0000' % \\\n+\t\tmktime(commit_time + (0, 0, 0))\n+\n+\tprintlines(('commit ' + branch_ref, 'committer ' + committer, \\\n+\t\t'data <<EOM', 'Imported from ' + zipfile + '.', 'EOM', \\\n+\t\t'', 'deleteall'))\n+\n+\tfor name in mark.keys():\n+\t\tfast_import.write('M 100644 ' + mark[name] + ' ' + name + \"\\n\")\n+\n+\tprintlines(('',  'tag ' + path.basename(zipfile), \\\n+\t\t'from ' + branch_ref, 'tagger ' + committer, \\\n+\t\t'data <<EOM', 'Package ' + zipfile, 'EOM', ''))\n+\n+if fast_import.close():\n+\texit(1)\n-- \n1.5.6.1.297.g148d9\n"},{"id":"81798","messageId":"alpine.DEB.1.00.0806302352370.9925@racer","threadId":"14228","inReplyTo":"alpine.DEB.1.00.0806301948130.9925@racer","subject":"Re: [PATCH] Add another fast-import example, this time for .zip files","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-06-30T22:53:52Z","receivedAt":"2008-06-30T22:53:52Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 30 Jun 2008, Johannes Schindelin wrote:\n\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> \n> \tI needed that today.\n\n... and I needed that on top, which I forgot to commit, and therefore \nnever sent in my first mail on this subject:\n\n-- snipsnap --\ndiff --git a/contrib/fast-import/import-zip.py b/contrib/fast-import/import-zips.py\nsimilarity index 85%\nrename from contrib/fast-import/import-zip.py\nrename to contrib/fast-import/import-zips.py\nindex 4200a66..fcf5823 100755\n--- a/contrib/fast-import/import-zip.py\n+++ b/contrib/fast-import/import-zips.py\n@@ -40,6 +40,11 @@ for zipfile in argv[1:]:\n \n \t\tif commit_time < info.date_time:\n \t\t\tcommit_time = info.date_time\n+\t\tif common_prefix == None:\n+\t\t\tcommon_prefix = name[:name.rfind('/') + 1]\n+\t\telse:\n+\t\t\twhile not name.startswith(common_prefix):\n+\t\t\t\tcommon_prefix = name[:name.rfind('/') + 1]\n \n \t\tmark[name] = ':' + str(next_mark)\n \t\tnext_mark += 1\n@@ -56,7 +61,8 @@ for zipfile in argv[1:]:\n \t\t'', 'deleteall'))\n \n \tfor name in mark.keys():\n-\t\tfast_import.write('M 100644 ' + mark[name] + ' ' + name + \"\\n\")\n+\t\tfast_import.write('M 100644 ' + mark[name] + ' ' +\n+\t\t\tname[len(common_prefix):] + \"\\n\")\n \n \tprintlines(('',  'tag ' + path.basename(zipfile), \\\n \t\t'from ' + branch_ref, 'tagger ' + committer, \\\n"}]}