Patchwork [1,of,2] changegroup.writebundle: provide ui

login
register
mail settings
Submitter Eric Sumner
Date Jan. 16, 2015, 11:10 p.m.
Message ID <4f8446060b6df2a787ba.1421449822@dev911.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7500/
State Superseded
Headers show

Comments

Eric Sumner - Jan. 16, 2015, 11:10 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1421361581 28800
#      Thu Jan 15 14:39:41 2015 -0800
# Node ID 4f8446060b6df2a787baa3df70ed2e208fb49437
# Parent  55f663bdf6b3e045898789f64e5e878bcaaddf1b
changegroup.writebundle: provide ui

The next diff will add support for writing bundle2 files to writebundle, but
the bundle2 generator wants access to a ui object.  This changes the signature
and callsites to pass one in.
Pierre-Yves David - Jan. 16, 2015, 11:30 p.m.
On 01/16/2015 03:10 PM, Eric Sumner wrote:
> --- a/mercurial/changegroup.py
> +++ b/mercurial/changegroup.py
> @@ -79,7 +79,7 @@
>   # hgweb uses this list to communicate its preferred type
>   bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
>
> -def writebundle(cg, filename, bundletype, vfs=None):
> +def writebundle(cg, filename, bundletype, vfs=None, ui=None):
>       """Write a bundle file and return its filename.
>
>       Existing files will not be overwritten.
> @@ -88,6 +88,8 @@
>       The bundle file will be deleted in case of errors.
>       """
>
> +    if ui is None:
> +        raise ValueError(_('ui parameter is required'))

This part is strange. After discussion with eric in real life. he will 
more ui as the first parameter and make it required.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -43,6 +43,7 @@ 
         self.repo = repo
         self.name = name
         self.vfs = scmutil.vfs(repo.join('shelved'))
+        self.ui = self.repo.ui
         if filetype:
             self.fname = name + '.' + filetype
         else:
@@ -82,7 +83,7 @@ 
         return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root,
                                            self.vfs.join(self.fname))
     def writebundle(self, cg):
-        changegroup.writebundle(cg, self.fname, 'HG10UN', self.vfs)
+        changegroup.writebundle(cg, self.fname, 'HG10UN', self.vfs, ui=self.ui)
 
 class shelvedstate(object):
     """Handle persistence during unshelving operations.
diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -410,7 +410,8 @@ 
         else:
             cg = other.changegroupsubset(incoming, rheads, 'incoming')
         bundletype = localrepo and "HG10BZ" or "HG10UN"
-        fname = bundle = changegroup.writebundle(cg, bundlename, bundletype)
+        fname = bundle = changegroup.writebundle(cg, bundlename, bundletype,
+                                                 ui=ui)
         # keep written bundle?
         if bundlename:
             bundle = None
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -79,7 +79,7 @@ 
 # hgweb uses this list to communicate its preferred type
 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
 
-def writebundle(cg, filename, bundletype, vfs=None):
+def writebundle(cg, filename, bundletype, vfs=None, ui=None):
     """Write a bundle file and return its filename.
 
     Existing files will not be overwritten.
@@ -88,6 +88,8 @@ 
     The bundle file will be deleted in case of errors.
     """
 
+    if ui is None:
+        raise ValueError(_('ui parameter is required'))
     fh = None
     cleanup = None
     try:
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1218,7 +1218,7 @@ 
         scmutil.nochangesfound(ui, repo, outgoing and outgoing.excluded)
         return 1
 
-    changegroup.writebundle(cg, fname, bundletype)
+    changegroup.writebundle(cg, fname, bundletype, ui=ui)
 
 @command('cat',
     [('o', 'output', '',
@@ -2166,7 +2166,7 @@ 
     bundletype = btypes.get(bundletype)
     if bundletype not in changegroup.bundletypes:
         raise util.Abort(_('unknown bundle type specified with --type'))
-    changegroup.writebundle(bundle, bundlepath, bundletype)
+    changegroup.writebundle(bundle, bundlepath, bundletype, ui=ui)
 
 @command('debugignore', [], '')
 def debugignore(ui, repo, *values, **opts):
diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -193,7 +193,7 @@ 
                 type = x
                 break
 
-        tempname = changegroup.writebundle(cg, None, type)
+        tempname = changegroup.writebundle(cg, None, type, ui=self.ui)
         fp = httpconnection.httpsendfile(self.ui, tempname, "rb")
         headers = {'Content-Type': 'application/mercurial-0.1'}
 
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -31,7 +31,7 @@ 
         bundletype = "HG10BZ"
     else:
         bundletype = "HG10UN"
-    return changegroup.writebundle(cg, name, bundletype, vfs)
+    return changegroup.writebundle(cg, name, bundletype, vfs, ui=repo.ui)
 
 def _collectfiles(repo, striprev):
     """find out the filelogs affected by the strip"""