Patchwork [2,of,2] unbundle: Support bundle2 files

login
register
mail settings
Submitter Eric Sumner
Date Jan. 16, 2015, 8:20 p.m.
Message ID <e330ca1592577409465f.1421439657@dev911.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7493/
State Superseded
Commit 5827ad0b849e3757c876e9f034846b1aba37ba88
Headers show

Comments

Eric Sumner - Jan. 16, 2015, 8:20 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1421284195 28800
#      Wed Jan 14 17:09:55 2015 -0800
# Node ID e330ca1592577409465f1b238b9b2ce689ba55e9
# Parent  e07587a186a859fdb065b9475afd0470e2ae4508
unbundle: Support bundle2 files

This adds support for bundle2 files to the unbundle command.  The modheads code
is complicated by the odd return values from addchangegroup (0 => no change,
1 => no new heads, +/-2 => 1 more/fewer heads, etc)
Pierre-Yves David - Jan. 16, 2015, 8:24 p.m.
On 01/16/2015 12:20 PM, Eric Sumner wrote:
> # HG changeset patch
> # User Eric Sumner <ericsumner@fb.com>
> # Date 1421284195 28800
> #      Wed Jan 14 17:09:55 2015 -0800
> # Node ID e330ca1592577409465f1b238b9b2ce689ba55e9
> # Parent  e07587a186a859fdb065b9475afd0470e2ae4508
> unbundle: Support bundle2 files
>
> This adds support for bundle2 files to the unbundle command.  The modheads code
> is complicated by the odd return values from addchangegroup (0 => no change,
> 1 => no new heads, +/-2 => 1 more/fewer heads, etc)
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -6143,8 +6143,33 @@
>           for fname in fnames:
>               f = hg.openpath(ui, fname)
>               gen = exchange.readbundle(ui, f, fname)
> -            modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
> -                                                  'bundle:' + fname)
> +            if isinstance(gen, bundle2.unbundle20):
> +                tr = repo.transaction('unbundle')
> +                try:
> +                    op = bundle2.processbundle(repo, gen, lambda: tr)
> +                    tr.close()
> +                finally:
> +                    if tr:
> +                        tr.release()
> +                modheads = 0
> +                changes = False
> +                for r in op.records['changegroup']:
> +                    result = r.get('result', 0)
> +                    if result > 1:
> +                        changes = True
> +                        modheads += result - 1
> +                    elif result < -1:
> +                        changes = True
> +                        modheads += result + 1
> +                    elif result == 1:
> +                        changes = True
> +                if changes and modheads >= 0:
> +                    modheads += 1
> +                elif changes:
> +                    modheads -= 1

There is already an implementation of this in exchange.py, can you check 
it for factorisation?
Eric Sumner - Jan. 16, 2015, 8:31 p.m.
On 1/16/15, 12:24 PM, "Pierre-Yves David" <pierre-yves.david@ens-lyon.org>
wrote:
>
>There is already an implementation of this in exchange.py, can you check
>it for factorisation?

Looks like they should be the same; I¹ll send a v2

  ‹ Eric
>
>-- 
>Pierre-Yves David

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6143,8 +6143,33 @@ 
         for fname in fnames:
             f = hg.openpath(ui, fname)
             gen = exchange.readbundle(ui, f, fname)
-            modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
-                                                  'bundle:' + fname)
+            if isinstance(gen, bundle2.unbundle20):
+                tr = repo.transaction('unbundle')
+                try:
+                    op = bundle2.processbundle(repo, gen, lambda: tr)
+                    tr.close()
+                finally:
+                    if tr:
+                        tr.release()
+                modheads = 0
+                changes = False
+                for r in op.records['changegroup']:
+                    result = r.get('result', 0)
+                    if result > 1:
+                        changes = True
+                        modheads += result - 1
+                    elif result < -1:
+                        changes = True
+                        modheads += result + 1
+                    elif result == 1:
+                        changes = True
+                if changes and modheads >= 0:
+                    modheads += 1
+                elif changes:
+                    modheads -= 1
+            else:
+                modheads = changegroup.addchangegroup(repo, gen, 'unbundle',
+                                                      'bundle:' + fname)
     finally:
         lock.release()
 
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -762,13 +762,11 @@ 
       9520eea781bcca16c1e15acc0ba14335a0e8e5ba
       eea13746799a9e0bfd88f29d3c2e9dc9389f524f
       02de42196ebee42ef284b6780a87cdc96e8eaab6
-  $ hg unbundle2 < ../rev.hg2
+  $ hg unbundle ../rev.hg2
   adding changesets
   adding manifests
   adding file changes
   added 0 changesets with 0 changes to 3 files
-  0 unread bytes
-  addchangegroup return: 1
 
 with reply