[PATCH] rebase: don't fail when pulling applied patches (issue1622)

Matt Mackall mpm at selenic.com
Tue Jul 19 20:30:19 UTC 2011


On Mon, 2011-07-18 at 20:29 +0200, Stefano Tortarolo wrote:
> # HG changeset patch
> # User Stefano Tortarolo <stefano.tortarolo at gmail.com>
> # Date 1311013707 -7200
> # Node ID 4c4b1e8339c5d6d579244d7dfe15fb5991ca0885
> # Parent  647071c6dfcfc19a4dedb37c1e4c0b60378d953b
> rebase: don't fail when pulling applied patches (issue1622)
> 
> When mq patches are sent to another repo, applied and then
> pulled again, rebase fails with the error:
> "abort: cannot delete revision X above applied patches"

I don't really understand this description?

> In this situations, the only reasonable thing to do seems to be
> qfinish those patches, rebase and then try to import them
> again as mq patches. If this is not possible, it just goes on
> and prints something like:
> "revision Y cannot be imported again as mq patch"

When can this fail?

> diff --git a/hgext/rebase.py b/hgext/rebase.py
> --- a/hgext/rebase.py
> +++ b/hgext/rebase.py
> @@ -380,21 +380,30 @@
>  
>      for p in mq.applied:
>          rev = repo[p.node].rev()
> -        if rev in state:
> -            repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' %
> +        repo.ui.debug('revision %d is an mq patch (%s), finalize it.\n' %
>                                          (rev, p.name))
> -            mqrebase[rev] = (p.name, isagitpatch(repo, p.name))
> +        mqrebase[rev] = (p.name, isagitpatch(repo, p.name))
>  
>      if mqrebase:
>          mq.finish(repo, mqrebase.keys())
>  
>          # We must start import from the newest revision
>          for rev in sorted(mqrebase, reverse=True):
> -            if rev not in skipped:
> +            if rev not in skipped and rev in state:
>                  name, isgit = mqrebase[rev]
> -                repo.ui.debug('import mq patch %d (%s)\n' % (state[rev], name))
> +                repo.ui.debug('import rebased revision as mq patch %d (%s)\n'
> +                                % (state[rev], name))
>                  mq.qimport(repo, (), patchname=name, git=isgit,
>                                  rev=[str(state[rev])])
> +            if rev not in state:
> +                repo.ui.debug('trying to import mq patch (%s)\n'
> +                              % (mqrebase[rev][0]))
> +                try:
> +                    repo.mq.qimport(repo, (), patchname=mqrebase[rev][0],
> +                            git=mqrebase[rev][1],rev=[str(repo[rev])])
> +                except util.Abort:
> +                    repo.ui.warn('revision %s cannot be imported again as mq'
> +                                    ' patch\n' % (rev))
>  
>          # restore old series to preserve guards
>          mq.fullseries = original_series
> diff --git a/tests/test-rebase-mq-skip.t b/tests/test-rebase-mq-skip.t
> --- a/tests/test-rebase-mq-skip.t
> +++ b/tests/test-rebase-mq-skip.t
> @@ -12,8 +12,8 @@
>    > EOF
>  
> 
> -  $ hg init a
> -  $ cd a
> +  $ hg init base
> +  $ cd base
>    $ hg qinit -c
>  
>    $ echo c1 > c1
> @@ -47,6 +47,10 @@
>  
>    $ hg up -q -C qtip
>  
> +  $ cd ..
> +  $ cp -a base a
> +  $ cd a
> +
>    $ hg rebase
>    saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob)
>  
> @@ -134,3 +138,72 @@
>    |
>    o  0: 'r0' tags:
>    
> +  $ cd ..
> +
> +New repo, same as other before import
> +  $ hg init c
> +  $ cd c
> +  $ echo 'A'>a
> +  $ hg ci -A -d '0 0' -m 'A'
> +  adding a
> +
> +  $ echo 'B'>b
> +  $ hg add b
> +  $ hg qnew -f -d '1 0' p1.patch -m 'B'
> +
> +  $ echo 'C'>c
> +  $ hg add c
> +  $ hg qnew -f -d '2 0' p2.patch -m 'C'
> +  $ hg tglog
> +  @  2: 'C' tags: p2.patch qtip tip
> +  |
> +  o  1: 'B' tags: p1.patch qbase
> +  |
> +  o  0: 'A' tags: qparent
> +  
> +
> +Committing over an mq patch is not allowed but we can obtain a revision
> +as child of an mq patch if we pull
> +  $ cd ../
> +  $ hg clone c c2 -q -r 0
> +  $ cd c2
> +  $ echo 'B'>b
> +  $ hg add b
> +  $ hg ci -A -d '1 0' -m 'B'
> +
> +  $ echo 'D'>d
> +  $ hg ci -A -d '2 0' -m 'D'
> +  adding d
> +
> +  $ hg tglog
> +  @  2: 'D' tags: tip
> +  |
> +  o  1: 'B' tags:
> +  |
> +  o  0: 'A' tags:
> +  
> +  $ cd ../c
> +  $ hg pull -q ../c2
> +  $ hg tglog
> +  o  3: 'D' tags: tip
> +  |
> +  | @  2: 'C' tags: p2.patch qtip
> +  |/
> +  o  1: 'B' tags: p1.patch qbase
> +  |
> +  o  0: 'A' tags: qparent
> +  
> +Rebase will
> +  $ hg rebase -s 2 -d 3
> +  revision 1 cannot be imported again as mq patch
> +  saved backup bundle to $TESTTMP/c/.hg/strip-backup/*-backup.hg (glob)
> +
> +  $ hg tglog
> +  @  3: 'C' tags: p2.patch qbase qtip tip
> +  |
> +  o  2: 'D' tags: qparent
> +  |
> +  o  1: 'B' tags:
> +  |
> +  o  0: 'A' tags:
> +  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.





More information about the Mercurial-devel mailing list