Browse Source

cli: open pack-objects output files in binary mode to avoid write() error

Previous code failed as follows:

$ git rev-list main | dulwich pack-objects foo
Traceback (most recent call last):
  File "/home/stsp/dulwich/venv/bin/dulwich", line 33, in <module>
    sys.exit(load_entry_point('dulwich==0.20.50', 'console_scripts', 'dulwich')())
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/cli.py", line 783, in main
    return cmd_kls().run(argv[1:])
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/cli.py", line 541, in run
    porcelain.pack_objects(".", object_ids, packf, idxf)
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/porcelain.py", line 1754, in pack_objects
    entries, data_sum = write_pack_objects(
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/pack.py", line 1713, in write_pack_objects
    return write_pack_data(
  File "/home/stsp/dulwich/venv/lib/python3.9/site-packages/dulwich/pack.py", line 1804, in write_pack_data
    write(chunk)
TypeError: write() argument must be str, not bytes
Stefan Sperling 2 years ago
parent
commit
0f9c8a1822
1 changed files with 2 additions and 2 deletions
  1. 2 2
      dulwich/cli.py

+ 2 - 2
dulwich/cli.py

@@ -535,8 +535,8 @@ class cmd_pack_objects(Command):
             idxf = None
             close = []
         else:
-            packf = open(basename + ".pack", "w")
-            idxf = open(basename + ".idx", "w")
+            packf = open(basename + ".pack", "wb")
+            idxf = open(basename + ".idx", "wb")
             close = [packf, idxf]
         porcelain.pack_objects(".", object_ids, packf, idxf)
         for f in close: