commit:     f2207e41792d8180519e5695934af05daad3c971
Author:     David Sardari <d <AT> duxsco <DOT> de>
AuthorDate: Thu Mar 31 20:29:54 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Oct 18 00:41:35 2022 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f2207e41

GitSync.update: default to "--depth 1" (bug 824782 comment 17)

Enforce the use of "--depth" in both GitSync.new and GitSync.update following 
the same logic.

Each function gets its own designated portage option of "clone-depth" and 
"sync-depth".
This means that portage option "sync-depth" is not taken into consideration 
anymore in GitSync.new.

Portage option "clone-depth" and "sync-depth" lead to following behaviour with 
a value of:
- 0: The use of "--depth <value>" is disabled causing the retrieval of the 
whole Git history.
- ℕ (positive integer): "--depth <value>" is used.
- Unset portage option: "--depth 1" is used.

Bug: https://bugs.gentoo.org/824782
Signed-off-by: David Sardari <d <AT> duxsco.de>
Closes: https://github.com/gentoo/portage/pull/801
Signed-off-by: Sam James <sam <AT> gentoo.org>

 NEWS                                |  3 +++
 lib/portage/sync/modules/git/git.py | 14 ++++++++------
 man/portage.5                       |  8 +++++---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/NEWS b/NEWS
index f3d24e12c..780684966 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,9 @@ Features:
   methods. General BINPKG_COMPRESS_FLAGS will be ignored if current method had
   specified BINPKG_COMPRESS_FLAGS_[format] (bug #871573).
 
+* sync: git: git will sync with --depth=1 unless otherwise specified in 
repos.conf
+  (bug #824782).
+
 * install-qa-check.d: 90gcc-warnings: Add additional code quality warnings
   which are indicative of problems with LTO in particular:
   * -Wlto-type-mismatch

diff --git a/lib/portage/sync/modules/git/git.py 
b/lib/portage/sync/modules/git/git.py
index 381e31700..31ce5febf 100644
--- a/lib/portage/sync/modules/git/git.py
+++ b/lib/portage/sync/modules/git/git.py
@@ -85,9 +85,6 @@ class GitSync(NewBase):
         if self.repo.clone_depth is not None:
             if self.repo.clone_depth != 0:
                 git_cmd_opts += " --depth %d" % self.repo.clone_depth
-        elif self.repo.sync_depth is not None:
-            if self.repo.sync_depth != 0:
-                git_cmd_opts += " --depth %d" % self.repo.sync_depth
         else:
             # default
             git_cmd_opts += " --depth 1"
@@ -152,6 +149,13 @@ class GitSync(NewBase):
 
         if self.settings.get("PORTAGE_QUIET") == "1":
             git_cmd_opts += " --quiet"
+        if self.repo.sync_depth is not None:
+            if self.repo.sync_depth != 0:
+                git_cmd_opts += " --depth %d" % self.repo.sync_depth
+        else:
+            # default
+            git_cmd_opts += " --depth 1"
+
         if self.repo.module_specific_options.get("sync-git-pull-extra-opts"):
             git_cmd_opts += (
                 " %s" % 
self.repo.module_specific_options["sync-git-pull-extra-opts"]
@@ -178,10 +182,8 @@ class GitSync(NewBase):
             writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
             return (e.returncode, False)
 
-        shallow = self.repo.sync_depth is not None and self.repo.sync_depth != 0
+        shallow = self.repo.sync_depth is None or self.repo.sync_depth != 0
         if shallow:
-            git_cmd_opts += " --depth %d" % self.repo.sync_depth
-
             # For shallow fetch, unreachable objects may need to be pruned
             # manually, in order to prevent automatic git gc calls from
             # eventually failing (see bug 599008).

diff --git a/man/portage.5 b/man/portage.5
index 0c1a60827..3e1233615 100644
--- a/man/portage.5
+++ b/man/portage.5
@@ -979,7 +979,8 @@ yes, true.
 .TP
 .B clone\-depth
 Specifies clone depth to use for DVCS repositories. Defaults to 1 (only
-the newest commit). If set to 0, the depth is unlimited.
+the newest commit). If set to 0, the depth is unlimited, because Git is
+not executed with "--depth #".
 .TP
 .B eclass\-overrides
 Makes given repository inherit eclasses from specified repositories.
@@ -1032,8 +1033,9 @@ overlay filesystems. Defaults to yes, true.
 Specifies CVS repository.
 .TP
 .B sync\-depth
-Specifies sync depth to use for DVCS repositories. If set to 0, the
-depth is unlimited. Defaults to 0.
+Specifies sync depth to use for DVCS repositories. Defaults to 1 (only
+the newest commit). If set to 0, the depth is unlimited, because Git is
+not executed with "--depth #".
 .TP
 .B sync\-git\-clone\-env
 Set environment variables for git when cloning repository (git clone).

Reply via email to