Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a depth argument to ControlDir.sprout() and Repository.fetch(). #201

Open
wants to merge 13 commits into
base: 3.3
Choose a base branch
from
13 changes: 9 additions & 4 deletions breezy/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,18 +680,20 @@ def set_append_revisions_only(self, enabled: bool) -> None:
raise errors.UpgradeRequired(self.user_url)
self.get_config_stack().set('append_revisions_only', enabled)

def fetch(self, from_branch, stop_revision=None, limit=None, lossy=False):
def fetch(self, from_branch, stop_revision=None, limit=None, lossy=False,
depth=None):
"""Copy revisions from from_branch into this branch.

:param from_branch: Where to copy from.
:param stop_revision: What revision to stop at (None for at the end
of the branch.
:param limit: Optional rough limit of revisions to fetch
:param depth: Revision depth
:return: None
"""
with self.lock_write():
return InterBranch.get(from_branch, self).fetch(
stop_revision, limit=limit, lossy=lossy)
stop_revision, limit=limit, lossy=lossy, depth=depth)

def get_bound_location(self):
"""Return the URL of the branch we are bound to.
Expand Down Expand Up @@ -2105,11 +2107,12 @@ def copy_content_into(self, revision_id=None, tag_selector=None):
"""
raise NotImplementedError(self.copy_content_into)

def fetch(self, stop_revision=None, limit=None, lossy=False):
def fetch(self, stop_revision=None, limit=None, lossy=False, depth=None):
"""Fetch revisions.

:param stop_revision: Last revision to fetch
:param limit: Optional rough limit of revisions to fetch
:param depth: Optional revision depth
:return: FetchResult object
"""
raise NotImplementedError(self.fetch)
Expand Down Expand Up @@ -2167,9 +2170,11 @@ def copy_content_into(self, revision_id=None, tag_selector=None):
if self.source._push_should_merge_tags():
self.source.tags.merge_to(self.target.tags, selector=tag_selector)

def fetch(self, stop_revision=None, limit=None, lossy=False):
def fetch(self, stop_revision=None, limit=None, lossy=False, depth=None):
if self.target.base == self.source.base:
return (0, [])
if depth is not None:
raise errors.FetchDepthUnsupported(self)
with self.source.lock_read(), self.target.lock_write():
fetch_spec_factory = fetch.FetchSpecFactory()
fetch_spec_factory.source_branch = self.source
Expand Down
6 changes: 5 additions & 1 deletion breezy/bzr/bzrdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def sprout(self, url, revision_id=None, force_new_repo=False,
recurse='down', possible_transports=None,
accelerator_tree=None, hardlink=False, stacked=False,
source_branch=None, create_tree_if_local=True,
lossy=False):
depth=None):
"""Create a copy of this controldir prepared for use as a new line of
development.

Expand All @@ -376,8 +376,12 @@ def sprout(self, url, revision_id=None, force_new_repo=False,
location of this control directory.
:param create_tree_if_local: If true, a working-tree will be created
when working locally.
:param depth: Optional fetch depth
:return: The created control directory
"""
if depth is not None:
raise errors.FetchDepthUnsupported(self)

with contextlib.ExitStack() as stack:
fetch_spec_factory = fetch.FetchSpecFactory()
if revision_id is not None:
Expand Down
3 changes: 2 additions & 1 deletion breezy/controldir.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def sprout(self, url, revision_id=None, force_new_repo=False,
recurse='down', possible_transports=None,
accelerator_tree=None, hardlink=False, stacked=False,
source_branch=None, create_tree_if_local=True,
lossy=False):
depth=None):
"""Create a copy of this controldir prepared for use as a new line of
development.

Expand All @@ -438,6 +438,7 @@ def sprout(self, url, revision_id=None, force_new_repo=False,
location of this control directory.
create_tree_if_local: If true, a working-tree will be created
when working locally.
:param depth: Possible fetch depth
"""
raise NotImplementedError(self.sprout)

Expand Down
8 changes: 8 additions & 0 deletions breezy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,14 @@ def __init__(self, method, method_self):
self.tname = type(method_self).__name__


class FetchDepthUnsupported(UnsupportedOperation):

fmt = ("InterBranch %(interbranch)r does not support fetching depths.")

def __init__(self, interbranch):
BzrError.__init__(self, interbranch=interbranch)


class FetchLimitUnsupported(UnsupportedOperation):

fmt = ("InterBranch %(interbranch)r does not support fetching limits.")
Expand Down
27 changes: 17 additions & 10 deletions breezy/git/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,12 +1007,15 @@ def is_compatible(cls, source, target):
return False
return True

def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
def fetch(self, stop_revision=None, fetch_tags=None, limit=None,
lossy=False, depth=None):
self.fetch_objects(
stop_revision, fetch_tags=fetch_tags, limit=limit, lossy=lossy)
stop_revision, fetch_tags=fetch_tags, limit=limit, lossy=lossy,
depth=depth)
return _mod_repository.FetchResult()

