Package: git-buildpackage
Version: 0.4.5
Severity: normal
Tags: patch

Hi,

  To make git-buildpackage work more like the setup i use for
  {svn,bzr}-buildpackage a way is needed to let it grab the original tarball
  from another dir.

  Attached patch adds a --git-tarball-dir option to specify such an alternate
  location


  Sjoerd

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.22-2-amd64 (SMP w/4 CPU cores)
Locale: LANG=C, LC_CTYPE=nl_NL (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/bash

Versions of packages git-buildpackage depends on:
ii  devscripts                   2.10.9      Scripts to make the life of a Debi
ii  git-core                     1:1.5.3.4-1 fast, scalable, distributed revisi
ii  python                       2.4.4-6     An interactive high-level object-o
ii  python-support               0.7.4       automated rebuilding support for p

git-buildpackage recommends no packages.

-- no debconf information
commit 16687b9ef193807aaad4d596e67ee25f8677aa7c
Author: Sjoerd Simons <[EMAIL PROTECTED]>
Date:   Sun Oct 28 12:54:19 2007 +0100

    Add tarball-dir option

diff --git a/docs/manpages/git-buildpackage.sgml 
b/docs/manpages/git-buildpackage.sgml
index 473ca1e..3c257d4 100644
--- a/docs/manpages/git-buildpackage.sgml
+++ b/docs/manpages/git-buildpackage.sgml
@@ -31,6 +31,7 @@
       
<arg><option>--git-posttag=</option><replaceable>command</replaceable></arg>
       
<arg><option>--git-debian-tag=</option><replaceable>tag-format</replaceable></arg>
       <arg><option>--git-no-create-orig</option></arg>
+      
<arg><option>--git-tarball-dir=</option><replaceable>directory</replaceable></arg>
       
<arg><option>--git-export-dir=</option><replaceable>directory</replaceable></arg>
       
<arg><option>--git-export=</option><replaceable>treeish</replaceable></arg>
     </cmdsynopsis>
@@ -177,6 +178,13 @@
         </listitem>
       </varlistentry>
       <varlistentry>
+        
<term><option>--git-tarball-dir=</option><replaceable>directory</replaceable>
+        </term>
+        <listitem>
+          <para>Search original tarballs in 
<replaceable>directory</replaceable></para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>--git-export=</option><replaceable>treeish</replaceable>
         </term>
        <listitem> <para>Instead of exporting the current branch head export at
diff --git a/gbp.conf b/gbp.conf
index 57b4b44..a620ab7 100644
--- a/gbp.conf
+++ b/gbp.conf
@@ -24,6 +24,7 @@
 #posttag = git-push git.example.com
 # use this for more svn-buildpackage like bahaviour:
 #export-dir = ../build-area/
+#tarball-dir = ../tarballs/
 
 # Options only affecting git-import-orig
 [git-import-orig]
diff --git a/gbp/config.py b/gbp/config.py
index 21d5f21..bf2ca98 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -37,6 +37,7 @@ class GbpOptionParser(OptionParser):
                  'snapshot-number' : 'snapshot + 1',
                  'git-log'         : '--no-merges',
                  'export-dir'      : '',
+                 'tarball-dir'      : '',
              }
     config_files = [ '/etc/git-buildpackage/gbp.conf',
                      os.path.expanduser('~/.gbp.conf'),
diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py
index 1ae8d10..621f5e8 100644
--- a/gbp/deb_utils.py
+++ b/gbp/deb_utils.py
@@ -6,6 +6,7 @@
 import email
 import commands
 import os
+import shutil
 
 # When trying to parse a version-number from a dsc or changes file, these are
 # the valid characters.
@@ -46,4 +47,15 @@ def has_orig(cp, dir):
         return False
     return True
 
+def copy_orig(cp, orig_dir, output_dir):
+  if orig_dir == output_dir:
+    return True
+
+  try:
+    shutil.copyfile(os.path.join(orig_dir, orig_file(cp)),
+        os.path.join(output_dir, orig_file(cp)))
+  except IOError:
+    return False
+  return True
+
 # vim:et:ts=4:sw=4:
diff --git a/git-buildpackage b/git-buildpackage
index 147e98e..02e654f 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -24,7 +24,7 @@ import errno
 import pipes
 import time
 from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag)
-from gbp.deb_utils import (parse_changelog, is_native, orig_file, has_orig)
+from gbp.deb_utils import (parse_changelog, is_native, orig_file, has_orig, 
copy_orig)
 from gbp.command_wrappers import (GitTag, Command, CommandExecFailed, 
RemoveTree)
 from gbp.config import GbpOptionParser
 from gbp.errors import GbpError
@@ -132,6 +132,8 @@ def main(argv):
                       help="format string for upstream tags, default is 
'%(upstream-tag)s'")
     parser.add_config_file_option(option_name="export-dir", dest="export_dir",
                       help="before building export into EXPORT_DIR")
+    parser.add_config_file_option(option_name="tarball-dir", 
dest="tarball_dir",
+                      help="location to look for external tarballs")
     parser.add_option("--git-export", dest="treeish", default=default_tree,
                       help="export treeish object TREEISH, default is '%s'" % 
default_tree)
     (options, args) = parser.parse_args(args)
@@ -166,6 +168,11 @@ def main(argv):
             raise GbpError,"'%s' does not exist, not a debian package" % 
changelog
 
         output_dir = prepare_output_dir(options.export_dir)
+        if options.tarball_dir:
+          tarball_dir = options.tarball_dir
+        else:
+          tarball_dir = output_dir
+
         if not repo.has_treeish(options.treeish):
             raise GbpError # git-ls-tree printed an error message already
         # Export to another build dir if requested:
@@ -183,8 +190,9 @@ def main(argv):
             move_old_export(export_dir)
             os.rename(tmp_dir, export_dir)
 
+
         # Build the orig.tar.gz if necessary:
-        if not is_native(cp) and not has_orig(cp, output_dir) and not 
options.no_create_orig:
+        if not is_native(cp) and not has_orig(cp, tarball_dir) and not 
options.no_create_orig:
             # --upstream-branch was given on the command line, so use this:
             if options.upstream_branch != 
GbpOptionParser.defaults['upstream-branch']:
                 upstream_tree = options.upstream_branch
@@ -198,6 +206,11 @@ def main(argv):
                 raise GbpError # git-ls-tree printed an error message already
             if not create_orig(cp, output_dir, upstream_tree):
                 raise GbpError, "Cannot create upstream tarball at '%s'" % 
output_dir
+        else:
+          if not has_orig(cp, tarball_dir):
+            raise GbpError, "Original tarball '%s' not found" % 
os.path.join(tarball_dir, orig_file(cp))
+          if not copy_orig (cp, tarball_dir, output_dir):
+            raise GbpError, "Cannot copy upstream tarball to '%s'" % output_dir
 
         if options.export_dir:
             os.chdir(export_dir)

Reply via email to