Convert integer marks to string in fast-export

Björn Lindström bkhl at elektrubadur.se
Tue Jun 30 11:15:44 UTC 2020


Hello,

when using `fast-export --export-marks` I would get an error like this

```
bkhl at toolbox:.../foo/custom$ brz fast-export 
--export-marks=../marks.bzr ../bzr/trunk/ > /dev/null
16:59:32 Calculating the revisions to include ...
16:59:32 Starting export of 1108 revisions ...
16:59:34 1000/1108 commits exported at 32153/minute
brz: ERROR: AttributeError: 'int' object has no attribute 'lstrip'

Traceback (most recent call last):
  […]
  File 
"/usr/lib64/python3.8/site-packages/breezy/plugins/fastimport/exporter.py", 
line 306, in _save_marks
    marks_file.export_marks(self.export_marks_file, revision_ids)
  File 
"/usr/lib64/python3.8/site-packages/breezy/plugins/fastimport/marks_file.py", 
line 83, in export_marks
    f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),
AttributeError: 'int' object has no attribute 'lstrip'

brz 3.0.2 on python 3.8.2rc2 (Linux-5.6.19-300.fc32.x86_64-x86_64-with-
    glibc2.2.5)
arguments: ['/usr/bin/brz', 'fast-export', 
'--export-marks=../marks.bzr',
```

This patch converts incoming `bytes` or `int` objects to strings 
appropriately, as far as I can tell:


=== modified file 'breezy/plugins/fastimport/marks_file.py'
--- old/breezy/plugins/fastimport/marks_file.py	2020-06-01 23:15:18 
+0000
+++ new/breezy/plugins/fastimport/marks_file.py	2020-06-30 10:28:48 
+0000
@@ -76,7 +76,11 @@
     try:
         # Write the revision info
         for mark in revision_ids:
-            f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),
+            if isinstance(mark, int):
+                mark_name = str(mark)
+            elif isinstance(mark, bytes):
+                mark_name = mark.lstrip(b':').decode('utf-8')
+            f.write(':%s %s\n' % (mark_name,
                                   revision_ids[mark].decode('utf-8')))
     finally:
         f.close()


Not sure if this is necessary though. Can we maybe just assume the 
marks are always going to be `int`s?

I first made a GitHub "PR" for this over here 
https://github.com/breezy-team/breezy/pull/117, before being told on 
the IRC chat that it would be more appropriate to send a patch tot he 
mailing list.

Best wishes,
Björn





More information about the bazaar mailing list