Issue2100

Title rebase --collapse fails with --keepbranches
Priority bug Status resolved
Superseder Nosy List astratto, brendan, gward, mtomilov, pmezard
Assigned To Topics rebase

Created on 2010-03-18.05:19:45 by mtomilov, last changed 2010-07-23.18:17:23 by mpm.

Messages
msg12160 (view) Author: pmezard Date: 2010-03-23.22:15:29
@gward: moved to issue2112
msg12158 (view) Author: pmezard Date: 2010-03-23.22:01:06
Fix in crew-stable: http://hg.intevation.org/mercurial/crew/rev/129e96f7a87a

@gward: I pushed my fix because the issue you are raising was already there.
It probably deserves an issue on its own.
msg12157 (view) Author: brendan Date: 2010-03-23.22:00:09
See http://hg.intevation.org/mercurial/crew/rev/129e96f7a87a
(rebase: fix --collapse with --keepbranches (issue2100))
msg12142 (view) Author: gward Date: 2010-03-23.13:52:19
@pmezard: please the patch I posted to mercurial-devel yesterday 
(http://www.selenic.com/pipermail/mercurial-devel/2010-March/019799.html).  
I added test code that does not merely crash, but tests that --collapse and 
--keepbranches do the right thing together.

Also, the kludgy fix that I posted addresses one concern that I don't see in 
your fix: what if someone tries to rebase --collapse --keepbranch where the 
source changesets are not all on the same named branch?  I think the only 
option there is to abort, because it's not possible to fulfill the user's 
wish.

(That said, your fix is definitely better.  Maybe we should combine your fix 
with my tests and then worry about the multiple-branches thing later.)
msg12129 (view) Author: astratto Date: 2010-03-23.09:45:06
The general idea behind 38fe86fb16e3 was to facilitate interoperability, but
most of all to simplify the way we could extend rebase and fix their bugs.

So, your idea sounds reasonable to me. Go ahead please.
msg12127 (view) Author: pmezard Date: 2010-03-23.09:27:06
@astratto: this is a refactoring bug: the extrafn argument was pulled
outside concludenode() but the extra logic was not duplicated. Here is a
conservative patch fixing the issue by duplicating this logic. Still, if the
extrafn argument was not removed for API reason and nobody calls
concludenode() except rebase extension, I'd like to move it back to
concludenode()

What do you think?


# HG changeset patch
# User Patrick Mezard <pmezard@gmail.com>
# Date 1269336196 -3600
# Branch stable
# Node ID 1ff1c2574fbc3c5fdd3e75cccc6b2618ef5453b5
# Parent  32023a0a389b19da430281d6d9c3a370a5d2ebda
rebase: fix --collapse with --keepbranches (issue2100)

This was broken in 38fe86fb16e3. I was tempted to move the extrafn call back
into concludenode() but I had the feeling 38fe86fb16e3 and its successors were
introduced to facilitate interoperability with thg and other projects, so I was
reluctant to change concludenode() signature again. I will leave it to
knowledgeable people.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -189,8 +189,12 @@
                 if rebased not in skipped and state[rebased] != nullmerge:
                     commitmsg += '\n* %s' % repo[rebased].description()
             commitmsg = ui.edit(commitmsg, repo.ui.username())
+            # TODO: The 'extra' business should not be duplicated
+            extra = {'rebase_source': repo[rev].hex()}
+            if extrafn:
+                extrafn(repo[rev], extra)
             newrev = concludenode(repo, rev, p1, external, commitmsg=commitmsg,
-                                                    extra=extrafn)
+                                  extra=extra)
 
         if 'qtip' in repo.tags():
             updatemq(repo, state, skipped, **opts)
diff --git a/tests/test-rebase-collapse b/tests/test-rebase-collapse
--- a/tests/test-rebase-collapse
+++ b/tests/test-rebase-collapse
@@ -43,7 +43,7 @@
 hg glog  --template '{rev}: {desc}\n'
 echo '% Rebasing B onto H'
 hg up -C 3
