git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: spearce@spearce.org, git@vger.kernel.org
Subject: [PATCH] Add another fast-import example, this time for .zip files
Date: Mon, 30 Jun 2008 19:50:44 +0100 (BST)	[thread overview]
Message-ID: <alpine.DEB.1.00.0806301948130.9925@racer> (raw)


Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---

	I needed that today.

 contrib/fast-import/import-zip.py |   66 +++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100755 contrib/fast-import/import-zip.py

diff --git a/contrib/fast-import/import-zip.py b/contrib/fast-import/import-zip.py
new file mode 100755
index 0000000..de677e4
--- /dev/null
+++ b/contrib/fast-import/import-zip.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+## zip archive frontend for git-fast-import
+##
+## For example:
+##
+##  mkdir project; cd project; git init
+##  python import-zips.py *.zip
+##  git log --stat import-zips
+
+from os import popen, path
+from sys import argv, exit
+from time import mktime
+from zipfile import ZipFile
+
+if len(argv) < 2:
+	print 'Usage:', argv[0], '<zipfile>...'
+	exit(1)
+
+branch_ref = 'refs/heads/import-zips'
+committer_name = 'Z Ip Creator'
+committer_email = 'zip@example.com'
+
+fast_import = popen('git fast-import --quiet', 'w')
+def printlines(list):
+	for str in list:
+		fast_import.write(str + "\n")
+
+for zipfile in argv[1:]:
+	commit_time = 0
+	next_mark = 1
+	common_prefix = None
+	mark = dict()
+	
+	zip = ZipFile(zipfile, 'r')
+	for name in zip.namelist():
+		if name.endswith('/'):
+			continue
+		info = zip.getinfo(name)
+
+		if commit_time < info.date_time:
+			commit_time = info.date_time
+
+		mark[name] = ':' + str(next_mark)
+		next_mark += 1
+
+		printlines(('blob', 'mark ' + mark[name], \
+					'data ' + str(info.file_size)))
+		fast_import.write(zip.read(name) + "\n")
+
+	committer = committer_name + ' <' + committer_email + '> %d +0000' % \
+		mktime(commit_time + (0, 0, 0))
+
+	printlines(('commit ' + branch_ref, 'committer ' + committer, \
+		'data <<EOM', 'Imported from ' + zipfile + '.', 'EOM', \
+		'', 'deleteall'))
+
+	for name in mark.keys():
+		fast_import.write('M 100644 ' + mark[name] + ' ' + name + "\n")
+
+	printlines(('',  'tag ' + path.basename(zipfile), \
+		'from ' + branch_ref, 'tagger ' + committer, \
+		'data <<EOM', 'Package ' + zipfile, 'EOM', ''))
+
+if fast_import.close():
+	exit(1)
-- 
1.5.6.1.297.g148d9

             reply	other threads:[~2008-06-30 18:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-30 18:50 Johannes Schindelin [this message]
2008-06-30 22:53 ` [PATCH] Add another fast-import example, this time for .zip files Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.1.00.0806301948130.9925@racer \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).