From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: /, lib/portage/sync/modules/git/
Date: Wed, 21 Dec 2022 01:28:10 +0000 (UTC) [thread overview]
Message-ID: <1671586082.da8e7d193563a2b0c88a523083b2a3466ff4526e.sam@gentoo> (raw)
commit: da8e7d193563a2b0c88a523083b2a3466ff4526e
Author: Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Wed Dec 14 16:09:50 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Dec 21 01:28:02 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=da8e7d19
sync: git: only perform shallow updates if the repository is shallow
With the new default of shallow cloning/updating git repositories,
added with f2207e41792d ("GitSync.update: default to "--depth 1" (bug
824782 comment 17)"), existing *non-shallow* repositories would become
shallow after a "emerge --sync".
This adds a check to see if the repository is already shallow, and
only in this case performs a shallow clone.
Thanks to Douglas Freed for pointing out that this should consider
whether or not the user explicitly set sync-depth.
Thanks-to: Douglas Freed <dwfreed <AT> mtu.edu>
Bug: https://bugs.gentoo.org/824782
Bug: https://bugs.gentoo.org/887025
Closes: https://github.com/gentoo/portage/pull/960
Signed-off-by: Sam James <sam <AT> gentoo.org>
NEWS | 2 ++
lib/portage/sync/modules/git/git.py | 28 +++++++++++++++++++++++-----
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/NEWS b/NEWS
index e80c82227..98f9c71a8 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ portage-3.0.42 (UNRELEASED)
Features:
* cnf: make.conf.example.loong: add for the loong arch (bug #884135).
+* git: only perform shallow updates if the repository is a shallow one
+
Bug fixes:
* glsa: Abort if a GLSA's arch list doesn't match the expected format (bug #882797).
diff --git a/lib/portage/sync/modules/git/git.py b/lib/portage/sync/modules/git/git.py
index 5fcc292cc..f16af0622 100644
--- a/lib/portage/sync/modules/git/git.py
+++ b/lib/portage/sync/modules/git/git.py
@@ -148,12 +148,31 @@ class GitSync(NewBase):
if self.settings.get("PORTAGE_QUIET") == "1":
git_cmd_opts += " --quiet"
+
+ # Default: Perform shallow updates (but only if the target is
+ # already a shallow repository).
+ sync_depth = 1
if self.repo.sync_depth is not None:
- if self.repo.sync_depth != 0:
- git_cmd_opts += " --depth %d" % self.repo.sync_depth
+ sync_depth = self.repo.sync_depth
else:
- # default
- git_cmd_opts += " --depth 1"
+ # If sync-depth is not explicitly set by the user,
+ # then check if the target repository is already a
+ # shallow one. And do not perform a shallow update if
+ # the target repository is not shallow.
+ is_shallow_cmd = ["git", "rev-parse", "--is-shallow-repository"]
+ is_shallow_res = portage._unicode_decode(
+ subprocess.check_output(
+ is_shallow_cmd,
+ cwd=portage._unicode_encode(self.repo.location),
+ )
+ )
+ if is_shallow_res == "false":
+ sync_depth = 0
+
+ shallow = False
+ if sync_depth > 0:
+ git_cmd_opts += f" --depth {sync_depth}"
+ shallow = True
if self.repo.module_specific_options.get("sync-git-pull-extra-opts"):
git_cmd_opts += (
@@ -181,7 +200,6 @@ class GitSync(NewBase):
writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
return (e.returncode, False)
- shallow = self.repo.sync_depth is None or self.repo.sync_depth != 0
if shallow:
# For shallow fetch, unreachable objects may need to be pruned
# manually, in order to prevent automatic git gc calls from
next reply other threads:[~2022-12-21 1:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-21 1:28 Sam James [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-12-21 1:28 [gentoo-commits] proj/portage:master commit in: /, lib/portage/sync/modules/git/ Sam James
2022-12-31 14:11 Sam James
2023-02-22 17:33 Sam James
2023-10-22 19:03 Sam James
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1671586082.da8e7d193563a2b0c88a523083b2a3466ff4526e.sam@gentoo \
--to=sam@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox