Hi Andres,
On Mon, Dec 31, 2007 at 03:24:17AM -0500, Andres Mejia wrote:
> Please allow an option to omit importing the upstream files from a
> package and track just the debian directory. I've attached a patch
> that provides git-import-dsc with an 'omit-upstream' option that does
> this.
Thanks a lot for your patch! Making it possible to import the debian/
dir only is a good idea but then we should name it as such:
--debian-dir-only, this makes clear that modifications to directories
outside debian/ will get lost (many debian diff.gzs patch files outside
of debian/). We should also warn the user in this case, that not all of
the diff.gz got imported.
There are other issues like ending up in different directories wether an
exception was raised or not (import_without_upstream) and you can merge
ApplyDebianDiff and get rid of copy_file completely if you use a pipe.
Furthermore the docs (especially the manpages) would need some care too
and we should possible merge the git-init, git-add .,  git-commit -a
into a function since this appears in several places.
Would you give the patch another whirl? Otherwise I'll do as soon as I
find the time.
Thanks again,
 -- Guido

> 
> -- 
> Regards,
> Andres Mejia

> --- git-import-dsc.bak        2007-12-31 03:09:23.000000000 -0500
> +++ git-import-dsc    2007-12-31 03:10:01.000000000 -0500
> @@ -115,6 +115,33 @@
>      return True
>  
>  
> +def import_without_upstream(src, dirs):
> +    """
> +    Create a git repository that will hold just the debian patch
> +    """
> +    diffgz = "%s_%s-%s.diff.gz" % (src.pkg, src.upstream_version, 
> src.debian_version)
> +    diffgz_path = os.path.abspath(diffgz)
> +    os.chdir(dirs['tmp'])
> +    try:
> +        package = "%s-%s" % (src.pkg, src.upstream_version)
> +        os.mkdir(package)
> +        dirs['git'] = os.path.abspath(package)
> +        gbpc.CopyFile(diffgz_path, '.')()
> +        gbpc.GunzipDiffGz(diffgz)()
> +        diff = "%s_%s-%s.diff" % (src.pkg, src.upstream_version, 
> src.debian_version)
> +        gbpc.ApplyDebianDiff(diff)()
> +        os.chdir(dirs['git'])
> +        gbpc.GitInitDB()()
> +        gbpc.GitAdd()(['.'])
> +        gbpc.GitCommitAll()(
> +             msg="Imported debian directory only for %s version %s-%s" % 
> (src.pkg, src.upstream_version, src.debian_version))
> +    except gbpc.CommandExecFailed:
> +        print >>sys.stderr, "Creation of git repository failed"
> +        gbpc.RemoveTree(dirs['tmp'])
> +        return False
> +    return True
> +
> +
>  def apply_debian_patch(src, dirs, options, tagger, filter):
>      """apply the debian patch and tag appropriately"""
>      try:
> @@ -189,6 +216,8 @@
>                        help="Format string for upstream tags, default is 
> '%(upstream-tag)s'")
>      parser.add_config_file_option(option_name="filter", dest="filter",
>                        help="files to filter out during import")
> +    parser.add_config_file_option(option_name="omit-upstream", 
> dest="omit_upstream",
> +                      help="omit importing files from upstream", 
> action="store_true")
>      (options, args) = parser.parse_args(argv[1:])
>  
>      if options.verbose:
> @@ -206,10 +235,14 @@
>                  raise GbpError
>  
>              dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='.'))
> -            if not import_initial(src, dirs, options, gitTag, 
> options.filter):
> -                raise GbpError
> +            if options.omit_upstream:
> +                if not import_without_upstream(src, dirs):
> +                    raise GbpError
> +            else:
> +                if not import_initial(src, dirs, options, gitTag, 
> options.filter):
> +                     raise GbpError
>              os.chdir(dirs['top'])
> -            if not src.native:
> +            if not src.native and not options.omit_upstream:
>                  dirs['unpack'] = os.path.join(dirs['tmp'], 'unpack')
>                  os.mkdir(dirs['unpack'])
>                  dirs['dpkg-src'] = os.path.join(dirs['unpack'],
> --- gbp/command_wrappers.py.bak 2007-12-31 03:09:28.000000000 -0500
> +++ gbp/command_wrappers.py     2007-12-31 03:10:50.000000000 -0500
> @@ -113,6 +113,33 @@
>          self.run_error = "Couldn't extract %s" % dsc
>          Command.__call__(self, [dsc, output_dir])
> 
> +class GunzipDiffGz(Command):
> +    """
> +    Extract diff.gz to get patch file
> +    """
> +    def __init__(self, file):
> +        self.file = file
> +        Command.__init__(self, 'gunzip', [ file ])
> +        self.run_error = "Couldn't extract %s" % file
> +
> +class CopyFile(Command):
> +    """
> +    Copy a file
> +    """
> +    def __init__(self, file, dest):
> +        self.file = file
> +        self.dest = dest
> +        Command.__init__(self, 'cp', [ file, dest ])
> +        self.run_error = "Couldn't copy %s to %s" % (file, dest)
> +
> +class ApplyDebianDiff(Command):
> +    """
> +    Applies the Debian diff that's included in a non-native package
> +    """
> +    def __init__(self, diff):
> +        self.diff = diff
> +        Command.__init__(self, 'patch', [ '-p0', '-f', '-s', '-t', '-i', 
> diff ])
> +        self.run_error = "Couldn't apply Debian diff %s" % diff
> 
>  class GitCommand(Command):
>      "Mother/Father of all git commands"
> --- gbp/config.py.bak   2007-12-31 03:09:32.000000000 -0500
> +++ gbp/config.py       2007-12-31 03:10:10.000000000 -0500
> @@ -38,6 +38,7 @@
>                   'git-log'         : '--no-merges',
>                   'export-dir'      : '',
>                   'tarball-dir'     : '',
> +                 'omit-upstream'   : '',      # empty means False
>               }
>      config_files = [ '/etc/git-buildpackage/gbp.conf',
>                       os.path.expanduser('~/.gbp.conf'),




-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to