Patchwork [4,of,4] bundlerepo: basic bundle2 support

login
register
mail settings
Submitter Eric Sumner
Date Feb. 6, 2015, 7:47 p.m.
Message ID <485a3c2e0be1eebb491f.1423252054@waste.org>
Download mbox | patch
Permalink /patch/7719/
State Accepted
Commit ff5caa8dfd993680d9602ca6ebb14da9de10d5f4
Headers show

Comments

Eric Sumner - Feb. 6, 2015, 7:47 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1423250845 28800
#      Fri Feb 06 11:27:25 2015 -0800
# Node ID 485a3c2e0be1eebb491f7ca40fd64c47b29dba7f
# Parent  85768b6246cbeada0e13e8fa69ceff23a6c00286
bundlerepo: basic bundle2 support

For bundlerepo to work with bundle2 files, we need to find the part that
contains the bundle's changegroup data and work with that instead of the
entire bundle.  Future work can add separate processing for other bundle2
parts.
Eric Sumner - Feb. 6, 2015, 8:13 p.m.
These should really be tagged v2, but push gate doesn't support that yet.

  -- Eric

On 2/6/15, 11:47 AM, "Eric Sumner" <ericsumner@fb.com> wrote:

># HG changeset patch
># User Eric Sumner <ericsumner@fb.com>
># Date 1423250845 28800
>#      Fri Feb 06 11:27:25 2015 -0800
># Node ID 485a3c2e0be1eebb491f7ca40fd64c47b29dba7f
># Parent  85768b6246cbeada0e13e8fa69ceff23a6c00286
>bundlerepo: basic bundle2 support
>
>For bundlerepo to work with bundle2 files, we need to find the part that
>contains the bundle's changegroup data and work with that instead of the
>entire bundle.  Future work can add separate processing for other bundle2
>parts.
>
>diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
>--- a/mercurial/bundlerepo.py
>+++ b/mercurial/bundlerepo.py
>@@ -15,7 +15,7 @@
> from i18n import _
> import os, tempfile, shutil
> import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange
>-import localrepo, changelog, manifest, filelog, revlog, error, phases
>+import localrepo, changelog, manifest, filelog, revlog, error, phases,
>bundle2
> 
> class bundlerevlog(revlog.revlog):
>     def __init__(self, opener, indexfile, bundle, linkmapper):
>@@ -238,6 +238,24 @@
>                  
>bundlename,
>                                                                 self.vfs)
> 
>+        if isinstance(self.bundle, bundle2.unbundle20):
>+            cgparts = [part for part in self.bundle.iterparts()
>+                       if (part.type == 'b2x:changegroup')
>+                       and (part.params.get('version', '01')
>+                            in changegroup.packermap)]
>+
>+            if not cgparts:
>+                raise util.Abort('No changegroups found')
>+            version = cgparts[0].params.get('version', '01')
>+            cgparts = [p for p in cgparts
>+                       if p.params.get('version', '01') == version]
>+            if len(cgparts) > 1:
>+                raise NotImplementedError("Can't process multiple
>changegroups")
>+            part = cgparts[0]
>+
>+            part.seek(0)
>+            self.bundle = changegroup.packermap[version][1](part, 'UN')
>+
>         # dict with the mapping 'filename' -> position in the bundle
>         self.bundlefilespos = {}
> 
>diff --git a/tests/test-strip.t b/tests/test-strip.t
>--- a/tests/test-strip.t
>+++ b/tests/test-strip.t
>@@ -220,8 +220,69 @@
>   Stream params: {}
>   b2x:changegroup -- "{'version': '02'}"
>       264128213d290d868c54642d13aeaa3675551a78
>+  $ hg incoming .hg/strip-backup/*
>+  comparing with .hg/strip-backup/264128213d29-0b39d6bf-backup.hg
>+  searching for changes
>+  changeset:   4:264128213d29
>+  tag:         tip
>+  parent:      1:ef3a871183d7
>+  user:        test
>+  date:        Thu Jan 01 00:00:00 1970 +0000
>+  summary:     c
>+  
>   $ restore
>-
>+  $ hg up -C 4
>+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>+  $ hg --config experimental.bundle2-exp=True --config
>experimental.strip-bundle2-version=02 --traceback strip 4
>+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>+  saved backup bundle to
>$TESTTMP/test/.hg/strip-backup/264128213d29-0b39d6bf-backup.hg (glob)
>+  $ hg parents
>+  changeset:   1:ef3a871183d7
>+  user:        test
>+  date:        Thu Jan 01 00:00:00 1970 +0000
>+  summary:     b
>+  
>+  $ hg debugbundle .hg/strip-backup/*
>+  Stream params: {}
>+  b2x:changegroup -- "{'version': '02'}"
>+      264128213d290d868c54642d13aeaa3675551a78
>+  $ hg pull .hg/strip-backup/*
>+  pulling from .hg/strip-backup/264128213d29-0b39d6bf-backup.hg
>+  searching for changes
>+  adding changesets
>+  adding manifests
>+  adding file changes
>+  added 1 changesets with 0 changes to 0 files (+1 heads)
>+  (run 'hg heads' to see heads, 'hg merge' to merge)
>+  $ rm .hg/strip-backup/*
>+  $ hg log --graph
>+  o  changeset:   4:264128213d29
>+  |  tag:         tip
>+  |  parent:      1:ef3a871183d7
>+  |  user:        test
>+  |  date:        Thu Jan 01 00:00:00 1970 +0000
>+  |  summary:     c
>+  |
>+  | o  changeset:   3:443431ffac4f
>+  | |  user:        test
>+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
>+  | |  summary:     e
>+  | |
>+  | o  changeset:   2:65bd5f99a4a3
>+  |/   user:        test
>+  |    date:        Thu Jan 01 00:00:00 1970 +0000
>+  |    summary:     d
>+  |
>+  @  changeset:   1:ef3a871183d7
>+  |  user:        test
>+  |  date:        Thu Jan 01 00:00:00 1970 +0000
>+  |  summary:     b
>+  |
>+  o  changeset:   0:9ab35a2d17cb
>+     user:        test
>+     date:        Thu Jan 01 00:00:00 1970 +0000
>+     summary:     a
>+  
>   $ hg up -C 2
>   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>   $ hg merge 4
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel@selenic.com
>http://selenic.com/mailman/listinfo/mercurial-devel
Matt Mackall - Feb. 6, 2015, 11:07 p.m.
On Fri, 2015-02-06 at 13:47 -0600, Eric Sumner wrote:
> # HG changeset patch
> # User Eric Sumner <ericsumner@fb.com>
> # Date 1423250845 28800
> #      Fri Feb 06 11:27:25 2015 -0800
> # Node ID 485a3c2e0be1eebb491f7ca40fd64c47b29dba7f
> # Parent  85768b6246cbeada0e13e8fa69ceff23a6c00286
> bundlerepo: basic bundle2 support

These are queued for default, thanks.

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -15,7 +15,7 @@ 
 from i18n import _
 import os, tempfile, shutil
 import changegroup, util, mdiff, discovery, cmdutil, scmutil, exchange
-import localrepo, changelog, manifest, filelog, revlog, error, phases
+import localrepo, changelog, manifest, filelog, revlog, error, phases, bundle2
 
 class bundlerevlog(revlog.revlog):
     def __init__(self, opener, indexfile, bundle, linkmapper):
@@ -238,6 +238,24 @@ 
                                                                 bundlename,
                                                                 self.vfs)
 
+        if isinstance(self.bundle, bundle2.unbundle20):
+            cgparts = [part for part in self.bundle.iterparts()
+                       if (part.type == 'b2x:changegroup')
+                       and (part.params.get('version', '01')
+                            in changegroup.packermap)]
+
+            if not cgparts:
+                raise util.Abort('No changegroups found')
+            version = cgparts[0].params.get('version', '01')
+            cgparts = [p for p in cgparts
+                       if p.params.get('version', '01') == version]
+            if len(cgparts) > 1:
+                raise NotImplementedError("Can't process multiple changegroups")
+            part = cgparts[0]
+
+            part.seek(0)
+            self.bundle = changegroup.packermap[version][1](part, 'UN')
+
         # dict with the mapping 'filename' -> position in the bundle
         self.bundlefilespos = {}
 
diff --git a/tests/test-strip.t b/tests/test-strip.t
--- a/tests/test-strip.t
+++ b/tests/test-strip.t
@@ -220,8 +220,69 @@ 
   Stream params: {}
   b2x:changegroup -- "{'version': '02'}"
       264128213d290d868c54642d13aeaa3675551a78
+  $ hg incoming .hg/strip-backup/*
+  comparing with .hg/strip-backup/264128213d29-0b39d6bf-backup.hg
+  searching for changes
+  changeset:   4:264128213d29
+  tag:         tip
+  parent:      1:ef3a871183d7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     c
+  
   $ restore
-
+  $ hg up -C 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg --config experimental.bundle2-exp=True --config experimental.strip-bundle2-version=02 --traceback strip 4
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  saved backup bundle to $TESTTMP/test/.hg/strip-backup/264128213d29-0b39d6bf-backup.hg (glob)
+  $ hg parents
+  changeset:   1:ef3a871183d7
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     b
+  
+  $ hg debugbundle .hg/strip-backup/*
+  Stream params: {}
+  b2x:changegroup -- "{'version': '02'}"
+      264128213d290d868c54642d13aeaa3675551a78
+  $ hg pull .hg/strip-backup/*
+  pulling from .hg/strip-backup/264128213d29-0b39d6bf-backup.hg
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 0 changes to 0 files (+1 heads)
+  (run 'hg heads' to see heads, 'hg merge' to merge)
+  $ rm .hg/strip-backup/*
+  $ hg log --graph
+  o  changeset:   4:264128213d29
+  |  tag:         tip
+  |  parent:      1:ef3a871183d7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     c
+  |
+  | o  changeset:   3:443431ffac4f
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     e
+  | |
+  | o  changeset:   2:65bd5f99a4a3
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     d
+  |
+  @  changeset:   1:ef3a871183d7
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     b
+  |
+  o  changeset:   0:9ab35a2d17cb
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     a
+  
   $ hg up -C 2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg merge 4