aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-08-10 22:23:34 +0200
committerGuido Günther <agx@sigxcpu.org>2011-08-10 22:34:38 +0200
commit4e2f7deb43cfce3e658eec13ac60489d4f16730e (patch)
treef4ddee262998322438c303223380a00c159f792b
parentb3931e00dfc7dcbeabc24c5f717d1fe21268470f (diff)
gbp-pq: Use latest patches with --time-machine
When going back in history to find the point where the patches in debian/patches still apply make sure we use the latest ones not the one currently in the tree.
-rwxr-xr-xgbp-pq37
1 files changed, 36 insertions, 1 deletions
diff --git a/gbp-pq b/gbp-pq
index e826b8e..688fcbe 100755
--- a/gbp-pq
+++ b/gbp-pq
@@ -24,6 +24,7 @@ import os
import shutil
import subprocess
import sys
+import tempfile
from gbp.config import (GbpOptionParser, GbpOptionGroup)
from gbp.git import (GitRepositoryError, GitRepository)
from gbp.command_wrappers import (Command, GitCommand, RunAtCommand,
@@ -167,6 +168,29 @@ def get_maintainer_from_control():
return None, None
+def safe_patches(series):
+ """
+ Safe the current patches in a temporary directory
+ below .git/
+
+ @param series: path to series file
+ @return: tmpdir and path to safed series file
+ @rtype: tuple
+ """
+
+ src = os.path.dirname(series)
+ name = os.path.basename(series)
+
+ tmpdir = tempfile.mkdtemp(dir='.git/', prefix='gbp-pq')
+ patches = os.path.join(tmpdir, 'patches')
+ series = os.path.join(patches, name)
+
+ gbp.log.debug("Safeing patches '%s' in '%s'" % (src, tmpdir))
+ shutil.copytree(src, patches)
+
+ return (tmpdir, series)
+
+
def import_quilt_patches(repo, branch, series, tries):
"""
apply a series of quilt patches in the series file 'series' to branch
@@ -178,6 +202,8 @@ def import_quilt_patches(repo, branch, series, tries):
@param tries: try that many times to apply the patches going back one
commit in the branches history after each failure.
"""
+ tmpdir = None
+
if is_pq_branch(branch):
gbp.log.err("Already on a patch-queue branch '%s' - doing nothing." % branch)
raise GbpError
@@ -189,6 +215,12 @@ def import_quilt_patches(repo, branch, series, tries):
% pq_branch)
commits = repo.commits(options=['-%d' % tries], first_parent=True)
+ # If we go back in history we have to safe our pq so we always try to apply
+ # the latest one
+ if len(commits) > 1:
+ tmpdir, series = safe_patches(series)
+
+ queue = PatchQueue.read_series_file(series)
for commit in commits:
try:
gbp.log.info("Trying to apply patches at '%s'" % commit)
@@ -197,7 +229,6 @@ def import_quilt_patches(repo, branch, series, tries):
raise GbpError, ("Cannot create patch-queue branch '%s'." % pq_branch)
repo.set_branch(pq_branch)
- queue = PatchQueue.read_series_file(series)
for patch in queue:
gbp.log.debug("Applying %s" % patch.path)
try:
@@ -212,6 +243,10 @@ def import_quilt_patches(repo, branch, series, tries):
else:
raise GbpError, "Couldn't apply patches"
+ if tmpdir:
+ gbp.log.debug("Remove temporary patch safe '%s'" % tmpdir)
+ shutil.rmtree(tmpdir)
+
def get_mailinfo(patch):
"""Read patch information into a structured form"""