Ok, here's my revised patch. On Jan 3, 2008 4:58 AM, Guido Guenther <[EMAIL PROTECTED]> wrote: > 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.
I've done the proper modification for the option and added an info message. > 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 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 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. I've also patched the appropriate documentation. -- 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>