Split out vcs module.

This commit is contained in:
Jelmer Vernooij 2021-02-06 18:50:52 +00:00
parent 3b71585f6c
commit 88213d8500
No known key found for this signature in database
GPG key ID: 579C160D4C9E23E8
2 changed files with 66 additions and 39 deletions

View file

@ -26,8 +26,6 @@ from typing import Optional, List, Tuple, Callable, Type
from debian.deb822 import Deb822 from debian.deb822 import Deb822
from breezy.errors import NotBranchError
from breezy.export import export
from breezy.tree import Tree from breezy.tree import Tree
from breezy.workingtree import WorkingTree from breezy.workingtree import WorkingTree
@ -44,6 +42,7 @@ from .buildsystem import detect_buildsystems, NoBuildToolsFound
from .session import run_with_tee, Session from .session import run_with_tee, Session
from .session.schroot import SchrootSession from .session.schroot import SchrootSession
from .debian.fix_build import DependencyContext from .debian.fix_build import DependencyContext
from .vcs import dupe_vcs_tree, export_vcs_tree
class DistNoTarball(Exception): class DistNoTarball(Exception):
@ -260,43 +259,6 @@ def run_dist(session):
raise NoBuildToolsFound() raise NoBuildToolsFound()
def export_vcs_tree(tree, directory):
try:
export(tree, directory, 'dir', None)
except OSError as e:
if e.errno == errno.ENOSPC:
raise DetailedFailure(
1, ['export'], NoSpaceOnDevice())
raise
def dupe_vcs_tree(tree, directory):
with tree.lock_read():
if isinstance(tree, WorkingTree):
tree = tree.basis_tree()
try:
result = tree._repository.controldir.sprout(
directory, create_tree_if_local=True,
revision_id=tree.get_revision_id())
except OSError as e:
if e.errno == errno.ENOSPC:
raise DetailedFailure(
1, ['sprout'], NoSpaceOnDevice())
raise
if not result.has_workingtree():
raise AssertionError
# Copy parent location - some scripts need this
if isinstance(tree, WorkingTree):
parent = tree.branch.get_parent()
else:
try:
parent = tree._repository.controldir.open_branch().get_parent()
except NotBranchError:
parent = None
if parent:
result.open_branch().set_parent(parent)
class DistCatcher(object): class DistCatcher(object):
def __init__(self, directory): def __init__(self, directory):

65
ognibuild/vcs.py Normal file
View file

@ -0,0 +1,65 @@
#!/usr/bin/python3
# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import errno
from breezy.errors import NotBranchError
from breezy.export import export
from breezy.workingtree import WorkingTree
from buildlog_consultant.sbuild import (
NoSpaceOnDevice,
)
from . import DetailedFailure
def export_vcs_tree(tree, directory):
try:
export(tree, directory, 'dir', None)
except OSError as e:
if e.errno == errno.ENOSPC:
raise DetailedFailure(
1, ['export'], NoSpaceOnDevice())
raise
def dupe_vcs_tree(tree, directory):
with tree.lock_read():
if isinstance(tree, WorkingTree):
tree = tree.basis_tree()
try:
result = tree._repository.controldir.sprout(
directory, create_tree_if_local=True,
revision_id=tree.get_revision_id())
except OSError as e:
if e.errno == errno.ENOSPC:
raise DetailedFailure(
1, ['sprout'], NoSpaceOnDevice())
raise
if not result.has_workingtree():
raise AssertionError
# Copy parent location - some scripts need this
if isinstance(tree, WorkingTree):
parent = tree.branch.get_parent()
else:
try:
parent = tree._repository.controldir.open_branch().get_parent()
except NotBranchError:
parent = None
if parent:
result.open_branch().set_parent(parent)