Patchwork [evolve-ext-V2] evolve: Fix crash when reading docstring

login
register
mail settings
Submitter Juntao Li
Date March 18, 2016, 12:10 a.m.
Message ID <e6922c0ce4e73df496f0.1458259845@juntaoli-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/13930/
State Accepted
Headers show

Comments

Juntao Li - March 18, 2016, 12:10 a.m.
# HG changeset patch
# User Juntao Li <juntaoli@fb.com>
# Date 1458259431 25200
#      Thu Mar 17 17:03:51 2016 -0700
# Node ID e6922c0ce4e73df496f098a947f74580e5aa6bcd
# Parent  081605c2e9b6bb4d917295aae06b8428f64d0df1
evolve: Fix crash when reading docstring

Before this patch, hg evolve --divergent could crash when looking
for docstring of function of merge.update. We were checking the
docstring to work properly with older version of Mercurial. It
could crash if an extension would wrap merge.update without
keeping the docstring. This patch fixes the crash.
Pierre-Yves David - March 19, 2016, 6:52 a.m.
On 03/17/2016 05:10 PM, Juntao Li wrote:
> # HG changeset patch
> # User Juntao Li <juntaoli@fb.com>
> # Date 1458259431 25200
> #      Thu Mar 17 17:03:51 2016 -0700
> # Node ID e6922c0ce4e73df496f098a947f74580e5aa6bcd
> # Parent  081605c2e9b6bb4d917295aae06b8428f64d0df1
> evolve: Fix crash when reading docstring

Pushed to evolve-main, thanks.

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -1997,7 +1997,14 @@ 
         hg.update(repo, divergent.rev())
     repo.ui.note(_('merging divergent changeset\n'))
     if progresscb: progresscb()
-    if 'partial' in merge.update.__doc__:
+    try:
+        stats = merge.update(repo,
+                             other.node(),
+                             branchmerge=True,
+                             force=False,
+                             ancestor=base.node(),
+                             mergeancestor=True)
+    except TypeError:
         # Mercurial  < 43c00ca887d1 (3.7)
         stats = merge.update(repo,
                              other.node(),
@@ -2006,13 +2013,6 @@ 
                              partial=None,
                              ancestor=base.node(),
                              mergeancestor=True)
-    else:
-        stats = merge.update(repo,
-                             other.node(),
-                             branchmerge=True,
-                             force=False,
-                             ancestor=base.node(),
-                             mergeancestor=True)
 
     hg._showstats(repo, stats)
     if stats[3]:
diff --git a/tests/test-divergent.t b/tests/test-divergent.t
--- a/tests/test-divergent.t
+++ b/tests/test-divergent.t
@@ -107,5 +107,53 @@ 
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   working directory is now at 6602ff5a79dc
- 
-  $ cd ..  
+
+Test None docstring issue of evolve divergent, which caused hg crush
+
+  $ hg init test2
+  $ cd test2
+  $ mkcommits _a _b
+  $ hg up "desc(_a)"
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit bdivergent1
+  created new head
+  $ hg up "desc(_a)"
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ mkcommit bdivergent2
+  created new head
+  $ hg prune -s "desc(bdivergent1)" "desc(_b)"
+  1 changesets pruned
+  $ hg prune -s "desc(bdivergent2)" "desc(_b)" --hidden
+  1 changesets pruned
+  2 new divergent changesets
+  $ hg log -G
+  @  3:e708fd28d5cf@default(draft) add bdivergent2 [divergent]
+  |
+  | o  2:c2f698071cba@default(draft) add bdivergent1 [divergent]
+  |/
+  o  0:135f39f4bd78@default(draft) add _a []
+  
+  $ cat >$TESTTMP/test_extension.py  << EOF
+  > from mercurial import merge
+  > origupdate = merge.update
+  > def newupdate(*args, **kwargs):
+  >   return origupdate(*args, **kwargs)
+  > merge.update = newupdate
+  > EOF
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > testextension=$TESTTMP/test_extension.py
+  > EOF
+  $ hg evolve --all
+  nothing to evolve on current working copy parent
+  (do you want to use --divergent)
+  [2]
+  $ hg evolve --divergent
+  merge:[3] add bdivergent2
+  with: [2] add bdivergent1
+  base: [1] add _b
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  working directory is now at aa26817f6fbe
+
+
+  $ cd ..