public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit
@ 2024-02-16 16:24 André Draszik
  2024-02-16 16:24 ` [OE-core][PATCH 1/3] bitbake: fetch/git2: support git's safe.bareRepository André Draszik
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: André Draszik @ 2024-02-16 16:24 UTC (permalink / raw)
  To: openembedded-core

Hi,

When git is configured with safe.bareRepository=explicit [1], various pieces
here just fail. LWN has an article about the problem that this configuration
option addresses and why it is useful in [2].

To test, simply run
    git config --global safe.bareRepository explicit
to add safe.bareRepository=explicit to your ~/.gitconfig, and see things
fail without these patches.

These patches are the first stop-gap step to make bitbake/OE work with this
configuration option enabled. I believe in the future, these should be
converted to invoking git with the --git-dir= option explicitly.

Link: https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/config/safe.txt#n1 [1]
Link: https://lwn.net/Articles/892755/ [2]

Cheers,
Andre'




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [OE-core][PATCH 1/3] bitbake: fetch/git2: support git's safe.bareRepository
  2024-02-16 16:24 [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
@ 2024-02-16 16:24 ` André Draszik
  2024-02-16 16:25 ` [OE-core][PATCH 2/3] bitbake: tests/fetch: " André Draszik
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: André Draszik @ 2024-02-16 16:24 UTC (permalink / raw)
  To: openembedded-core

When git is configured with safe.bareRepository=explicit [1], the
bitbake git fetcher fails miserably. LWN has an article about the
problem that this configuration option addresses and why it is useful
in [2].

It also seems that it is being rolled out in some environments as a
default for users.

In order to allow having this configuration turned on for a user's
environment in general, the fetcher has to be tought to use --git-dir=
for all relevent git operations.

The alternative, implemented here, is to forcibly turn off that option
for all git operations. In the future, we could look into converting
these to using the --git-dir= command line argument instead.

While at it, fix one open-coded invocation of git that wasn't using
ud.basecmd

Link: https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/config/safe.txt#n1 [1]
Link: https://lwn.net/Articles/892755/ [2]
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 bitbake/lib/bb/fetch2/git.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 0deeb5cee1f2..842f1c689697 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -258,7 +258,7 @@ class Git(FetchMethod):
             for name in ud.names:
                 ud.unresolvedrev[name] = 'HEAD'
 
-        ud.basecmd = d.getVar("FETCHCMD_git") or "git -c gc.autoDetach=false -c core.pager=cat"
+        ud.basecmd = d.getVar("FETCHCMD_git") or "git -c gc.autoDetach=false -c core.pager=cat -c safe.bareRepository=all"
 
         write_tarballs = d.getVar("BB_GENERATE_MIRROR_TARBALLS") or "0"
         ud.write_tarballs = write_tarballs != "0" or ud.rebaseable
@@ -514,7 +514,7 @@ class Git(FetchMethod):
 
             logger.info("Creating tarball of git repository")
             with create_atomic(ud.fullmirror) as tfile:
-                mtime = runfetchcmd("git log --all -1 --format=%cD", d,
+                mtime = runfetchcmd("{} log --all -1 --format=%cD".format(ud.basecmd), d,
                         quiet=True, workdir=ud.clonedir)
                 runfetchcmd("tar -czf %s --owner oe:0 --group oe:0 --mtime \"%s\" ."
                         % (tfile, mtime), d, workdir=ud.clonedir)
-- 
2.44.0.rc0.258.g7320e95886-goog



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [OE-core][PATCH 2/3] bitbake: tests/fetch: support git's safe.bareRepository
  2024-02-16 16:24 [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
  2024-02-16 16:24 ` [OE-core][PATCH 1/3] bitbake: fetch/git2: support git's safe.bareRepository André Draszik
