/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/fastimport/marks_file.py

  • Committer: Jelmer Vernooij
  • Date: 2020-07-04 12:29:00 UTC
  • mfrom: (7490.40.42 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200704122900-o0y82e758ci5jie4
Merge lp:brz/3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    """
30
30
    # Check that the file is readable and in the right format
31
31
    try:
32
 
        f = open(filename, 'r')
 
32
        f = open(filename, 'rb')
33
33
    except IOError:
34
34
        warning("Could not import marks file %s - not importing marks",
35
35
                filename)
40
40
        revision_ids = {}
41
41
 
42
42
        line = f.readline()
43
 
        if line == 'format=1\n':
 
43
        if line == b'format=1\n':
44
44
            # Cope with old-style marks files
45
45
            # Read the branch info
46
46
            branch_names = {}
47
 
            for string in f.readline().rstrip('\n').split('\0'):
 
47
            for string in f.readline().rstrip(b'\n').split(b'\0'):
48
48
                if not string:
49
49
                    continue
50
 
                name, integer = string.rsplit('.', 1)
 
50
                name, integer = string.rsplit(b'.', 1)
51
51
                branch_names[name] = int(integer)
52
52
            line = f.readline()
53
53
 
54
54
        while line:
55
 
            line = line.rstrip('\n')
56
 
            mark, revid = line.split(' ', 1)
57
 
            mark = mark.lstrip(':')
58
 
            revision_ids[mark] = revid.encode('utf-8')
 
55
            line = line.rstrip(b'\n')
 
56
            mark, revid = line.split(b' ', 1)
 
57
            mark = mark.lstrip(b':')
 
58
            revision_ids[mark] = revid
59
59
            line = f.readline()
60
60
    finally:
61
61
        f.close()
69
69
    :param revision_ids: dictionary mapping marks -> bzr revision-ids
70
70
    """
71
71
    try:
72
 
        f = open(filename, 'w')
 
72
        f = open(filename, 'wb')
73
73
    except IOError:
74
74
        warning("Could not open export-marks file %s - not exporting marks",
75
75
                filename)
77
77
 
78
78
    try:
79
79
        # Write the revision info
80
 
        for mark in revision_ids:
81
 
            f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),
82
 
                                  revision_ids[mark].decode('utf-8')))
 
80
        for mark, revid in sorted(revision_ids.items()):
 
81
            f.write(b':%s %s\n' % (mark.lstrip(b':'), revid))
83
82
    finally:
84
83
        f.close()