From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 5F482138A1A for ; Sun, 18 Jan 2015 10:33:59 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CEF42E0962; Sun, 18 Jan 2015 10:33:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4DC16E092B for ; Sun, 18 Jan 2015 10:33:58 +0000 (UTC) Received: from pomiot.lan (mgorny-1-pt.tunnel.tserv28.waw1.ipv6.he.net [IPv6:2001:470:70:353::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 9A3BA3406E3; Sun, 18 Jan 2015 10:33:56 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-portage-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-portage-dev] [PATCH v2] sync: support sync-depth for DVCS-es (git --depth) Date: Sun, 18 Jan 2015 11:33:49 +0100 Message-Id: <1421577229-4661-1-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 2.2.1 In-Reply-To: <20150118014159.4b1104e8.dolsen@gentoo.org> References: <20150118014159.4b1104e8.dolsen@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Archives-Salt: fc6359f7-5be0-41a3-babf-417cce17ff51 X-Archives-Hash: 047d7278fc92f011d9ceb658916d866c Support sync-depth with the default set to 1. This allows the user to reduce the number of historical commits fetched along with the repository (git --depth). --- man/portage.5 | 6 +++++- pym/portage/repository/config.py | 6 +++++- pym/portage/sync/modules/git/__init__.py | 28 +++++++++++++++++++++++++++- pym/portage/sync/modules/git/git.py | 6 +++++- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/man/portage.5 b/man/portage.5 index f0b0e20..5d0e7c0 100644 --- a/man/portage.5 +++ b/man/portage.5 @@ -1,4 +1,4 @@ -.TH "PORTAGE" "5" "Jan 2015" "Portage VERSION" "Portage" +TH "PORTAGE" "5" "Jan 2015" "Portage VERSION" "Portage" .SH NAME portage \- the heart of Gentoo .SH "DESCRIPTION" @@ -906,6 +906,10 @@ Specifies priority of given repository. .B sync\-cvs\-repo Specifies CVS repository. .TP +.B sync\-depth +Specifies clone depth to use for DVCS repositories. Defaults to 1 (only +the newest commit). If set to 0, the depth is unlimited. +.TP .B sync\-type Specifies type of synchronization performed by `emerge \-\-sync`. .br diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index 7e17e02..84fc2ff 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -88,7 +88,8 @@ class RepoConfig(object): 'profile_formats', 'sign_commit', 'sign_manifest', 'sync_cvs_repo', 'sync_type', 'sync_umask', 'sync_uri', 'sync_user', 'thin_manifest', 'update_changelog', 'user_location', '_eapis_banned', - '_eapis_deprecated', '_masters_orig') + '_eapis_deprecated', '_masters_orig', + 'sync_depth') def __init__(self, name, repo_opts, local_config=True): """Build a RepoConfig with options in repo_opts @@ -176,6 +177,8 @@ class RepoConfig(object): auto_sync = auto_sync.strip().lower() self.auto_sync = auto_sync + self.sync_depth = repo_opts.get('sync-depth') + # Not implemented. format = repo_opts.get('format') if format is not None: @@ -489,6 +492,7 @@ class RepoConfigLoader(object): for k in ('aliases', 'auto_sync', 'eclass_overrides', 'force', 'masters', 'priority', 'sync_cvs_repo', 'sync_type', 'sync_umask', 'sync_uri', 'sync_user', + 'sync_depth', ): v = getattr(repos_conf_opts, k, None) if v is not None: diff --git a/pym/portage/sync/modules/git/__init__.py b/pym/portage/sync/modules/git/__init__.py index 833b389..a372881 100644 --- a/pym/portage/sync/modules/git/__init__.py +++ b/pym/portage/sync/modules/git/__init__.py @@ -5,7 +5,33 @@ doc = """Git plug-in module for portage. Performs a git pull on repositories.""" __doc__ = doc[:] +from portage.localization import _ from portage.sync.config_checks import CheckSyncConfig +from portage.util import writemsg_level + + +class CheckGitConfig(CheckSyncConfig): + def __init__(self, repo, logger): + CheckSyncConfig.__init__(self, repo, logger) + self.checks.append('check_depth') + + def check_depth(self): + d = self.repo.sync_depth + # default + self.repo.sync_depth = 1 + + if d is not None: + try: + d = int(d) + except ValueError: + writemsg_level("!!! %s\n" % + _("sync-depth value is not a number: '%s'") + % (d), + level=self.logger.ERROR, noiselevel=-1) + else: + if d == 0: + d = None + self.repo.sync_depth = d module_spec = { @@ -23,7 +49,7 @@ module_spec = { 'exists': 'Returns a boolean of whether the specified dir ' + 'exists and is a valid Git repository', }, - 'validate_config': CheckSyncConfig, + 'validate_config': CheckGitConfig, } } } diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py index 35943dd..d4f2cc1 100644 --- a/pym/portage/sync/modules/git/git.py +++ b/pym/portage/sync/modules/git/git.py @@ -63,9 +63,13 @@ class GitSync(SyncBase): sync_uri = self.repo.sync_uri if sync_uri.startswith("file://"): sync_uri = sync_uri[6:] - exitcode = portage.process.spawn_bash("cd %s ; %s clone %s ." % \ + depth_arg = '' + if self.repo.sync_depth is not None: + depth_arg = '--depth %d ' % self.repo.sync_depth + exitcode = portage.process.spawn_bash("cd %s ; %s clone %s%s ." % \ (portage._shell_quote(self.repo.location), self.bin_command, + depth_arg, portage._shell_quote(sync_uri)), **portage._native_kwargs(self.spawn_kwargs)) if exitcode != os.EX_OK: -- 2.2.1