Hi Andres, thanks again for your patch! On Fri, Jan 04, 2008 at 02:13:35AM -0500, Andres Mejia wrote: [..snip..] > I'm not sure what you mean with the directories. I thought it would go > back to the top level directory with "os.chdir(dirs['top'])" executed > after the import-* methods. > > I took out the Gunzip and Copy methods. git-import-dsc will now use a > temporary file to store the contents of the patch and that file will You can create the temporary file with the tempfile module.
> be used with ApplyDebianDiff. I wanted to do something where it would > read the contents of the diff.gz from stdin but it seems that the '|' > character gets ignored for some reason. You can use the subprocess module (have a look at git-dch) or you can use the pipes modules (have a look at git-buildpackage) to avoid the tempfile completely. > I've also patched the appropriate documentation. Great! Would you give the patch another whirl to get rid of the tempfile? As a bonus it would be great to not always warn the user but only if the patch modifies files outside of debian/. Why do you give "-f" and "-s" in the patch options? Cheers, -- Guido > > -- > Regards, > Andres Mejia > --- git-import-dsc.bak 2007-12-31 03:09:23.000000000 -0500 > +++ git-import-dsc 2008-01-04 01:43:24.000000000 -0500 > @@ -21,6 +21,7 @@ > import re > import os > import tempfile > +import random > import glob > import gbp.command_wrappers as gbpc > from gbp.deb_utils import debian_version_chars > @@ -115,6 +116,43 @@ > return True > > > +def import_without_upstream(src, dirs): > + """ > + Create a git repository that will hold just the debian patch > + """ > + # Warn users about the potential for files outside of debian/ being > + # included in diff.gz until something gets written in git-import-dsc > + # to take care of this. > + print "Importing debian directory only." > + print "Be sure to check for directories/files that may have ended up" > + print "being included in the diff.gz patch and remove them manually." > + print "Don't forget about hidden directories/files as well." > + 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) > + # Write a temporary file to use as .diff patch and then apply it > + tempdiff = "tmp"+str(random.randrange(10000000,99999999))+".diff" > + output = os.popen('gunzip -c ' + diffgz_path, 'r') > + TEMPFILE = open(tempdiff, "w") > + TEMPFILE.write(output.read()) > + TEMPFILE.close() > + gbpc.ApplyDebianDiff(tempdiff)() > + 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 +227,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="debian-dir-only", > dest="debian_dir_only", > + help="import only the debian directory of a package", > action="store_true") > (options, args) = parser.parse_args(argv[1:]) > > if options.verbose: > @@ -206,10 +246,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.debian_dir_only: > + 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.debian_dir_only: > 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 2008-01-04 01:43:14.000000000 -0500 > @@ -113,6 +113,14 @@ > self.run_error = "Couldn't extract %s" % dsc > Command.__call__(self, [dsc, output_dir]) > > +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" > > class GitCommand(Command): > "Mother/Father of all git commands" > --- gbp/config.py.bak 2007-12-31 03:09:32.000000000 -0500 > +++ gbp/config.py 2008-01-04 01:43:07.000000000 -0500 > @@ -38,6 +38,7 @@ > 'git-log' : '--no-merges', > 'export-dir' : '', > 'tarball-dir' : '', > + 'debian-dir-only' : '', # empty means False > } > config_files = [ '/etc/git-buildpackage/gbp.conf', > os.path.expanduser('~/.gbp.conf'), > --- docs/manpages/git-import-dsc.sgml.bak 2008-01-04 01:46:04.000000000 > -0500 > +++ docs/manpages/git-import-dsc.sgml 2008-01-04 01:49:24.000000000 -0500 > @@ -29,6 +29,7 @@ > > <arg><option>--debian-tag=</option><replaceable>tag-format</replaceable></arg> > > <arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg> > <arg><option>--filter=</option><replaceable>pattern</replaceable></arg> > + <arg><option>--debian-dir-only</option></arg> > <arg choice="plain"><replaceable>debian-source.dsc</replaceable></arg> > </cmdsynopsis> > </refsynopsisdiv> > @@ -103,6 +104,12 @@ > <para>filter out these files during import</para> > </listitem> > </varlistentry> > + <varlistentry> > + <term><option>--debian-dir-only</option></term> > + <listitem> > + <para>import only the debian directory of a package</para> > + </listitem> > + </varlistentry> > </variablelist> > </refsect1> > <refsect1>