def fetch_objects(self, stop_revision, fetch_tags, limit=None, lossy=False, tag_selector=None):
def fetch_objects(self, stop_revision, fetch_tags, limit=None, lossy=False,
tag_selector=None, depth=None):
interrepo = self._get_interrepo(self.source, self.target)
if fetch_tags is None:
c = self.source.get_config_stack()
Expand All @@ -1033,7 +1036,7 @@ def determine_wants(heads):
[self._last_revid], include_tags=fetch_tags, tag_selector=tag_selector)
return real(heads)
pack_hint, head, refs = interrepo.fetch_objects(
determine_wants, self.source.mapping, limit=limit,
determine_wants, self.source.mapping, limit=limit, depth=depth,
lossy=lossy)
if (pack_hint is not None and
self.target.repository._format.pack_compresses):
Expand Down Expand Up @@ -1168,7 +1171,8 @@ def _basic_push(self, overwrite, stop_revision, tag_selector=None):
class InterGitBranch(branch.GenericInterBranch):
"""InterBranch implementation that pulls between Git branches."""

def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False,
depth=None):
raise NotImplementedError(self.fetch)


Expand Down Expand Up @@ -1248,7 +1252,8 @@ def is_compatible(self, source, target):
return (isinstance(source, GitBranch) and
isinstance(target, LocalGitBranch))

def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False,
depth=None):
interrepo = _mod_repository.InterRepository.get(
self.source.repository, self.target.repository)
if stop_revision is None:
Expand All @@ -1258,7 +1263,8 @@ def fetch(self, stop_revision=None, fetch_tags=None, limit=None, lossy=False):
fetch_tags = c.get('branch.fetch_tags')
determine_wants = interrepo.get_determine_wants_revids(
[stop_revision], include_tags=fetch_tags)
interrepo.fetch_objects(determine_wants, limit=limit, lossy=lossy)
interrepo.fetch_objects(
determine_wants, limit=limit, lossy=lossy, depth=depth)
return _mod_repository.FetchResult()

def _basic_push(self, overwrite=False, stop_revision=None, tag_selector=None):
Expand Down Expand Up @@ -1455,7 +1461,7 @@ def ref_equals(refs, ref, git_sha, revid):
return ret

def fetch(self, stop_revision=None, fetch_tags=None, lossy=False,
limit=None):
limit=None, depth=None):
if stop_revision is None:
stop_revision = self.source.last_revision()
ret = []
Expand All @@ -1465,7 +1471,8 @@ def fetch(self, stop_revision=None, fetch_tags=None, lossy=False,
ret.append((None, stop_revision))
if getattr(self.interrepo, 'fetch_revs', None):
try:
revidmap = self.interrepo.fetch_revs(ret, lossy=lossy, limit=limit)
revidmap = self.interrepo.fetch_revs(
ret, lossy=lossy, limit=limit, depth=depth)
except NoPushSupport:
raise errors.NoRoundtrippingSupport(self.source, self.target)
return _mod_repository.FetchResult(revidmap={
Expand All @@ -1481,7 +1488,7 @@ def determine_wants(refs):
return wants

self.interrepo.fetch_objects(
determine_wants, lossy=lossy, limit=limit)
determine_wants, lossy=lossy, limit=limit, depth=depth)
return _mod_repository.FetchResult()

def pull(self, overwrite=False, stop_revision=None, local=False,
Expand Down
5 changes: 3 additions & 2 deletions breezy/git/dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _available_backup_name(self, base):
def sprout(self, url, revision_id=None, force_new_repo=False,
recurse='down', possible_transports=None,
accelerator_tree=None, hardlink=False, stacked=False,
source_branch=None, create_tree_if_local=True):
source_branch=None, create_tree_if_local=True, depth=None):
from ..repository import InterRepository
from ..transport.local import LocalTransport
from ..transport import get_transport
Expand Down Expand Up @@ -187,7 +187,8 @@ def sprout(self, url, revision_id=None, force_new_repo=False,
else:
determine_wants = interrepo.determine_wants_all
interrepo.fetch_objects(determine_wants=determine_wants,
mapping=source_branch.mapping)
mapping=source_branch.mapping,
depth=depth)
result_branch = source_branch.sprout(
result, revision_id=revision_id, repository=result_repo)
if (create_tree_if_local and
Expand Down
4 changes: 3 additions & 1 deletion breezy/git/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,16 @@ def import_git_commit(repo, mapping, head, lookup_object,

def import_git_objects(repo, mapping, object_iter,
target_git_object_retriever, heads, pb=None,
limit=None):
limit=None, depth=None):
"""Import a set of git objects into a bzr repository.

:param repo: Target Bazaar repository
:param mapping: Mapping to use
:param object_iter: Iterator over Git objects.
:return: Tuple with pack hints and last imported revision id
"""
if depth is None:
raise NotImplementedError
def lookup_object(sha):
try:
return object_iter[sha]
Expand Down
Loading