Skip to contentSkip to conversation

git-make-shallow: use stdin mode

PATCH In review Nick Owens 2 participants 4 messages Jan 5, 2025 – Jan 10, 2025

lore
Share & tools
lore

Nick Owens

author
#0 lore raw

PATCH 1/1 git-make-shallow: use stdin mode

when there are many refs to delete, using xargs to exec git can take a very long time. make this faster by only running git update-ref with stdin mode.

for a repo with over 34000 git tags this makes git-make-shallow finish in 2 seconds instead of 3 minutes for me.

---
 bin/git-make-shallow | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bin/git-make-shallow +2 -2
index 9de557c10..8ad704fae 100755
@@ -115,8 +115,8 @@ 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_cmd + ['update-ref', '-d', '--no-deref'],
-                     input=''.join(l + '\0' for l in to_remove))
+        check_output(git_cmd + ['update-ref', '--no-deref', '--stdin', '-z'],
+                     input=''.join('delete ' + l + '\0\0' for l in to_remove) + 'commit\0')
 
 
 def follow_history_intersections(revisions, refs):
Signature · 1 line
2.34.1
#1 lore raw
Quoted 18 lines · Nick Owens via lists.openembedded.org

when there are many refs to delete, using xargs to exec git can take a very long time. make this faster by only running git update-ref with stdin mode.

for a repo with over 34000 git tags this makes git-make-shallow finish in 2 seconds instead of 3 minutes for me.

---
 bin/git-make-shallow | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
bin/git-make-shallow +0 -0
index 9de557c10..8ad704fae 100755
@@ -115,8 +115,8 @@ def filter_refs(refs):
      all_refs = get_all_refs()
      to_remove = set(all_refs) - set(refs)
Quoted 7 lines

     if to_remove:
-        check_output(['xargs', '-0', '-n', '1'] + git_cmd + ['update-ref', '-d', '--no-deref'], -                     input=''.join(l + '\0' for l in to_remove))
+        check_output(git_cmd + ['update-ref', '--no-deref', '--stdin', '-z'],
+                     input=''.join('delete ' + l + '\0\0' for l in to_remove) + 'commit\0')

This sounded really good and it merged however we're seeing intermittent failures:

https://valkyrie.yoctoproject.org/#/builders/54/builds/725/steps/11/logs/stdio
https://valkyrie.yoctoproject.org/#/builders/23/builds/810/steps/11/logs/stdio

This appears like it might me python or git version specific, there is a deprecation warning in the log which I also wonder about...

Cheers,

Richard

author
#2 lore raw

right. i think this is because the transaction model was only introduced in git 2.27 whereas ubuntu focal (20.04) only has 2.25. and, i think i bungled the use of the transaction commands by not issuing 'start'. i think dropping commit should resolve it.

bitbake/bin/git-make-shallow +0 -1
index d0532c5ab8..bead94a766 100755
@@ -113,8 +113,8 @@ 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'],
- input=''.join(l + '\0' for l in to_remove))
+ check_output(['git', 'update-ref', '--no-deref', '--stdin', '-z'],
+ input=''.join('delete ' + l + '\0\0' for l in
to_remove))

def follow_history_intersections(revisions, refs):

Quoted 47 lines · Richard Purdie
Quoted 1 line · Nick Owens via lists.openembedded.org

when there are many refs to delete, using xargs to exec git can take a

very long

Quoted 15 lines

time. make this faster by only running git update-ref with stdin mode.

for a repo with over 34000 git tags this makes git-make-shallow finish in 2 seconds instead of 3 minutes for me.

---
 bin/git-make-shallow | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bin/git-make-shallow +0 -0
index 9de557c10..8ad704fae 100755

bin/git-make-shallow def filter_refs(refs): · line 118

Quoted 4 lines
bin/git-make-shallow +0 -1
@@ -115,8 +115,8 @@ 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_cmd +

['update-ref', '-d', '--no-deref'],

bin/git-make-shallow def filter_refs(refs): · line 118

Quoted 2 lines
bin/git-make-shallow +1 -1
-                     input=''.join(l + '\0' for l in to_remove))
+        check_output(git_cmd + ['update-ref', '--no-deref', '--stdin',

'-z'],

bin/git-make-shallow def filter_refs(refs): · line 119

Quoted 1 line
bin/git-make-shallow +1 -0
+                     input=''.join('delete ' + l + '\0\0' for l in

to_remove) + 'commit\0')

Quoted 2 lines

This sounded really good and it merged however we're seeing intermittent failures:

https://valkyrie.yoctoproject.org/#/builders/54/builds/725/steps/11/logs/stdio

https://valkyrie.yoctoproject.org/#/builders/23/builds/810/steps/11/logs/stdio

This appears like it might me python or git version specific, there is a deprecation warning in the log which I also wonder about...

Cheers,

Richard

#3 lore raw
Quoted 16 lines · Nick Owens

right. i think this is because the transaction model was only introduced in git 2.27 whereas ubuntu focal (20.04) only has 2.25. and, i think i bungled the use of the transaction commands by not issuing 'start'. i think dropping commit should resolve it.

bitbake/bin/git-make- renamed from bitbake/bin/git-make-shallow +0 -0

shallow
index d0532c5ab8..bead94a766 100755

bitbake/bin/git-make-shallow +0 -0
@@ -113,8 +113,8 @@ 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'],

Quoted 8 lines

-                     input=''.join(l + '\0' for l in to_remove))
+        check_output(['git', 'update-ref', '--no-deref', '--stdin', '-z'],
+                     input=''.join('delete ' + l + '\0\0' for l in to_remove))


 def follow_history_intersections(revisions, refs):

Thanks for the hint, I've turned this into a patch, sent and then merged it since this was breaking builds and there are enough other issues atm to worry about so I wanted to get it resolved! :)

I did test it on the failing 20.04 worker and it works there now.

Cheers,

Richard