-hg rebase --collapse 2>&1 | sed 's/\(saving bundle to \).*/\1/'
+hg rebase --collapse --keepbranches 2>&1 | sed 's/\(saving bundle to \).*/\1/'
 hg glog  --template '{rev}: {desc}\n'
 echo "Expected A, B, C, D, F, H"
 hg manifest
msg12126 (view) Author: pmezard Date: 2010-03-23.09:24:57
Adding Stephano to noisy list
msg12120 (view) Author: gward Date: 2010-03-22.21:48:42
This is nothing to do with copies: it's an interaction between --collapse
and --keepbranches.  (That is, they interact badly.)

Here's a slightly simpler reproduction:

  hg init .
  touch a
  hg ci -A -minit
  hg branch test
  touch b
  hg ci -A -m"on branch"
  hg up default
  echo a >> a
  hg ci -m "change on default"
  hg up test

At this point the graph is:

o  changeset:   2:c03f5c9a01d3
|  tag:         tip
|  parent:      0:2c4aa810efdb
|  user:        Greg Ward <gward@...>
|  date:        Mon Mar 22 17:43:18 2010 -0400
|  summary:     change on default
|
| @  changeset:   1:ed1ed8ec9919
|/   branch:      test
|    user:        Greg Ward <gward@...>
|    date:        Mon Mar 22 17:43:05 2010 -0400
|    summary:     on branch
|
o  changeset:   0:2c4aa810efdb
   user:        Greg Ward <gward@...>
   date:        Mon Mar 22 17:42:48 2010 -0400
   summary:     init

And rebase fails as described by mtomilov:

hg rebase -d 2 --keepbranches --collapse
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Mercurial Distributed SCM (version 1.5)
** Extensions loaded: rebase
Traceback (most recent call last):
  File "/home/gward/bin/hgs", line 27, in <module>
    mercurial.dispatch.run()
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 16, in run
    sys.exit(dispatch(sys.argv[1:]))
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 30, in
dispatch
    return _runcatch(u, args)
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 47, in
_runcatch
    return _dispatch(ui, args)
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 466, in
_dispatch
    return runcommand(lui, repo, cmd, fullargs, ui, options, d)
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 336, in
runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 517, in
_runcommand
    return checkargs()
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 471, in
checkargs
    return cmdfunc()
  File "/home/gward/src/hg-crew-stable/mercurial/dispatch.py", line 465, in
<lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/home/gward/src/hg-crew-stable/mercurial/util.py", line 401, in check
    return func(*args, **kwargs)
  File "/home/gward/src/hg-crew-stable/hgext/rebase.py", line 162, in rebase
    extra=extrafn)
  File "/home/gward/src/hg-crew-stable/hgext/rebase.py", line 248, in
concludenode
    date=repo[rev].date(), extra=extra)
  File "/home/gward/src/hg-crew-stable/mercurial/localrepo.py", line 822, in
