All of lore.kernel.org
 help / color / mirror / Atom feed
From: ecordonnier@snap.com
To: openembedded-core@lists.openembedded.org
Cc: Etienne Cordonnier <ecordonnier@snap.com>
Subject: [PATCH v2 2/3] archiver.bbclass: remove .git from original git source archives
Date: Fri, 30 Oct 2026 18:45:35 +0100	[thread overview]
Message-ID: <20261030174536.2724008-3-ecordonnier@snap.com> (raw)
In-Reply-To: <20261030174536.2724008-1-ecordonnier@snap.com>

From: Etienne Cordonnier <ecordonnier@snap.com>

In the original mode, do_ar_original unpacks git sources and archives the
unpacked tree, including its .git. This .git is of no use in the archive:

- For a clone, unpack() uses clone -s, so .git has no objects, only a
  reference to the clone in DL_DIR via objects/info/alternates. It is
  confusing and still wastes a little space.
- For a shallow tarball, .git has all the (compressed) objects, which
  duplicates the sources and doubles the size of the archive.

Remove it, as well as the .git files of submodules. Keep it with nocheckout
(which bareclone implies), where the repository is what gets unpacked.

AI-Generated: Claude Opus 5.5
Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
---
 meta/classes/archiver.bbclass            | 12 +++++++
 meta/lib/oeqa/selftest/cases/archiver.py | 43 ++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/meta/classes/archiver.bbclass b/meta/classes/archiver.bbclass
index f6cca35186..a6b5706abd 100644
--- a/meta/classes/archiver.bbclass
+++ b/meta/classes/archiver.bbclass
@@ -216,6 +216,18 @@ python do_ar_original() {
         elif os.path.isdir(local) or shallow:
             tmpdir = tempfile.mkdtemp(dir=d.getVar('ARCHIVER_WORKDIR'))
             fetch.unpack(tmpdir, (url,))
+            if isinstance(ud.method, bb.fetch.git.Git) and not ud.nocheckout:
+                # The .git of a clone has no objects (clone -s only references
+                # them via objects/info/alternates), and the one of a shallow
+                # tarball duplicates the sources, so it is of no use in the
+                # archive. This includes the .git files of submodules. Keep it
+                # with nocheckout (and bareclone), where it is the source.
+                for root, dirs, files in os.walk(ud.destdir):
+                    if '.git' in dirs:
+                        dirs.remove('.git')
+                        bb.utils.remove(os.path.join(root, '.git'), recurse=True)
+                    if '.git' in files:
+                        os.remove(os.path.join(root, '.git'))
             # To handle recipes with more than one source, we add the "name"
             # URL parameter as suffix. We treat it as an error when
             # there's more than one URL without a name, or a name gets reused.
diff --git a/meta/lib/oeqa/selftest/cases/archiver.py b/meta/lib/oeqa/selftest/cases/archiver.py
index 84f13839c9..d55787cfc4 100644
--- a/meta/lib/oeqa/selftest/cases/archiver.py
+++ b/meta/lib/oeqa/selftest/cases/archiver.py
@@ -212,6 +212,49 @@ class Archiver(OESelftestTestCase):
 
         names = self._get_original_git_archive_names(target)
         self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+        self._assert_no_git(names)
+
+    def test_archiver_mode_original_git(self):
+        """
+        Test that the archive of a git source with
+        `ARCHIVER_MODE[src] = "original"` has no .git directory.
+        """
+        target = 'gitrepotest'
+
+        features = 'INHERIT += "archiver"\n'
+        features += 'ARCHIVER_MODE[src] = "original"\n'
+        self.write_config(features)
+
+        bitbake('-c cleansstate %s' % target)
+        bitbake('-c deploy_archives %s' % target)
+
+        names = self._get_original_git_archive_names(target)
+        self.assertTrue([n for n in names if n.endswith('/COPYING')], 'Archive has no source files: %s' % names[:20])
+        self._assert_no_git(names)
+
+    def test_archiver_mode_original_gitsm(self):
+        """
+        Test that the archive of a git source with submodules with
+        `ARCHIVER_MODE[src] = "original"` contains the submodules, but neither
+        the .git directory nor the .git files of the submodules.
+        """
+        target = 'git-submodule-test'
+
+        features = 'INHERIT += "archiver"\n'
+        features += 'ARCHIVER_MODE[src] = "original"\n'
+        features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
+        self.write_config(features)
+
+        bitbake('-c cleansstate %s' % target)
+        bitbake('-c deploy_archives %s' % target)
+
+        names = self._get_original_git_archive_names(target)
+        self.assertTrue([n for n in names if n.endswith('/.gitmodules')], 'Archive has no submodules: %s' % names[:20])
+        self._assert_no_git(names)
+
+    def _assert_no_git(self, names):
+        git = [n for n in names if '.git' in n.split('/')]
+        self.assertFalse(git, 'Archive contains .git: %s' % git[:20])
 
     def _get_original_git_archive_names(self, target):
         """
-- 
2.43.0


  parent reply	other threads:[~2026-10-30 17:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 17:45 [PATCH v2 0/3] *** archiver.bbclass: archive shallow git sources which have no clone *** ecordonnier
2026-10-30 17:45 ` [PATCH v2 1/3] archiver.bbclass: archive shallow git sources which have no clone ecordonnier
2026-10-30 17:45 ` ecordonnier [this message]
2026-10-30 17:45 ` [PATCH v2 3/3] archiver.bbclass: fail on sources which cannot be archived ecordonnier

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=20261030174536.2724008-3-ecordonnier@snap.com \
    --to=ecordonnier@snap.com \
    --cc=openembedded-core@lists.openembedded.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.