Re: [PATCH - stgit] Patch to allow import of compressed files
From: Asheesh Laroia <hidden>
Date: 2016-06-15 22:44:43
On Tue, 10 Jun 2008, Karl Hasselström wrote:
On 2008-06-09 13:38:55 -0500, Clark Williams wrote:quoted
This patch allows StGit to directly import compressed (.gz and .bz2) files with reasonable patch names. I do a lot of work on modified kernel trees and usually the first two things imported are a stable update patch followed immediately by an -rt patch, both of which are compressed. With this patch I can just copy the files down directly from kernel.org and import them, rather than having to keep uncompressed copies around. Hey, I'm lazy... :)Lazy is good. Thanks for the patch!quoted
+ if filename.endswith(".gz"): + import gzip + f = gzip.open(filename) + pname = filename.replace(".gz", "") + elif filename.endswith(".bz2"): + import bz2 + f = bz2.BZ2File(filename, 'r') + pname = filename.replace(".bz2", "")Some comments here: * By my reading of the docs, the second argument to BZ2File defaults to 'r' anyway, so you could omit it.
Peanut gallery question: Why not just always try these methods and catch some format exception if they fail, proceeding to the next possible decompressor (proceeding on to no decompressor)? That way if a file is called .GZ, it will still be handled properly; in fact, all files would still be handled properly. And these formats leave notes in the first few bytes of the file as to if they should be tried, so it's not as if it would come at some performance cost. -- Asheesh. -- Say "twenty-three-skiddoo" to logout.