[Pkg-bazaar-commits] ./bzr/unstable r790: Merge from aaron:
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:21:03 UTC 2009
------------------------------------------------------------
revno: 790
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-06-27 11:36:22 +1000
message:
Merge from aaron:
------------------------------------------------------------
revno: 763
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 17:30:28 -0400
message:
Copy files in immutable stores directly.
------------------------------------------------------------
revno: 762
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 16:12:33 -0400
message:
Fixed direct call of get_url in RemoteBranch.get_revision
------------------------------------------------------------
revno: 761
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 12:00:31 -0400
message:
Added prefetch support to update_revisions
------------------------------------------------------------
revno: 760
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:57:54 -0400
message:
Added cache support to branch and pull
------------------------------------------------------------
revno: 759
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:21:37 -0400
message:
Added find_cached_branch to branch
------------------------------------------------------------
revno: 758
committer: Aaron Bentley <abentley at panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:17:10 -0400
message:
Added CachedStore type to reduce remote downloads
added:
bzrlib/meta_store.py
modified:
bzrlib/branch.py
bzrlib/commands.py
bzrlib/store.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2005-06-24 11:09:36 +0000
+++ b/bzrlib/branch.py 2005-06-27 01:36:22 +0000
@@ -45,6 +45,22 @@
return Branch(f, **args)
+def find_cached_branch(f, cache_root, **args):
+ from remotebranch import RemoteBranch
+ br = find_branch(f, **args)
+ def cacheify(br, store_name):
+ from meta_store import CachedStore
+ cache_path = os.path.join(cache_root, store_name)
+ os.mkdir(cache_path)
+ new_store = CachedStore(getattr(br, store_name), cache_path)
+ setattr(br, store_name, new_store)
+
+ if isinstance(br, RemoteBranch):
+ cacheify(br, 'inventory_store')
+ cacheify(br, 'text_store')
+ cacheify(br, 'revision_store')
+ return br
+
def _relpath(base, path):
"""Return path relative to base, or raise exception.
@@ -752,6 +768,14 @@
pb.update('comparing histories')
revision_ids = self.missing_revisions(other, stop_revision)
+
+ if hasattr(other.revision_store, "prefetch"):
+ other.revision_store.prefetch(revision_ids)
+ if hasattr(other.inventory_store, "prefetch"):
+ inventory_ids = [other.get_revision(r).inventory_id
+ for r in revision_ids]
+ other.inventory_store.prefetch(inventory_ids)
+
revisions = []
needed_texts = sets.Set()
i = 0
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-06-27 01:27:02 +0000
+++ b/bzrlib/commands.py 2005-06-27 01:36:22 +0000
@@ -469,6 +469,8 @@
def run(self, location=None):
from bzrlib.merge import merge
+ import tempfile
+ from shutil import rmtree
import errno
br_to = Branch('.')
@@ -484,18 +486,23 @@
else:
print "Using last location: %s" % stored_loc
location = stored_loc
- from branch import find_branch, DivergedBranches
- br_from = find_branch(location)
- location = pull_loc(br_from)
- old_revno = br_to.revno()
+ cache_root = tempfile.mkdtemp()
try:
- br_to.update_revisions(br_from)
- except DivergedBranches:
- raise BzrCommandError("These branches have diverged. Try merge.")
-
- merge(('.', -1), ('.', old_revno), check_clean=False)
- if location != stored_loc:
- br_to.controlfile("x-pull", "wb").write(location + "\n")
+ from branch import find_cached_branch, DivergedBranches
+ br_from = find_cached_branch(location, cache_root)
+ location = pull_loc(br_from)
+ old_revno = br_to.revno()
+ try:
+ br_to.update_revisions(br_from)
+ except DivergedBranches:
+ raise BzrCommandError("These branches have diverged."
+ " Try merge.")
+
+ merge(('.', -1), ('.', old_revno), check_clean=False)
+ if location != stored_loc:
+ br_to.controlfile("x-pull", "wb").write(location + "\n")
+ finally:
+ rmtree(cache_root)
@@ -514,44 +521,50 @@
def run(self, from_location, to_location=None, revision=None):
import errno
from bzrlib.merge import merge
- from branch import find_branch, DivergedBranches, NoSuchRevision
+ from branch import find_cached_branch, DivergedBranches, NoSuchRevision
from shutil import rmtree
- try:
- br_from = find_branch(from_location)
- except OSError, e:
- if e.errno == errno.ENOENT:
- raise BzrCommandError('Source location "%s" does not exist.' %
- to_location)
- else:
- raise
-
- if to_location is None:
- to_location = os.path.basename(from_location.rstrip("/\\"))
-
- try:
- os.mkdir(to_location)
- except OSError, e:
- if e.errno == errno.EEXIST:
- raise BzrCommandError('Target directory "%s" already exists.' %
- to_location)
- if e.errno == errno.ENOENT:
- raise BzrCommandError('Parent of "%s" does not exist.' %
- to_location)
- else:
- raise
- br_to = Branch(to_location, init=True)
-
- try:
- br_to.update_revisions(br_from, stop_revision=revision)
- except NoSuchRevision:
- rmtree(to_location)
- msg = "The branch %s has no revision %d." % (from_location,
- revision)
- raise BzrCommandError(msg)
- merge((to_location, -1), (to_location, 0), this_dir=to_location,
- check_clean=False, ignore_zero=True)
- from_location = pull_loc(br_from)
- br_to.controlfile("x-pull", "wb").write(from_location + "\n")
+ from meta_store import CachedStore
+ import tempfile
+ cache_root = tempfile.mkdtemp()
+ try:
+ try:
+ br_from = find_cached_branch(from_location, cache_root)
+ except OSError, e:
+ if e.errno == errno.ENOENT:
+ raise BzrCommandError('Source location "%s" does not'
+ ' exist.' % to_location)
+ else:
+ raise
+
+ if to_location is None:
+ to_location = os.path.basename(from_location.rstrip("/\\"))
+
+ try:
+ os.mkdir(to_location)
+ except OSError, e:
+ if e.errno == errno.EEXIST:
+ raise BzrCommandError('Target directory "%s" already'
+ ' exists.' % to_location)
+ if e.errno == errno.ENOENT:
+ raise BzrCommandError('Parent of "%s" does not exist.' %
+ to_location)
+ else:
+ raise
+ br_to = Branch(to_location, init=True)
+
+ try:
+ br_to.update_revisions(br_from, stop_revision=revision)
+ except NoSuchRevision:
+ rmtree(to_location)
+ msg = "The branch %s has no revision %d." % (from_location,
+ revision)
+ raise BzrCommandError(msg)
+ merge((to_location, -1), (to_location, 0), this_dir=to_location,
+ check_clean=False, ignore_zero=True)
+ from_location = pull_loc(br_from)
+ br_to.controlfile("x-pull", "wb").write(from_location + "\n")
+ finally:
+ rmtree(cache_root)
def pull_loc(branch):
=== added file 'bzrlib/meta_store.py'
--- a/bzrlib/meta_store.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/meta_store.py 2005-06-27 01:36:22 +0000
@@ -0,0 +1,41 @@
+# Copyright (C) 2005 by Canonical Ltd
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from trace import mutter
+from bzrlib.store import ImmutableStore
+
+class CachedStore:
+ """A store that caches data locally, to avoid repeated downloads.
+ The precacache method should be used to avoid server round-trips for
+ every piece of data.
+ """
+ def __init__(self, store, cache_dir):
+ self.source_store = store
+ self.cache_store = ImmutableStore(cache_dir)
+
+ def __getitem__(self, id):
+ mutter("Cache add %s" % id)
+ if id not in self.cache_store:
+ self.cache_store.add(self.source_store[id], id)
+ return self.cache_store[id]
+
+ def prefetch(self, ids):
+ """Copy a series of ids into the cache, before they are used.
+ For remote stores that support pipelining or async downloads, this can
+ increase speed considerably.
+ """
+ mutter("Prefetch of ids %s" % ",".join(ids))
+ self.cache_store.copy_multi(self.source_store, ids)
=== modified file 'bzrlib/store.py'
--- a/bzrlib/store.py 2005-06-20 04:33:23 +0000
+++ b/bzrlib/store.py 2005-06-27 01:36:22 +0000
@@ -119,6 +119,8 @@
pb = ProgressBar()
pb.update('preparing to copy')
to_copy = [id for id in ids if id not in self]
+ if isinstance(other, ImmutableStore):
+ return self.copy_multi_immutable(other, to_copy, pb)
count = 0
for id in to_copy:
count += 1
@@ -127,6 +129,27 @@
assert count == len(to_copy)
pb.clear()
return count
+
+
+ def copy_multi_immutable(self, other, to_copy, pb):
+ from shutil import copyfile
+ count = 0
+ for id in to_copy:
+ p = self._path(id)
+ other_p = other._path(id)
+ try:
+ copyfile(other_p, p)
+ except IOError, e:
+ if e.errno == errno.ENOENT:
+ copyfile(other_p+".gz", p+".gz")
+ else:
+ raise
+
+ count += 1
+ pb.update('copy', count, len(to_copy))
+ assert count == len(to_copy)
+ pb.clear()
+ return count
def __contains__(self, fileid):
More information about the Pkg-bazaar-commits
mailing list