Re: [PATCH - stgit] Patch to allow import of compressed files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2008-06-10 08:54:58 -0500, Clark Williams wrote:

> --- a/stgit/commands/imprt.py
> +++ b/stgit/commands/imprt.py
> @@ -178,8 +178,22 @@ def __create_patch(filename, message, author_name, author_email,
>  def __import_file(filename, options, patch = None):
>      """Import a patch from a file or standard input
>      """
> +    if patch:
> +        pname = patch
> +    else:
> +        pname = filename
> +
>      if filename:
> -        f = file(filename)
> +        if filename.endswith('.gz'):
> +            import gzip
> +            f = gzip.open(filename)
> +            pname = strip_suffix('.gz', filename)
> +        elif filename.endswith('.bz2'):
> +            import bz2
> +            f = bz2.BZ2File(filename)
> +            pname = strip_suffic('.bz2', filename)
                                  ^
Here's why I keep blathering about tests! In Python, you don't have a
compiler to catch these for you ...

> +        else:
> +            f = file(filename)
>      else:
>          f = sys.stdin
>  
> @@ -197,11 +211,6 @@ def __import_file(filename, options, patch = None):
>      if filename:
>          f.close()
>  
> -    if patch:
> -        pname = patch
> -    else:
> -        pname = filename
> -

I just realized a problem with this that was already present in your
first version: if patch != None, so that you set pname = patch, you
overwrite pname since you strip the .gz/.bz2 suffixes _later_.

Other than that, it looks good. But you sounded tempted to go with the
idea of just trying the decompressors rather than go by the suffix? I
think that'd be an improvement.

As for testing, you'd simply make two copies of one of the subtests in
t1800, where you test .gz- and .bz2-compressed versions of the same
patch. Should take about five minutes to write.

-- 
Karl Hasselström, kha@xxxxxxxxxxx
      www.treskal.com/kalle
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux