On Mon, Jul 30, 2007, Robert Collins wrote:
> > The current implementation is very simple (for branch in iter():
> > pull()), but there are at least two solutions to help with speed:
> > 1) (already proposed) rewrite this to reuse a transport when possible
> This is the right approach.
Okay, I gave it a shot (see attached patch), all will propose this for
inclusion in bzrtools; I filed this under Debian's bzrtools package for
now. [1]
Not sure whether the old behavior should still be made available.
[1] following the advice at https://bugs.launchpad.net/bzrtools/+filebug
--
Loïc Minier
--- bzrtools-0.18.0/debian/changelog
+++ bzrtools-0.18.0/debian/changelog
@@ -1,3 +1,11 @@
+bzrtools (0.18.0-1.1) UNRELEASED; urgency=low
+
+ * Non-maintainer upload.
+ * Group branches by URL base and reuse one transport per URL base to avoid
+ reopening a connection for each pull in multi-pull.
+
+ -- Loic Minier <[EMAIL PROTECTED]> Mon, 30 Jul 2007 12:06:43 +0200
+
bzrtools (0.18.0-1) unstable; urgency=low
[ Arnaud Fontaine ]
--- bzrtools-0.18.0.orig/__init__.py
+++ bzrtools-0.18.0/__init__.py
@@ -503,27 +503,72 @@
if not t.listable():
print "Can't list this type of location."
return 3
- for branch, wt in iter_branch_tree(t):
- if wt is None:
- pullable = branch
- else:
- pullable = wt
- parent = branch.get_parent()
- if parent is None:
- continue
- if wt is not None:
- base = wt.basedir
- else:
- base = branch.base
- if base.startswith(t.base):
- relpath = base[len(t.base):].rstrip('/')
- else:
- relpath = base
- print "Pulling %s from %s" % (relpath, parent)
- try:
- pullable.pull(Branch.open(parent))
- except Exception, e:
- print e
+ print "Grouping branches by URL"
+ by_urlbase = pullable_infos_by_urlbase(t)
+ for urlbase in by_urlbase:
+ print "Processing branches for %s/" % urlbase
+ urlbase_transport = get_transport(urlbase)
+ for pi in by_urlbase[urlbase]:
+ pullable = pi.get_pullable()
+ relpath = get_relpath(t.base, pi.get_base())
+ parent = pi.get_parent()
+ from bzrtools import bzrdir_from_transport
+ pull_transport = urlbase_transport.clone(get_relpath(urlbase, parent))
+ bzrdir = bzrdir_from_transport(pull_transport)
+ pull_branch = bzrdir.open_branch()
+ print "Pulling %s from %s" % (relpath, parent)
+ try:
+ pullable.pull(pull_branch)
+ except Exception, e:
+ print e
+
+
+def get_relpath(base, path):
+ if path.startswith(base):
+ return path[len(base):].rstrip('/')
+ else:
+ return path
+
+
+class PullableInfo:
+ def __init__(self, branch, wt):
+ self.branch = branch
+ self.wt = wt
+
+ def get_pullable(self):
+ if self.wt is None:
+ return self.branch
+ return self.wt
+
+ def get_parent(self):
+ return self.branch.get_parent()
+
+ def get_base(self):
+ if self.wt is not None:
+ return self.wt.basedir
+ return self.branch.base
+
+ def get_urlbase(self):
+ import re
+ # always matches at least the empty string
+ urlbase_pattern = re.compile("^(([^:]*://)?([^/]*))")
+ return urlbase_pattern.match(self.get_parent()).groups()[0]
+
+
+def pullable_infos_by_urlbase(t):
+ pullables_by_urlbase = {}
+ from bzrtools import iter_branch_tree
+ for branch, wt in iter_branch_tree(t):
+ parent = branch.get_parent()
+ if parent is None:
+ continue
+ pullable_info = PullableInfo(branch, wt)
+ urlbase = pullable_info.get_urlbase()
+ try:
+ pullables_by_urlbase[urlbase] += (pullable_info, )
+ except KeyError:
+ pullables_by_urlbase[urlbase] = (pullable_info, )
+ return pullables_by_urlbase
class cmd_branch_mark(bzrlib.commands.Command):
--
ubuntu-desktop mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-desktop