commit
    if (not force and not extra.get("close") and p2 == nullid
AttributeError: 'function' object has no attribute 'get'

I get pretty much the same stack trace with current crew or current crew-stable.
msg12119 (view) Author: gward Date: 2010-03-22.21:34:43
This looks like a bug in the --collapse option to rebase.  I don't think
this option makes any difference when rebasing a single changeset, so a
possible workaround here is simply to not run with --collapse.  (Assuming
your real-world scenario is only rebasing a single changeset, *or* you don't
need to collapse multiple changesets.)
msg12070 (view) Author: mtomilov Date: 2010-03-18.05:19:45
Ubuntu Karmic, Mercurial 1.5, Python 2.6.4

bullet@bullet-laptop:~/workshop/test/hg$ mkdir bug
bullet@bullet-laptop:~/workshop/test/hg$ cd bug
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg init .
bullet@bullet-laptop:~/workshop/test/hg/bug$ touch 1 2
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg add 1 2
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg ci -m "initial import"
1
2
committed changeset 0:c267aaf73db7
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg branch test_branch
marked working directory as branch test_branch
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg cp 1 3
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg ci -m "added 3"
3
committed changeset 1:cd463e8be06d
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg up default
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
bullet@bullet-laptop:~/workshop/test/hg/bug$ echo test >> 1
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg ci -m "default is changed"
1
created new head
committed changeset 2:f3267ed415c4
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg up test_branch
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
bullet@bullet-laptop:~/workshop/test/hg/bug$ hg glog
o  changeset:   2:f3267ed415c4
|  tag:         tip
|  parent:      0:c267aaf73db7
|  user:        Max Tomilov <mtomilov@altibase.com>
|  date:        Thu Mar 18 14:15:07 2010 +0900
|  summary:     default is changed
|
| @  changeset:   1:cd463e8be06d
|/   branch:      test_branch
|    user:        Max Tomilov <mtomilov@altibase.com>
|    date:        Thu Mar 18 14:14:50 2010 +0900
|    summary:     added 3
|
o  changeset:   0:c267aaf73db7
   user:        Max Tomilov <mtomilov@altibase.com>
   date:        Thu Mar 18 14:14:34 2010 +0900
   summary:     initial import

bullet@bullet-laptop:~/workshop/test/hg/bug$ hg parents
changeset:   1:cd463e8be06d
branch:      test_branch
user:        Max Tomilov <mtomilov@altibase.com>
date:        Thu Mar 18 14:14:50 2010 +0900
summary:     added 3

bullet@bullet-laptop:~/workshop/test/hg/bug$ hg rebase -d 2 --keepbranches -
-collapse
merging 1 and 3 to 3
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Mercurial Distributed SCM (version 1.5)
** Extensions loaded: graphlog, rebase, churn, transplant, patchbomb
Traceback (most recent call last):
  File "/usr/bin/hg", line 27, in <module>
    mercurial.dispatch.run()
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 16, in run
    sys.exit(dispatch(sys.argv[1:]))
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 30, in 
dispatch
    return _runcatch(u, args)
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 47, in 
_runcatch
    return _dispatch(ui, args)
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 466, in 
_dispatch
    return runcommand(lui, repo, cmd, fullargs, ui, options, d)
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 336, in 
runcommand
    ret = _runcommand(ui, options, cmd, d)
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 517, in 
_runcommand
    return checkargs()
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 471, in 
checkargs
    return cmdfunc()
  File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 465, in 
<lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/usr/lib/pymodules/python2.6/mercurial/util.py", line 401, in check
    return func(*args, **kwargs)
  File "/usr/lib/pymodules/python2.6/hgext/rebase.py", line 162, in rebase
    extra=extrafn)
  File "/usr/lib/pymodules/python2.6/hgext/rebase.py", line 248, in 
concludenode
    date=repo[rev].date(), extra=extra)
  File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 822, in 
commit
    if (not force and not extra.get("close") and p2 == nullid
AttributeError: 'function' object has no attribute 'get'
bullet@bullet-laptop:~/workshop/test/hg/bug$
History
Date User Action Args
2010-07-23 18:17:23mpmsetstatus: testing -> resolved
nosy: brendan, pmezard, astratto, gward, mtomilov
2010-03-23 22:15:29pmezardsetnosy: brendan, pmezard, astratto, gward, mtomilov
messages: + msg12160
2010-03-23 22:01:06pmezardsetstatus: chatting -> testing
nosy: brendan, pmezard, astratto, gward, mtomilov
messages: + msg12158
2010-03-23 22:00:09brendansetnosy: + brendan
messages: + msg12157
2010-03-23 13:52:19gwardsetnosy: pmezard, astratto, gward, mtomilov
messages: + msg12142
2010-03-23 09:45:06astrattosetnosy: pmezard, astratto, gward, mtomilov
messages: + msg12129
2010-03-23 09:27:06pmezardsetnosy: pmezard, astratto, gward, mtomilov
messages: + msg12127
2010-03-23 09:24:57pmezardsettopic: + rebase
nosy: + astratto, pmezard
messages: + msg12126
2010-03-22 21:48:42gwardsetnosy: gward, mtomilov
messages: + msg12120
title: rebase --collapse fails if one file is copied -> rebase --collapse fails with --keepbranches
2010-03-22 21:34:43gwardsetstatus: unread -> chatting
nosy: + gward
messages: + msg12119
title: rebase failed if one of file is copied -> rebase --collapse fails if one file is copied
2010-03-18 10:19:21djcsetpriority: urgent -> bug
2010-03-18 05:19:45mtomilovcreate