Package: git-buildpackage
Version: 0.6.31
Severity: wishlist
Tags: patch

Hello,

On the off chance you forget to clone a git repo for a debian package
with gbp-clone instead of git-clone, it would be handy to be able to
reference the local copy you already have when re-cloning the repo with
gbp-clone, in the same way that git-clone allows you to with the
--reference option.

Patch included.

Carlos

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.0.0-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages git-buildpackage depends on:
ii  devscripts            2.15.5
ii  git                   1:2.1.4-2.1
ii  man-db                2.7.0.2-5
ii  python                2.7.9-1
ii  python-dateutil       2.2-2
ii  python-pkg-resources  17.0-1
ii  python-six            1.9.0-3

Versions of packages git-buildpackage recommends:
ii  cowbuilder       0.73
ii  pristine-tar     1.33
ii  python-requests  2.7.0-3

Versions of packages git-buildpackage suggests:
ii  python-notify  0.1.1-4
ii  unzip          6.0-17

-- no debconf information
>From ab576c7d6e9358928c63c6d223ed89791a9b3d77 Mon Sep 17 00:00:00 2001
From: Carlos Maddela <[email protected]>
Date: Thu, 2 Apr 2015 03:35:06 +1100
Subject: [PATCH] Added support for referencing existing local repositories
 when cloning repositories.

---
 docs/manpages/gbp-clone.sgml | 8 ++++++++
 gbp/git/repository.py        | 5 ++++-
 gbp/scripts/clone.py         | 4 +++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/docs/manpages/gbp-clone.sgml b/docs/manpages/gbp-clone.sgml
index 20e6147..5b68158 100644
--- a/docs/manpages/gbp-clone.sgml
+++ b/docs/manpages/gbp-clone.sgml
@@ -27,6 +27,7 @@
       <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
       <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
       <arg><option>--depth=</option><replaceable>depth</replaceable></arg>
+      <arg><option>--reference=</option><replaceable>repository</replaceable></arg>
       <arg choice="plain"><replaceable>remote_uri</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -77,6 +78,13 @@
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term><option>--reference</option>=<replaceable>repository</replaceable>
+        </term>
+        <listitem>
+          <para>Local repository to use as alternate instead of re-copying data from remote repository.</para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term><option>--pristine-tar</option>
         </term>
         <listitem>
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 2fa4fdd..8142a25 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1891,7 +1891,7 @@ class GitRepository(object):
 
     @classmethod
     def clone(klass, path, remote, depth=0, recursive=False, mirror=False,
-              bare=False, auto_name=True):
+              bare=False, auto_name=True, reference=None):
         """
         Clone a git repository at I{remote} to I{path}.
 
@@ -1910,6 +1910,8 @@ class GitRepository(object):
         @param auto_name: If I{True} create a directory below I{path} based on
             the I{remote}s name. Otherwise create the repo directly at I{path}.
         @type auto_name: C{bool}
+        @param reference: create a clone using local objects from I{reference} repository
+        @type reference: C{str}
         @return: git repository object
         @rtype: L{GitRepository}
         """
@@ -1924,6 +1926,7 @@ class GitRepository(object):
         args.add_true(recursive, '--recursive')
         args.add_true(mirror, '--mirror')
         args.add_true(bare, '--bare')
+        args.add_true(reference, '--reference', reference)
         args.add(remote)
         args.add_true(name, name)
         try:
diff --git a/gbp/scripts/clone.py b/gbp/scripts/clone.py
index 1c7f4a9..216bf99 100755
--- a/gbp/scripts/clone.py
+++ b/gbp/scripts/clone.py
@@ -47,6 +47,8 @@ def build_parser(name):
     branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
     branch_group.add_option("--depth", action="store", dest="depth", default=0,
                             help="git history depth (for creating shallow clones)")
+    branch_group.add_option("--reference", action="store", dest="reference", default=None,
+                            help="git reference repository (use local copies where possible)")
 
     parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
                       help="verbose command execution")
@@ -89,7 +91,7 @@ def main(argv):
 
     try:
         repo = DebianGitRepository.clone(clone_to, source, options.depth,
-                                         auto_name=auto_name)
+                                         auto_name=auto_name,reference=options.reference)
         os.chdir(repo.path)
 
         # Reparse the config files of the cloned repository so we pick up the
-- 
2.1.4

Reply via email to