From: Clark Williams <clark.williams@gmail.com>
To: "Karl Hasselström" <kha@treskal.com>,
"Catalin Marinas" <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH] compressed import v3
Date: Thu, 12 Jun 2008 16:32:50 -0500 [thread overview]
Message-ID: <48519602.2090103@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 889 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Karl/Catalin, et al,
Attached is my latest stab at StGit importing patches from compressed files. This
version doesn't try to differentiate by the file extension; it just tries to open
gzip or bz2 files and if those fail it reverts to text. I'm not completely happy with
it, but I've spent about as much time on it as I can afford to (for this week anyway).
Yeah, yeah, Karl, there are four new tests in t1800-import. Let me know if you think
there should be more (more for compressed input that is; I'm not crazy enough to sign
up to write more tests for *everything*). :)
Clark
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iEYEARECAAYFAkhRlgIACgkQqA4JVb61b9d2ygCfTUPc5I9eXM4947VTrTZ+mO0H
+vIAoJJACG94TdnyUIac73lB4UYCZVlG
=sa3t
-----END PGP SIGNATURE-----
[-- Attachment #2: compressed-input.patch --]
[-- Type: text/x-patch, Size: 3929 bytes --]
Patch to allow import from compressed files (gzip and bzip2)
From: Clark Williams <williams@redhat.com>
Signed-off-by: Clark Williams <williams@redhat.com>
---
stgit/commands/imprt.py | 42 ++++++++++++++++++++++++++++++++++++------
t/t1800-import.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 6 deletions(-)
diff --git a/stgit/commands/imprt.py b/stgit/commands/imprt.py
index 4a4b792..fc5cdce 100644
--- a/stgit/commands/imprt.py
+++ b/stgit/commands/imprt.py
@@ -175,14 +175,49 @@ def __create_patch(filename, message, author_name, author_email,
backup = False)
out.done()
+def __mkpatchname(name, suffix):
+ if name.lower().endswith(suffix.lower()):
+ return name[:-len(suffix)]
+ return name
+
+def __gethandleandname(filename):
+ """return a file handle and a patch name derived from filename
+ """
+ # see if it's a gzip'ed patch
+ try:
+ import gzip
+ f = gzip.open(filename)
+ f.read(1)
+ f.seek(0)
+ return (f, __mkpatchname(filename, '.gz'))
+ except IOError, e:
+ pass
+ # see if it's a bzip2'ed patch
+ try:
+ import bz2
+ f = bz2.BZ2File(filename)
+ f.read(1)
+ f.seek(0)
+ return (f, __mkpatchname(filename, '.bz2'))
+ except IOError, e:
+ pass
+ # plain old file...
+ return (open(filename), filename)
+
def __import_file(filename, options, patch = None):
"""Import a patch from a file or standard input
"""
+ pname = None
if filename:
- f = file(filename)
+ (f, pname) = __gethandleandname(filename)
else:
f = sys.stdin
+ if patch:
+ pname = patch
+ elif not pname:
+ pname = filename
+
if options.mail:
try:
msg = email.message_from_file(f)
@@ -197,11 +232,6 @@ def __import_file(filename, options, patch = None):
if filename:
f.close()
- if patch:
- pname = patch
- else:
- pname = filename
-
__create_patch(pname, message, author_name, author_email,
author_date, diff, options)
diff --git a/t/t1800-import.sh b/t/t1800-import.sh
index 8c8c9a0..1352743 100755
--- a/t/t1800-import.sh
+++ b/t/t1800-import.sh
@@ -80,4 +80,46 @@ test_expect_success \
stg delete ..
'
+test_expect_success \
+ 'Apply a bzip2 patch created with "git diff"' \
+ '
+ bzip2 -c ../t1800-import/git-diff >../t1800-import/bzip2-git-diff &&
+ stg import ../t1800-import/bzip2-git-diff &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+ rm ../t1800-import/bzip2-git-diff &&
+ stg delete ..
+ '
+test_expect_success \
+ 'Apply a bzip2 patch with a .bz2 suffix' \
+ '
+ bzip2 -c ../t1800-import/git-diff >../t1800-import/git-diff.bz2 &&
+ stg import ../t1800-import/git-diff.bz2 &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+ rm ../t1800-import/git-diff.bz2 &&
+ stg delete ..
+ '
+
+test_expect_success \
+ 'Apply a gzip patch created with GNU diff' \
+ '
+ gzip -c ../t1800-import/gnu-diff >../t1800-import/gzip-gnu-diff &&
+ stg import ../t1800-import/gzip-gnu-diff &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+ rm ../t1800-import/gzip-gnu-diff &&
+ stg delete ..
+ '
+test_expect_success \
+ 'Apply a gzip patch with a .gz suffix' \
+ '
+ gzip -c ../t1800-import/gnu-diff >../t1800-import/gnu-diff.gz &&
+ stg import ../t1800-import/gnu-diff.gz &&
+ [ $(git cat-file -p $(stg id) \
+ | grep -c "tree e96b1fba2160890ff600b675d7140d46b022b155") = 1 ] &&
+ rm ../t1800-import/gnu-diff.gz &&
+ stg delete ..
+ '
+
test_done
next reply other threads:[~2008-06-12 21:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-12 21:32 Clark Williams [this message]
2008-06-13 5:11 ` [StGit PATCH] compressed import v3 Karl Hasselström
2008-06-13 14:53 ` Clark Williams
2008-06-14 10:26 ` Karl Hasselström
2008-06-14 15:49 ` Clark Williams
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=48519602.2090103@gmail.com \
--to=clark.williams@gmail.com \
--cc=catalin.marinas@gmail.com \
--cc=git@vger.kernel.org \
--cc=kha@treskal.com \
/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).