diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -14,7 +14,7 @@ http://www.selenic.com/mercurial/wiki/in ''' from mercurial import util, repair, merge, cmdutil, commands, error -from mercurial import extensions, ancestor, copies +from mercurial import extensions, ancestor, copies, patch from mercurial.commands import templateopts from mercurial.node import nullrev from mercurial.i18n import _ @@ -264,6 +264,14 @@ def defineparents(repo, rev, target, sta p2 = P2n return p1, p2 +def isagitpatch(repo, patchname): + 'Return true if the given patch is in git format' + mqpatch = os.path.join(repo.mq.path, patchname) + for line in patch.linereader(file(mqpatch, 'rb')): + if line.startswith('diff --git'): + return True + return False + def updatemq(repo, state, skipped, **opts): 'Update rebased mq patches - finalize and then import them' mqrebase = {} @@ -271,7 +279,7 @@ def updatemq(repo, state, skipped, **opt if repo[p.rev].rev() in state: repo.ui.debug(_('revision %d is an mq patch (%s), finalize it.\n') % (repo[p.rev].rev(), p.name)) - mqrebase[repo[p.rev].rev()] = p.name + mqrebase[repo[p.rev].rev()] = (p.name, isagitpatch(repo, p.name)) if mqrebase: repo.mq.finish(repo, mqrebase.keys()) @@ -283,9 +291,9 @@ def updatemq(repo, state, skipped, **opt for rev in mq: if rev not in skipped: repo.ui.debug(_('import mq patch %d (%s)\n') - % (state[rev], mqrebase[rev])) - repo.mq.qimport(repo, (), patchname=mqrebase[rev], - git=opts.get('git', False),rev=[str(state[rev])]) + % (state[rev], mqrebase[rev][0])) + repo.mq.qimport(repo, (), patchname=mqrebase[rev][0], + git=mqrebase[rev][1],rev=[str(state[rev])]) repo.mq.save_dirty() def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches, diff --git a/tests/test-rebase-mq b/tests/test-rebase-mq --- a/tests/test-rebase-mq +++ b/tests/test-rebase-mq @@ -11,6 +11,7 @@ filterpatch() -e "s/^\(# Node ID\).*/\1/" \ -e "s/^\(# Parent\).*/\1/" \ -e "s/^\(diff -r \)\([a-f0-9]* \)\(-r \)\([a-f0-9]* \)/\1x \3y /" \ + -e "s/^\(diff -r \)\([a-f0-9]* \)/\1x /" \ -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/" \ -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" } @@ -74,3 +75,38 @@ cat f echo '% And the patch is correct' cat .hg/patches/f2.patch | filterpatch +echo +echo '% Adding one git-style patch and one normal' +hg qpop -a +rm -fr .hg/patches +hg qinit -c + +hg up 0 +hg qnew --git f_git.patch +echo 'mq1' > p +hg add p +hg qref --git -m 'P0 (git)' + +hg qnew f.patch +echo 'mq2' > p +hg qref -m 'P1' + +echo '% Git patch' +cat .hg/patches/f_git.patch | filterpatch + +echo +echo '% Normal patch' +cat .hg/patches/f.patch | filterpatch + +echo +echo '% Rebase the applied mq patches' +hg rebase -s 2 -d 1 --quiet 2>&1 | sed -e 's/\(saving bundle to \).*/\1/' + +echo '% And the patches are correct' +echo '% Git patch' +cat .hg/patches/f_git.patch | filterpatch + +echo +echo '% Normal patch' +cat .hg/patches/f.patch | filterpatch + diff --git a/tests/test-rebase-mq.out b/tests/test-rebase-mq.out --- a/tests/test-rebase-mq.out +++ b/tests/test-rebase-mq.out @@ -77,3 +77,58 @@ diff -r x -r y f @@ -1,1 +1,1 @@ -mq1r1 +mq1r1mq2 + +% Adding one git-style patch and one normal +patch queue now empty +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +% Git patch +P0 (git) + +diff --git a/p b/p +new file mode 100644 +--- /dev/null ++++ b/p +@@ -0,0 +1,1 @@ ++mq1 + +% Normal patch +P1 + +diff -r x p +--- a/p ++++ b/p +@@ -1,1 +1,1 @@ +-mq1 ++mq2 + +% Rebase the applied mq patches +saving bundle to +% And the patches are correct +% Git patch +# HG changeset patch +# User test +# Date +# Node ID +# Parent +P0 (git) + +diff --git a/p b/p +new file mode 100644 +--- /dev/null ++++ b/p +@@ -0,0 +1,1 @@ ++mq1 + +% Normal patch +# HG changeset patch +# User test +# Date +# Node ID +# Parent +P1 + +--- a/p ++++ b/p +@@ -1,1 +1,1 @@ +-mq1 ++mq2