@ 2024-02-16 16:25 ` André Draszik
  2024-02-16 16:25 ` [OE-core][PATCH 3/3] bitbake: git-make-shallow: " André Draszik
  2024-02-16 16:33 ` [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
  3 siblings, 0 replies; 5+ messages in thread
From: André Draszik @ 2024-02-16 16:25 UTC (permalink / raw)
  To: openembedded-core

When git is configured with safe.bareRepository=explicit [1], the
bitbake selftests fail miserably. LWN has an article about the
problem that this configuration option addresses and why it is useful
in [2].

It also seems that it is being rolled out in some environments as a
default for users.

In order to allow having this configuration turned on for a user's
environment in general, the fetcher has to be tought to use --git-dir=
for all relevent git operations.

The alternative, implemented here, is to forcibly turn off that option
for all git operations. In the future, we could look into converting
these to using the --git-dir= command line argument instead.

Link: https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/config/safe.txt#n1 [1]
Link: https://lwn.net/Articles/892755/ [2]
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 bitbake/lib/bb/tests/fetch.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 41e1d8cf107c..bb30ed651313 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -416,9 +416,9 @@ class FetcherTest(unittest.TestCase):
 
     def git(self, cmd, cwd=None):
         if isinstance(cmd, str):
-            cmd = 'git ' + cmd
+            cmd = 'git -c safe.bareRepository=all ' + cmd
         else:
-            cmd = ['git'] + cmd
+            cmd = ['git', '-c', 'safe.bareRepository=all'] + cmd
         if cwd is None:
             cwd = self.gitdir
         return bb.process.run(cmd, cwd=cwd)[0]
-- 
2.44.0.rc0.258.g7320e95886-goog



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [OE-core][PATCH 3/3] bitbake: git-make-shallow: support git's safe.bareRepository
  2024-02-16 16:24 [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
  2024-02-16 16:24 ` [OE-core][PATCH 1/3] bitbake: fetch/git2: support git's safe.bareRepository André Draszik
  2024-02-16 16:25 ` [OE-core][PATCH 2/3] bitbake: tests/fetch: " André Draszik
@ 2024-02-16 16:25 ` André Draszik
  2024-02-16 16:33 ` [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
  3 siblings, 0 replies; 5+ messages in thread
From: André Draszik @ 2024-02-16 16:25 UTC (permalink / raw)
  To: openembedded-core

When git is configured with safe.bareRepository=explicit [1], the
git-make-shallow fails miserably. LWN has an article about the
problem that this configuration option addresses and why it is useful
in [2].

It also seems that it is being rolled out in some environments as a
default for users.

In order to allow having this configuration turned on for a user's
environment in general, the fetcher has to be tought to use --git-dir=
for all relevent git operations.

The alternative, implemented here, is to forcibly turn off that option
for all git operations. In the future, we could look into converting
these to using the --git-dir= command line argument instead.

Link: https://git.kernel.org/pub/scm/git/git.git/tree/Documentation/config/safe.txt#n1 [1]
Link: https://lwn.net/Articles/892755/ [2]
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
 bitbake/bin/git-make-shallow | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/bitbake/bin/git-make-shallow b/bitbake/bin/git-make-shallow
index d0532c5ab85e..9de557c10e4a 100755
--- a/bitbake/bin/git-make-shallow
+++ b/bitbake/bin/git-make-shallow
@@ -24,15 +24,17 @@ warnings.simplefilter("default")
 version = 1.0
 
 
+git_cmd = ['git', '-c', 'safe.bareRepository=all']
+
 def main():
     if sys.version_info < (3, 4, 0):
         sys.exit('Python 3.4 or greater is required')
 
-    git_dir = check_output(['git', 'rev-parse', '--git-dir']).rstrip()
+    git_dir = check_output(git_cmd + ['rev-parse', '--git-dir']).rstrip()
     shallow_file = os.path.join(git_dir, 'shallow')
     if os.path.exists(shallow_file):
         try:
-            check_output(['git', 'fetch', '--unshallow'])
+            check_output(git_cmd + ['fetch', '--unshallow'])
         except subprocess.CalledProcessError:
             try:
                 os.unlink(shallow_file)
@@ -41,21 +43,21 @@ def main():
                     raise
 
     args = process_args()
-    revs = check_output(['git', 'rev-list'] + args.revisions).splitlines()
+    revs = check_output(git_cmd + ['rev-list'] + args.revisions).splitlines()
 
     make_shallow(shallow_file, args.revisions, args.refs)
 
-    ref_revs = check_output(['git', 'rev-list'] + args.refs).splitlines()
+    ref_revs = check_output(git_cmd + ['rev-list'] + args.refs).splitlines()
     remaining_history = set(revs) & set(ref_revs)
     for rev in remaining_history:
-        if check_output(['git', 'rev-parse', '{}^@'.format(rev)]):
+        if check_output(git_cmd + ['rev-parse', '{}^@'.format(rev)]):
             sys.exit('Error: %s was not made shallow' % rev)
 
     filter_refs(args.refs)
 
     if args.shrink:
         shrink_repo(git_dir)
-        subprocess.check_call(['git', 'fsck', '--unreachable'])
+        subprocess.check_call(git_cmd + ['fsck', '--unreachable'])
 
 
 def process_args():
@@ -72,12 +74,12 @@ def process_args():
     args = parser.parse_args()
 
     if args.refs:
-        args.refs = check_output(['git', 'rev-parse', '--symbolic-full-name'] + args.refs).splitlines()
+        args.refs = check_output(git_cmd + ['rev-parse', '--symbolic-full-name'] + args.refs).splitlines()
     else:
         args.refs = get_all_refs(lambda r, t, tt: t == 'commit' or tt == 'commit')
 
     args.refs = list(filter(lambda r: not r.endswith('/HEAD'), args.refs))
-    args.revisions = check_output(['git', 'rev-parse'] + ['%s^{}' % i for i in args.revisions]).splitlines()
+    args.revisions = check_output(git_cmd + ['rev-parse'] + ['%s^{}' % i for i in args.revisions]).splitlines()
     return args
 
 
@@ -95,7 +97,7 @@ def make_shallow(shallow_file, revisions, refs):
 
 def get_all_refs(ref_filter=None):
     """Return all the existing refs in this repository, optionally filtering the refs."""
-    ref_output = check_output(['git', 'for-each-ref', '--format=%(refname)\t%(objecttype)\t%(*objecttype)'])
+    ref_output = check_output(git_cmd + ['for-each-ref', '--format=%(refname)\t%(objecttype)\t%(*objecttype)'])
     ref_split = [tuple(iter_extend(l.rsplit('\t'), 3)) for l in ref_output.splitlines()]
     if ref_filter:
         ref_split = (e for e in ref_split if ref_filter(*e))
@@ -113,7 +115,7 @@ def filter_refs(refs):
     all_refs = get_all_refs()
     to_remove = set(all_refs) - set(refs)
     if to_remove:
-        check_output(['xargs', '-0', '-n', '1', 'git', 'update-ref', '-d', '--no-deref'],
+        check_output(['xargs', '-0', '-n', '1'] + git_cmd + ['update-ref', '-d', '--no-deref'],
                      input=''.join(l + '\0' for l in to_remove))
 
 
@@ -126,7 +128,7 @@ def follow_history_intersections(revisions, refs):
         if rev in seen:
             continue
 
-        parents = check_output(['git', 'rev-parse', '%s^@' % rev]).splitlines()
+        parents = check_output(git_cmd + ['rev-parse', '%s^@' % rev]).splitlines()
 
         yield rev
         seen.add(rev)
@@ -134,12 +136,12 @@ def follow_history_intersections(revisions, refs):
         if not parents:
             continue
 
-        check_refs = check_output(['git', 'merge-base', '--independent'] + sorted(refs)).splitlines()
+        check_refs = check_output(git_cmd + ['merge-base', '--independent'] + sorted(refs)).splitlines()
         for parent in parents:
             for ref in check_refs:
                 print("Checking %s vs %s" % (parent, ref))
                 try:
-                    merge_base = check_output(['git', 'merge-base', parent, ref]).rstrip()
+                    merge_base = check_output(git_cmd + ['merge-base', parent, ref]).rstrip()
                 except subprocess.CalledProcessError:
                     continue
                 else:
@@ -159,14 +161,14 @@ def iter_except(func, exception, start=None):
 
 def shrink_repo(git_dir):
     """Shrink the newly shallow repository, removing the unreachable objects."""
-    subprocess.check_call(['git', 'reflog', 'expire', '--expire-unreachable=now', '--all'])
-    subprocess.check_call(['git', 'repack', '-ad'])
+    subprocess.check_call(git_cmd + ['reflog', 'expire', '--expire-unreachable=now', '--all'])
+    subprocess.check_call(git_cmd + ['repack', '-ad'])
     try:
         os.unlink(os.path.join(git_dir, 'objects', 'info', 'alternates'))
     except OSError as exc:
         if exc.errno != errno.ENOENT:
             raise
-    subprocess.check_call(['git', 'prune', '--expire', 'now'])
+    subprocess.check_call(git_cmd + ['prune', '--expire', 'now'])
 
 
 if __name__ == '__main__':
-- 
2.44.0.rc0.258.g7320e95886-goog



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit
  2024-02-16 16:24 [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
                   ` (2 preceding siblings ...)
  2024-02-16 16:25 ` [OE-core][PATCH 3/3] bitbake: git-make-shallow: " André Draszik
@ 2024-02-16 16:33 ` André Draszik
  3 siblings, 0 replies; 5+ messages in thread
From: André Draszik @ 2024-02-16 16:33 UTC (permalink / raw)
  To: openembedded-core

On Fri, 2024-02-16 at 16:24 +0000, André Draszik wrote:
> Hi,
> 
> When git is configured with safe.bareRepository=explicit [1], various pieces
> here just fail. LWN has an article about the problem that this configuration
> option addresses and why it is useful in [2].

This went to the wrong list, sorry. I'll resend on Monday.


Cheers,
Andre'



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-16 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-16 16:24 [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik
2024-02-16 16:24 ` [OE-core][PATCH 1/3] bitbake: fetch/git2: support git's safe.bareRepository André Draszik
2024-02-16 16:25 ` [OE-core][PATCH 2/3] bitbake: tests/fetch: " André Draszik
2024-02-16 16:25 ` [OE-core][PATCH 3/3] bitbake: git-make-shallow: " André Draszik
2024-02-16 16:33 ` [OE-core][PATCH 0/3] support git's safe.bareRepository=explicit André Draszik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox